diff --git a/python/paddle/fluid/contrib/slim/tests/test_user_defined_quantization.py b/python/paddle/fluid/contrib/slim/tests/test_user_defined_quantization.py index fad7ce76a2e344c2f6ec23cdffed6246a51510a8..63813f7ebfc177bc6736519ecf24e00353e6051a 100644 --- a/python/paddle/fluid/contrib/slim/tests/test_user_defined_quantization.py +++ b/python/paddle/fluid/contrib/slim/tests/test_user_defined_quantization.py @@ -28,6 +28,7 @@ from paddle.fluid.contrib.slim.quantization import OutScaleForInferencePass from paddle.fluid.contrib.slim.quantization import AddQuantDequantPass from paddle.fluid import core from paddle.fluid.layer_helper import LayerHelper +import paddle.nn.functional as F paddle.enable_static() @@ -75,8 +76,8 @@ def pact(x, name=None): learning_rate=1, ) u_param = helper.create_parameter(attr=u_param_attr, shape=[1], dtype=dtype) - x = paddle.subtract(x, fluid.layers.relu(paddle.subtract(x, u_param))) - x = paddle.add(x, fluid.layers.relu(paddle.subtract(-u_param, x))) + x = paddle.subtract(x, F.relu(paddle.subtract(x, u_param))) + x = paddle.add(x, F.relu(paddle.subtract(-u_param, x))) return x diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ast_util.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ast_util.py index b417cd5fd95af2c532e1a6410b3cfdfe9849ffb9..4834f675bd5907335314d656e4754bbd6cf0ce0c 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ast_util.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ast_util.py @@ -25,6 +25,7 @@ from ifelse_simple_func import ( import paddle import paddle.fluid as fluid +import paddle.nn.functional as F from paddle.jit.dy2static.utils import ast_to_func from paddle.utils import gast @@ -60,7 +61,7 @@ class TestAST2Func(unittest.TestCase): def test_ast2func_static(self): def func(x): - y = fluid.layers.relu(x) + y = F.relu(x) loss = paddle.mean(y) return loss diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ifelse.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ifelse.py index 13b95d0b31cd7634fd44bf048fe60a034680a50a..39f44ff191b66c72fd364e086a1897b349afa615 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ifelse.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ifelse.py @@ -43,6 +43,7 @@ from ifelse_simple_func import ( import paddle import paddle.fluid.core as core +import paddle.nn.functional as F from paddle.jit.api import declarative from paddle.jit.dy2static.program_translator import ProgramTranslator from paddle.jit.dy2static.utils import Dygraph2StaticException @@ -269,7 +270,7 @@ class TestDygraphIfElseNet(unittest.TestCase): # Test to call function ahead caller. def relu(x): - return fluid.layers.relu(x) + return F.relu(x) def call_external_func(x, label=None): diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lambda.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lambda.py index ce6ca928430df1c5b04848d91e358f20cefbf4d8..8466a167947e0d473ce6bb14b32b70c08c000ba9 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lambda.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lambda.py @@ -18,6 +18,7 @@ import numpy as np import paddle import paddle.fluid as fluid +import paddle.nn.functional as F from paddle.jit.api import declarative @@ -48,7 +49,7 @@ def call_lambda_in_func(x): add_func = lambda x: x + 1 - y = paddle.mean((lambda x: fluid.layers.relu(x))(x)) + y = paddle.mean((lambda x: F.relu(x))(x)) out = add_func(y) if y > 1 and y < 2 else (lambda x: x**2)(y) return out diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py index 4d2a70ee1cf4b15a08e24450e2b8b84c8eeabf4f..454f66b823e026b6419d70d31c4d8724aac4795c 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py @@ -19,6 +19,7 @@ import numpy as np import paddle import paddle.fluid as fluid +import paddle.nn.functional as F from paddle.jit.api import declarative from paddle.jit.dy2static.loop_transformer import NameVisitor from paddle.utils import gast @@ -51,7 +52,7 @@ def while_loop_dyfun_with_conflict_var(x): def relu(y): # 'y' is not visible outside the scope. - return fluid.layers.relu(y) + return F.relu(y) while x < 10: # If a tmp variable is created which has same name diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_reinforcement_learning.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_reinforcement_learning.py index c97d37d3523a8213225caf98faade249e256fa50..1955859f65fa8956953f9ded98ec444121ca510a 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_reinforcement_learning.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_reinforcement_learning.py @@ -21,6 +21,7 @@ import numpy as np import paddle import paddle.fluid as fluid +import paddle.nn.functional as F from paddle.fluid.dygraph import Layer, to_variable from paddle.jit import ProgramTranslator from paddle.jit.api import declarative @@ -45,7 +46,7 @@ class Policy(Layer): x = paddle.reshape(x, shape=[1, 4]) x = self.affine1(x) x = fluid.layers.dropout(x, self.dropout_ratio) - x = fluid.layers.relu(x) + x = F.relu(x) action_scores = self.affine2(x) log_prob = paddle.nn.functional.softmax(action_scores, axis=1) diff --git a/python/paddle/fluid/tests/unittests/ipu/test_fp16_support_ipu.py b/python/paddle/fluid/tests/unittests/ipu/test_fp16_support_ipu.py index ba96a7878a128906dc19a2bc556a8fb8dcd7e737..05dade4dc192f7086a693a87c8577f5fa8a854ff 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_fp16_support_ipu.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_fp16_support_ipu.py @@ -17,6 +17,7 @@ import unittest import numpy as np import paddle +import paddle.nn.functional as F import paddle.static from paddle.fluid.tests.unittests.ipu.op_test_ipu import IPUOpTest @@ -63,7 +64,7 @@ class TestBase(IPUOpTest): conv3 = paddle.static.nn.conv2d( add1, num_filters=8, filter_size=8, bias_attr=False ) - out = paddle.fluid.layers.relu(conv3, **self.attrs) + out = F.relu(conv3, **self.attrs) self.fetch_list = [out.name] def run_model(self, exec_mode): diff --git a/python/paddle/fluid/tests/unittests/ipu/test_unary_ops_ipu.py b/python/paddle/fluid/tests/unittests/ipu/test_unary_ops_ipu.py index b58418c03cf3b78d03af79528e2543167c78594a..02d914f3058fe3de60ab417b17cba6c27d08d2c2 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_unary_ops_ipu.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_unary_ops_ipu.py @@ -17,6 +17,7 @@ import unittest import numpy as np import paddle +import paddle.nn.functional as F import paddle.static from paddle.fluid.tests.unittests.ipu.op_test_ipu import IPUOpTest @@ -147,7 +148,7 @@ class TestReciprocal(TestBase): class TestRelu(TestBase): def set_test_op(self): - self.op = paddle.fluid.layers.relu + self.op = F.relu self.op_attrs = {} diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_elt_act_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_elt_act_fuse_pass.py index b5bfafad59cf65d377db1cda168d667a1b782a73..b1890ea95ab9782187c66d58027422e7481b0602 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_elt_act_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_elt_act_fuse_pass.py @@ -19,6 +19,7 @@ from inference_pass_test import InferencePassTest import paddle import paddle.fluid as fluid +import paddle.nn.functional as F from paddle.fluid.core import PassVersionChecker @@ -69,7 +70,7 @@ class ElementwiseActivationMkldnnFusePassTest_Add_Relu( ): def set_params(self): self.operand = paddle.add - self.act = fluid.layers.relu + self.act = F.relu class ElementwiseActivationMkldnnFusePassTest_Add_Tanh( @@ -169,7 +170,7 @@ class ElementwiseActivationMkldnnFusePassTest_Sub_Relu( ): def set_params(self): self.operand = paddle.subtract - self.act = fluid.layers.relu + self.act = F.relu class ElementwiseActivationMkldnnFusePassTest_Sub_Tanh( @@ -261,7 +262,7 @@ class ElementwiseActivationMkldnnFusePassTest_Mul_Relu( ): def set_params(self): self.operand = paddle.multiply - self.act = fluid.layers.relu + self.act = F.relu class ElementwiseActivationMkldnnFusePassTest_Mul_Tanh( diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_inplace_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_inplace_fuse_pass.py index a2ac6d42e54e78512abfbd2e082fc0f1be26359e..875025f8fb668d790bf7c69b95ec1a7671cb698a 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_inplace_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_inplace_fuse_pass.py @@ -19,6 +19,7 @@ from inference_pass_test import InferencePassTest import paddle import paddle.fluid as fluid +import paddle.nn.functional as F from paddle.fluid.core import PassVersionChecker @@ -33,7 +34,7 @@ class MkldnnInplacePassTest(InferencePassTest): data, num_filters=3, filter_size=3, bias_attr=False ) softmax_out = paddle.nn.functional.softmax(conv_out_1) - relu_out = fluid.layers.relu(conv_out_1) + relu_out = F.relu(conv_out_1) eltwise_out = paddle.add(softmax_out, relu_out) self.pass_name = 'mkldnn_inplace_pass' diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_matmul_op_output_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_matmul_op_output_fuse_pass.py index 7b4229e1c360b11ca2167081efbf6bdf33a1da87..c9284a1b5e9d2ccba1dc2117f9d3ba66794f9616 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_matmul_op_output_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_matmul_op_output_fuse_pass.py @@ -19,6 +19,7 @@ from inference_pass_test import InferencePassTest import paddle import paddle.fluid as fluid +import paddle.nn.functional as F class TestMKLDNNMatmulFuseOp(InferencePassTest): @@ -41,7 +42,7 @@ class TestMKLDNNMatmulFuseOp(InferencePassTest): out = paddle.transpose(out, perm=[0, 2, 1, 3]) out = paddle.reshape(out, [0, 0, self.shape_y[0] * self.shape_y[2]]) - out = fluid.layers.relu(out) + out = F.relu(out) return out def setUp(self): @@ -107,7 +108,7 @@ class TestMKLDNNMatmulOpNotFusedBreakPattern(TestMKLDNNMatmulFuseOp): out = paddle.transpose(out, perm=[0, 1, 2, 3]) # breaks pattern out = paddle.reshape(out, [0, 0, self.shape_y[0] * self.shape_y[2]]) - out = fluid.layers.relu(out) + out = F.relu(out) return out diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_activation_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_activation_pass.py index 4134f421e9e4b25632b4a1d9227f54e3830462a7..3a39c84141ced2c0f0538350b3d70c7d9bcaf9c3 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_activation_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_activation_pass.py @@ -22,6 +22,7 @@ from inference_pass_test import InferencePassTest import paddle import paddle.fluid as fluid import paddle.fluid.core as core +import paddle.nn.functional as F import paddle.static.nn as nn from paddle.fluid.core import AnalysisConfig, PassVersionChecker @@ -47,7 +48,7 @@ class TensorRTSubgraphPassActivationTest(InferencePassTest): self.fetch_list = [out] def append_act(self, x): - return fluid.layers.relu(x) + return F.relu(x) def test_check_output(self): if core.is_compiled_with_cuda(): 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 9451a214aadf37008a163eb066b1397f89a5ad1b..20b6068f23cce265d9e572770e861040d814f9af 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 @@ -20,6 +20,7 @@ from quant_dequant_test import QuantDequantTest import paddle import paddle.fluid as fluid import paddle.fluid.core as core +import paddle.nn.functional as F from paddle.fluid.core import AnalysisConfig, PassVersionChecker @@ -52,7 +53,7 @@ class QuantDequantTensorRTSubgraphPassConvTest(QuantDequantTest): cout = paddle.reshape(conv_out, shape=[1, 1, 12544]) elif self.conv_groups == 4: cout = paddle.reshape(conv_out, shape=[1, 1, 10816]) - result = fluid.layers.relu(cout) + result = F.relu(cout) loss = paddle.nn.functional.cross_entropy( input=result, label=label_shape, @@ -160,7 +161,7 @@ class DynamicShapeQuantDequantTensorRTSubgraphPassConvTest(QuantDequantTest): act=None, ) cout = paddle.reshape(conv_out, shape=[1, 1, 10816]) - result = fluid.layers.relu(cout) + result = F.relu(cout) loss = paddle.nn.functional.cross_entropy( input=result, label=label_shape, @@ -266,7 +267,7 @@ class QuantDequantTensorRTSubgraphPassConvTransposeTest(QuantDequantTest): cout = paddle.reshape(conv_out, shape=[1, 1, 12544]) elif self.conv_groups == 4: cout = paddle.reshape(conv_out, shape=[1, 1, 10816]) - result = fluid.layers.relu(cout) + result = F.relu(cout) loss = paddle.nn.functional.cross_entropy( input=result, label=label_shape, 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 372a4ea23ba3592b9cdf4a445afce3fb950f69ef..1c3af0d6c5271f4b9777db7a4fac5a8830f8340c 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 @@ -20,6 +20,7 @@ from quant_dequant_test import QuantDequantTest import paddle import paddle.fluid as fluid import paddle.fluid.core as core +import paddle.nn.functional as F from paddle.fluid.core import AnalysisConfig, PassVersionChecker @@ -37,7 +38,7 @@ class FCQuantDequantFusePassTRTDims3Cols1Test(QuantDequantTest): bias_attr=False, act="relu", ) - result = fluid.layers.relu(fc_out) + result = F.relu(fc_out) loss = paddle.nn.functional.cross_entropy( input=result, label=self.label, @@ -109,7 +110,7 @@ class FCQuantDequantFusePassTRTDims3Cols2Test(QuantDequantTest): act=None, ) c_out = paddle.reshape(fc_out, shape=[0, 784]) - result = fluid.layers.relu(c_out) + result = F.relu(c_out) loss = paddle.nn.functional.cross_entropy( input=result, label=self.label, @@ -183,7 +184,7 @@ class FCQuantDequantFusePassTRTDims3Cols3Test(QuantDequantTest): act=None, ) c_out = paddle.reshape(fc_out, shape=[1, 1, 2744]) - result = fluid.layers.relu(c_out) + result = F.relu(c_out) loss = paddle.nn.functional.cross_entropy( input=result, label=label_shape, 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 ca6a0d98d89f9a0cb3578698c88a9995fb5b191b..5c3f91de4e5197fe4753866d242218b7fee121eb 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 @@ -20,6 +20,7 @@ from quant_dequant_test import QuantDequantTest import paddle import paddle.fluid as fluid import paddle.fluid.core as core +import paddle.nn.functional as F from paddle.fluid.core import AnalysisConfig, PassVersionChecker @@ -46,7 +47,7 @@ class TensorRTMatMulQuantDequantDims3Test(QuantDequantTest): bias_attr=False, act=None, ) - result = fluid.layers.relu(fc_out) + result = F.relu(fc_out) loss = paddle.nn.functional.cross_entropy( input=result, label=self.label, @@ -148,7 +149,7 @@ class TensorRTMatMulQuantDequantDims4Test(QuantDequantTest): bias_attr=False, act=None, ) - result = fluid.layers.relu(fc_out) + result = F.relu(fc_out) loss = paddle.nn.functional.cross_entropy( input=result, label=self.label, @@ -249,7 +250,7 @@ class TensorRTMatMulQuantDequantDims3DynamicTest(QuantDequantTest): bias_attr=False, act=None, ) - result = fluid.layers.relu(fc_out) + result = F.relu(fc_out) loss = paddle.nn.functional.cross_entropy( input=result, label=self.label,