Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[remove fluid.layers.cross_entropy] remove unit tests (part 4) #48919

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/dist_allreduce_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def get_model(self, batch_size=2, single_device=False):

# Train program
predict = cnn_model(images)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/dist_ctr.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def get_model(self, batch_size=2):
auc_var, batch_auc_var, auc_states = paddle.static.auc(
input=predict, label=label
)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

inference_program = paddle.fluid.default_main_program().clone()
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/dist_fleet_ctr.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def net(self, args, is_train=True, batch_size=4, lr=0.01):
input=predict, label=label
)

cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

self.feeds = datas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def net(self, args, batch_size=4, lr=0.01):
label = fluid.layers.cast(label, dtype="int64")
predict = fluid.layers.fc(input=merge_layer, size=2, act='softmax')

cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)
fluid.layers.Print(avg_cost, message="avg_cost")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def get_model(self, batch_size=2, single_device=False):

# Train program
predict = cnn_model(images)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def get_model(self, batch_size=2, single_device=False):

# Train program
predict = cnn_model(images)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def net(self, args, batch_size=4, lr=0.01):

acc = paddle.static.accuracy(input=predict, label=label)
auc_var, _, _ = paddle.static.auc(input=predict, label=label)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

self.feeds = datas
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/dist_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def get_model(self, batch_size=2, use_dgc=False, dist_strategy=None):

# Train program
predict = cnn_model(images)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def get_model(self, batch_size=2):

# Train program
predict = cnn_model(images)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def get_model(self, batch_size=2):

# Train program
predict = cnn_model(images)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/dist_mnist_lars.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def get_model(self, batch_size=2):

# Train program
predict = cnn_model(images)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

# Evaluator
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/dist_se_resnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def get_model(self, batch_size=2, use_dgc=False):
# Train program
model = SE_ResNeXt(layers=50)
out = model.net(input=image, class_dim=102)
cost = fluid.layers.cross_entropy(input=out, label=label)
cost = paddle.nn.functional.cross_entropy(
input=out, label=label, reduction='none', use_softmax=False
)

avg_cost = paddle.mean(x=cost)
acc_top1 = paddle.static.accuracy(input=out, label=label, k=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def get_model(self, batch_size=2):

# Train program
predict = conv_net(data, dict_dim)
cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)
acc = paddle.static.accuracy(input=predict, label=label)
inference_program = fluid.default_main_program().clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def net(batch_size=4, lr=0.01):
label = fluid.layers.cast(label, dtype="int64")
predict = fluid.layers.fc(input=merge_layer, size=2, act='softmax')

cost = fluid.layers.cross_entropy(input=predict, label=label)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)
return datas, avg_cost

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def forward(self, inputs, label):
x = self._simple_img_conv_pool_2(x)
x = paddle.reshape(x, shape=[-1, self.pool_2_shape])
cost = self._fc(x)
loss = fluid.layers.cross_entropy(self.act(cost), label)
loss = paddle.nn.functional.cross_entropy(
self.act(cost), label, reduction='none', use_softmax=False
)
avg_loss = paddle.mean(loss)
return avg_loss

Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/seresnext_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def SE_ResNeXt50Small(use_feed):
)
# Classifier layer:
prediction = fluid.layers.fc(input=dropout, size=1000, act='softmax')
loss = fluid.layers.cross_entropy(input=prediction, label=label)
loss = paddle.nn.functional.cross_entropy(
input=prediction, label=label, reduction='none', use_softmax=False
)
loss = paddle.mean(loss)
return loss

Expand Down
12 changes: 9 additions & 3 deletions python/paddle/fluid/tests/unittests/simple_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def simple_fc_net_with_inputs(img, label, class_num=10):
),
)
prediction = fluid.layers.fc(hidden, size=class_num, act='softmax')
loss = fluid.layers.cross_entropy(input=prediction, label=label)
loss = paddle.nn.functional.cross_entropy(
input=prediction, label=label, reduction='none', use_softmax=False
)
loss = paddle.mean(loss)
return loss

Expand All @@ -56,7 +58,9 @@ def batchnorm_fc_with_inputs(img, label, class_num=10):
hidden = paddle.static.nn.batch_norm(input=hidden)

prediction = fluid.layers.fc(hidden, size=class_num, act='softmax')
loss = fluid.layers.cross_entropy(input=prediction, label=label)
loss = paddle.nn.functional.cross_entropy(
input=prediction, label=label, reduction='none', use_softmax=False
)
loss = paddle.mean(loss)
return loss

Expand Down Expand Up @@ -93,7 +97,9 @@ def bow_net(
fc_1 = fluid.layers.fc(input=bow_tanh, size=hid_dim, act="tanh")
fc_2 = fluid.layers.fc(input=fc_1, size=hid_dim2, act="tanh")
prediction = fluid.layers.fc(input=[fc_2], size=class_dim, act="softmax")
cost = fluid.layers.cross_entropy(input=prediction, label=label)
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=label, reduction='none', use_softmax=False
)
avg_cost = paddle.mean(x=cost)

return avg_cost
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/transformer_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ def transformer(
)
predict = paddle.nn.functional.softmax(predict)

cost = layers.cross_entropy(input=predict, label=gold)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=gold, reduction='none', use_softmax=False
)
weighted_cost = cost * weights
return paddle.sum(weighted_cost)