diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/auto_parallel_parallelizer.py b/python/paddle/fluid/tests/unittests/collective/fleet/auto_parallel_parallelizer.py index ffb413fca2c87..b1c00c61057ca 100755 --- a/python/paddle/fluid/tests/unittests/collective/fleet/auto_parallel_parallelizer.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/auto_parallel_parallelizer.py @@ -22,7 +22,6 @@ import paddle.utils as utils from paddle.distributed import fleet from paddle.distributed.fleet import auto -from paddle.fluid import layers paddle.enable_static() _global_parallel_strategy = None @@ -93,7 +92,9 @@ def mlp_pretrain_forward(train_program, start_program): predict = mlp(input) - cost = 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 avg_cost, train_program, start_program diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dist_mnist_gradient_merge.py b/python/paddle/fluid/tests/unittests/collective/fleet/dist_mnist_gradient_merge.py index 85394ea89da4e..01d6d970c6cd2 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dist_mnist_gradient_merge.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dist_mnist_gradient_merge.py @@ -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 diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_se_resnext.py b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_se_resnext.py index f484a7930059b..9515c987a50f8 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_se_resnext.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_se_resnext.py @@ -350,7 +350,9 @@ def run_one_loop(self, model, opt, data): out = model(img) softmax_out = paddle.nn.functional.softmax(out, use_cudnn=False) - loss = fluid.layers.cross_entropy(input=softmax_out, label=label) + loss = paddle.nn.functional.cross_entropy( + input=softmax_out, label=label, reduction='none', use_softmax=False + ) avg_loss = paddle.mean(x=loss) return avg_loss diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist.py b/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist.py index 4530d8e24216a..f974709ce87ab 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist.py @@ -100,7 +100,9 @@ def get_model(self, batch_size=2, use_dgc=False, dist_strategy=None): # Train program predict = cnn_model(images) with fluid.device_guard("gpu:1"): - 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 diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist_multi_device.py b/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist_multi_device.py index 0b75b034ce46e..ecc71abe6252c 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist_multi_device.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist_multi_device.py @@ -100,7 +100,9 @@ def get_model(self, batch_size=2, use_dgc=False, dist_strategy=None): # Train program predict = cnn_model(images) with fluid.device_guard("gpu:1"): - 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 diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist_one_device.py b/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist_one_device.py index 5b1e590fc0058..a6971e210af0c 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist_one_device.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/pipeline_mnist_one_device.py @@ -92,7 +92,9 @@ def get_model(self, batch_size=2, use_dgc=False, dist_strategy=None): # Train program predict = cnn_model(images) with fluid.device_guard("gpu:0"): - 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 diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/test_fleet_checkpoint.py b/python/paddle/fluid/tests/unittests/collective/fleet/test_fleet_checkpoint.py index d1e24149c2df2..b030b6121464d 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/test_fleet_checkpoint.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/test_fleet_checkpoint.py @@ -41,7 +41,9 @@ def _test_checkpoint(self, fs, dir_path): feed_list=[image, label], place=fluid.CPUPlace() ) predict = fluid.layers.fc(input=image, size=10, act='softmax') - loss = fluid.layers.cross_entropy(input=predict, label=label) + loss = paddle.nn.functional.cross_entropy( + input=predict, label=label, reduction='none', use_softmax=False + ) avg_loss = paddle.mean(loss) optimizer = fluid.optimizer.AdamOptimizer(learning_rate=0.001) diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision.py b/python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision.py index 3141ed81a458b..d30466d9fc957 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision.py @@ -1308,7 +1308,9 @@ def train_resnet(self, enable_amp=True, level='O1'): ): out = resnet(img) - loss = fluid.layers.cross_entropy(input=out, label=label) + loss = paddle.nn.functional.cross_entropy( + input=out, label=label, reduction='none', use_softmax=False + ) avg_loss = paddle.mean(x=loss) dy_out = avg_loss.numpy() diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision_for_eager.py b/python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision_for_eager.py index dbcdf3ac46c9e..f688d28b85603 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision_for_eager.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision_for_eager.py @@ -1298,7 +1298,9 @@ def train_resnet(self, enable_amp=True, level='O1'): ): out = resnet(img) - loss = fluid.layers.cross_entropy(input=out, label=label) + loss = paddle.nn.functional.cross_entropy( + input=out, label=label, reduction='none', use_softmax=False + ) avg_loss = paddle.mean(x=loss) dy_out = avg_loss.numpy() diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_quant_dequant_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_quant_dequant_pass.py index 05244e3627b69..9451a214aadf3 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_quant_dequant_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_quant_dequant_pass.py @@ -53,7 +53,12 @@ def network(): elif self.conv_groups == 4: cout = paddle.reshape(conv_out, shape=[1, 1, 10816]) result = fluid.layers.relu(cout) - loss = fluid.layers.cross_entropy(input=result, label=label_shape) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=label_shape, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result @@ -156,7 +161,12 @@ def network(): ) cout = paddle.reshape(conv_out, shape=[1, 1, 10816]) result = fluid.layers.relu(cout) - loss = fluid.layers.cross_entropy(input=result, label=label_shape) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=label_shape, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result @@ -257,7 +267,12 @@ def network(): elif self.conv_groups == 4: cout = paddle.reshape(conv_out, shape=[1, 1, 10816]) result = fluid.layers.relu(cout) - loss = fluid.layers.cross_entropy(input=result, label=label_shape) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=label_shape, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_fc_fuse_quant_dequant_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_fc_fuse_quant_dequant_pass.py index ca491a06c6860..372a4ea23ba35 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_fc_fuse_quant_dequant_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_fc_fuse_quant_dequant_pass.py @@ -38,7 +38,12 @@ def network(): act="relu", ) result = fluid.layers.relu(fc_out) - loss = fluid.layers.cross_entropy(input=result, label=self.label) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=self.label, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result @@ -105,7 +110,12 @@ def network(): ) c_out = paddle.reshape(fc_out, shape=[0, 784]) result = fluid.layers.relu(c_out) - loss = fluid.layers.cross_entropy(input=result, label=self.label) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=self.label, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result @@ -174,7 +184,12 @@ def network(): ) c_out = paddle.reshape(fc_out, shape=[1, 1, 2744]) result = fluid.layers.relu(c_out) - loss = fluid.layers.cross_entropy(input=result, label=label_shape) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=label_shape, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_matmul_quant_dequant.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_matmul_quant_dequant.py index 4e2b3e0ae2420..ca6a0d98d89f9 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_matmul_quant_dequant.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_matmul_quant_dequant.py @@ -47,7 +47,12 @@ def network(): act=None, ) result = fluid.layers.relu(fc_out) - loss = fluid.layers.cross_entropy(input=result, label=self.label) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=self.label, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result @@ -144,7 +149,12 @@ def network(): act=None, ) result = fluid.layers.relu(fc_out) - loss = fluid.layers.cross_entropy(input=result, label=self.label) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=self.label, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result @@ -240,7 +250,12 @@ def network(): act=None, ) result = fluid.layers.relu(fc_out) - loss = fluid.layers.cross_entropy(input=result, label=self.label) + loss = paddle.nn.functional.cross_entropy( + input=result, + label=self.label, + reduction='none', + use_softmax=False, + ) avg_loss = paddle.mean(loss) return avg_loss, result