未验证 提交 11d7dae9 编写于 作者: W wanghuancoder 提交者: GitHub

Del old dygraph optest1 (#51417)

* delete old dygraph op test
上级 da551b2e
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import time import time
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
from paddle.fluid.op import Operator from paddle.fluid.op import Operator
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
from paddle.framework import core from paddle.framework import core
......
...@@ -50,6 +50,17 @@ from white_list import ( ...@@ -50,6 +50,17 @@ from white_list import (
op_threshold_white_list, op_threshold_white_list,
) )
from paddle.fluid.wrapped_decorator import signature_safe_contextmanager
@signature_safe_contextmanager
def paddle_static_guard():
try:
paddle.enable_static()
yield
finally:
paddle.disable_static()
def check_out_dtype(api_fn, in_specs, expect_dtypes, target_index=0, **configs): def check_out_dtype(api_fn, in_specs, expect_dtypes, target_index=0, **configs):
""" """
...@@ -66,14 +77,16 @@ def check_out_dtype(api_fn, in_specs, expect_dtypes, target_index=0, **configs): ...@@ -66,14 +77,16 @@ def check_out_dtype(api_fn, in_specs, expect_dtypes, target_index=0, **configs):
check_out_dtype(fluid.layers.pad_constant_like, [([2,3,2,3], 'float64'), ([1, 3, 1,3], )], ['float32', 'float64', 'int64'], target_index=1, pad_value=0.) check_out_dtype(fluid.layers.pad_constant_like, [([2,3,2,3], 'float64'), ([1, 3, 1,3], )], ['float32', 'float64', 'int64'], target_index=1, pad_value=0.)
""" """
paddle.enable_static() with paddle_static_guard():
for i, expect_dtype in enumerate(expect_dtypes): for i, expect_dtype in enumerate(expect_dtypes):
with paddle.static.program_guard(paddle.static.Program()): with paddle.static.program_guard(paddle.static.Program()):
input_t = [] input_t = []
for index, spec in enumerate(in_specs): for index, spec in enumerate(in_specs):
if len(spec) == 1: if len(spec) == 1:
shape = spec[0] shape = spec[0]
dtype = expect_dtype if target_index == index else 'float32' dtype = (
expect_dtype if target_index == index else 'float32'
)
elif len(spec) == 2: elif len(spec) == 2:
shape, dtype = spec shape, dtype = spec
else: else:
...@@ -723,10 +736,8 @@ class OpTest(unittest.TestCase): ...@@ -723,10 +736,8 @@ class OpTest(unittest.TestCase):
if is_input: if is_input:
v = self._create_var_from_numpy(np_value_temp) v = self._create_var_from_numpy(np_value_temp)
if if_return_inputs_grad_dict: if if_return_inputs_grad_dict:
v.stop_gradient = False v.stop_gradient = False
if hasattr(v, "retain_grads"):
v.retain_grads() v.retain_grads()
if has_lod: if has_lod:
...@@ -887,6 +898,8 @@ class OpTest(unittest.TestCase): ...@@ -887,6 +898,8 @@ class OpTest(unittest.TestCase):
) )
if not kernel_sig: if not kernel_sig:
return None return None
if not hasattr(self, "python_api"):
print(kernel_sig)
assert hasattr(self, "python_api"), ( assert hasattr(self, "python_api"), (
"Detect there is KernelSignature for `%s` op, please set the `self.python_api` if you set check_dygraph = True" "Detect there is KernelSignature for `%s` op, please set the `self.python_api` if you set check_dygraph = True"
% self.op_type % self.op_type
...@@ -2256,6 +2269,10 @@ class OpTest(unittest.TestCase): ...@@ -2256,6 +2269,10 @@ class OpTest(unittest.TestCase):
dygraph_outputs = self._calc_python_api_output( dygraph_outputs = self._calc_python_api_output(
place, inputs, outputs place, inputs, outputs
) )
if dygraph_outputs is None:
# missing KernelSignature, fall back to eager middle output.
dygraph_outs = self._calc_dygraph_output(place)
# if outputs is None, kernel sig is empty or other error is happens. # if outputs is None, kernel sig is empty or other error is happens.
if not check_dygraph or dygraph_outputs is None: if not check_dygraph or dygraph_outputs is None:
block.append_op( block.append_op(
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import check_out_dtype from eager_op_test import check_out_dtype, paddle_static_guard
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
...@@ -93,13 +93,20 @@ class TestPool1D_API(unittest.TestCase): ...@@ -93,13 +93,20 @@ class TestPool1D_API(unittest.TestCase):
np.testing.assert_allclose(result.numpy(), result_np, rtol=1e-05) np.testing.assert_allclose(result.numpy(), result_np, rtol=1e-05)
def check_adaptive_max_static_results(self, place): def check_adaptive_max_static_results(self, place):
with paddle_static_guard():
with fluid.program_guard(fluid.Program(), fluid.Program()): with fluid.program_guard(fluid.Program(), fluid.Program()):
input = fluid.data(name="input", shape=[2, 3, 32], dtype="float32") input = fluid.data(
name="input", shape=[2, 3, 32], dtype="float32"
)
result = F.adaptive_max_pool1d(input, output_size=16) result = F.adaptive_max_pool1d(input, output_size=16)
input_np = np.random.random([2, 3, 32]).astype("float32") input_np = np.random.random([2, 3, 32]).astype("float32")
result_np = max_pool1D_forward_naive( result_np = max_pool1D_forward_naive(
input_np, ksize=[16], strides=[2], paddings=[0], adaptive=True input_np,
ksize=[16],
strides=[2],
paddings=[0],
adaptive=True,
) )
exe = fluid.Executor(place) exe = fluid.Executor(place)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import check_out_dtype from eager_op_test import check_out_dtype
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import check_out_dtype from eager_op_test import check_out_dtype
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
......
...@@ -15,7 +15,7 @@ import math ...@@ -15,7 +15,7 @@ import math
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
def add_position_encoding(input, alpha=1.0, beta=1.0): def add_position_encoding(input, alpha=1.0, beta=1.0):
......
...@@ -18,7 +18,7 @@ Unit testing for affine_channel_op ...@@ -18,7 +18,7 @@ Unit testing for affine_channel_op
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
def affine_channel(x, scale, bias, layout): def affine_channel(x, scale, bias, layout):
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
import paddle import paddle
...@@ -133,12 +133,10 @@ class TestAffineGridOp(OpTest): ...@@ -133,12 +133,10 @@ class TestAffineGridOp(OpTest):
} }
def test_check_output(self): def test_check_output(self):
self.check_output(check_eager=True) self.check_output()
def test_check_grad_normal(self): def test_check_grad_normal(self):
self.check_grad( self.check_grad(['Theta'], 'Output', no_grad_set=['OutputShape'])
['Theta'], 'Output', no_grad_set=['OutputShape'], check_eager=True
)
def initTestCase(self): def initTestCase(self):
self.theta_shape = (17, 2, 3) self.theta_shape = (17, 2, 3)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
import paddle import paddle
import paddle.fluid.core as core import paddle.fluid.core as core
...@@ -55,7 +55,7 @@ class TestAllcloseOp(OpTest): ...@@ -55,7 +55,7 @@ class TestAllcloseOp(OpTest):
} }
def test_check_output(self): def test_check_output(self):
self.check_output(check_eager=True) self.check_output()
class TestAllcloseOpException(TestAllcloseOp): class TestAllcloseOpException(TestAllcloseOp):
...@@ -63,28 +63,28 @@ class TestAllcloseOpException(TestAllcloseOp): ...@@ -63,28 +63,28 @@ class TestAllcloseOpException(TestAllcloseOp):
def test_rtol_num(): def test_rtol_num():
self.inputs['Rtol'] = np.array([1e-05, 1e-05]).astype("float64") self.inputs['Rtol'] = np.array([1e-05, 1e-05]).astype("float64")
self.inputs['Atol'] = np.array([1e-08]).astype("float64") self.inputs['Atol'] = np.array([1e-08]).astype("float64")
self.check_output(check_eager=True) self.check_output()
self.assertRaises(ValueError, test_rtol_num) self.assertRaises(ValueError, test_rtol_num)
def test_rtol_type(): def test_rtol_type():
self.inputs['Rtol'] = np.array([5]).astype("int32") self.inputs['Rtol'] = np.array([5]).astype("int32")
self.inputs['Atol'] = np.array([1e-08]).astype("float64") self.inputs['Atol'] = np.array([1e-08]).astype("float64")
self.check_output(check_eager=True) self.check_output()
self.assertRaises(ValueError, test_rtol_type) self.assertRaises(ValueError, test_rtol_type)
def test_atol_num(): def test_atol_num():
self.inputs['Rtol'] = np.array([1e-05]).astype("float64") self.inputs['Rtol'] = np.array([1e-05]).astype("float64")
self.inputs['Atol'] = np.array([1e-08, 1e-08]).astype("float64") self.inputs['Atol'] = np.array([1e-08, 1e-08]).astype("float64")
self.check_output(check_eager=True) self.check_output()
self.assertRaises(ValueError, test_atol_num) self.assertRaises(ValueError, test_atol_num)
def test_atol_type(): def test_atol_type():
self.inputs['Rtol'] = np.array([1e-05]).astype("float64") self.inputs['Rtol'] = np.array([1e-05]).astype("float64")
self.inputs['Atol'] = np.array([8]).astype("int32") self.inputs['Atol'] = np.array([8]).astype("int32")
self.check_output(check_eager=True) self.check_output()
self.assertRaises(ValueError, test_atol_type) self.assertRaises(ValueError, test_atol_type)
...@@ -198,7 +198,7 @@ class TestAllcloseOpFloat16(TestAllcloseOp): ...@@ -198,7 +198,7 @@ class TestAllcloseOpFloat16(TestAllcloseOp):
if core.is_compiled_with_cuda(): if core.is_compiled_with_cuda():
place = core.CUDAPlace(0) place = core.CUDAPlace(0)
if core.is_float16_supported(place): if core.is_float16_supported(place):
self.check_output_with_place(place, check_eager=True) self.check_output_with_place(place)
class TestAllcloseOpFloat32(TestAllcloseOp): class TestAllcloseOpFloat32(TestAllcloseOp):
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
import paddle.static.amp.amp_nn as amp_nn import paddle.static.amp.amp_nn as amp_nn
...@@ -44,7 +44,7 @@ class TestCheckFiniteAndUnscaleOp(OpTest): ...@@ -44,7 +44,7 @@ class TestCheckFiniteAndUnscaleOp(OpTest):
self.dtype = np.float32 self.dtype = np.float32
def test_check_output(self): def test_check_output(self):
self.check_output(check_eager=True) self.check_output()
class TestCheckFiniteAndUnscaleOpWithNan(OpTest): class TestCheckFiniteAndUnscaleOpWithNan(OpTest):
...@@ -69,7 +69,7 @@ class TestCheckFiniteAndUnscaleOpWithNan(OpTest): ...@@ -69,7 +69,7 @@ class TestCheckFiniteAndUnscaleOpWithNan(OpTest):
def test_check_output(self): def test_check_output(self):
# When input contains nan, do not check the output, # When input contains nan, do not check the output,
# since the output may be nondeterministic and will be discarded. # since the output may be nondeterministic and will be discarded.
self.check_output(no_check_set=['Out'], check_eager=True) self.check_output(no_check_set=['Out'])
class TestCheckFiniteAndUnscaleOpWithInf(OpTest): class TestCheckFiniteAndUnscaleOpWithInf(OpTest):
...@@ -94,7 +94,7 @@ class TestCheckFiniteAndUnscaleOpWithInf(OpTest): ...@@ -94,7 +94,7 @@ class TestCheckFiniteAndUnscaleOpWithInf(OpTest):
def test_check_output(self): def test_check_output(self):
# When input contains inf, do not check the output, # When input contains inf, do not check the output,
# since the output may be nondeterministic and will be discarded. # since the output may be nondeterministic and will be discarded.
self.check_output(no_check_set=['Out'], check_eager=True) self.check_output(no_check_set=['Out'])
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
def anchor_generator_in_python( def anchor_generator_in_python(
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from eager_op_test import OpTest
import paddle import paddle
from paddle import static from paddle import static
...@@ -49,7 +49,7 @@ class TestAngleOpFloat(OpTest): ...@@ -49,7 +49,7 @@ class TestAngleOpFloat(OpTest):
self.outputs = {'Out': out_ref} self.outputs = {'Out': out_ref}
def test_check_output(self): def test_check_output(self):
self.check_output(check_eager=True) self.check_output()
def test_check_grad(self): def test_check_grad(self):
self.check_grad( self.check_grad(
...@@ -58,7 +58,6 @@ class TestAngleOpFloat(OpTest): ...@@ -58,7 +58,6 @@ class TestAngleOpFloat(OpTest):
user_defined_grads=[ user_defined_grads=[
angle_grad(self.x, np.ones_like(self.x) / self.x.size) angle_grad(self.x, np.ones_like(self.x) / self.x.size)
], ],
check_eager=True,
) )
...@@ -75,7 +74,7 @@ class TestAngleOpComplex(OpTest): ...@@ -75,7 +74,7 @@ class TestAngleOpComplex(OpTest):
self.outputs = {'Out': out_ref} self.outputs = {'Out': out_ref}
def test_check_output(self): def test_check_output(self):
self.check_output(check_eager=True) self.check_output()
def test_check_grad(self): def test_check_grad(self):
self.check_grad( self.check_grad(
...@@ -84,7 +83,6 @@ class TestAngleOpComplex(OpTest): ...@@ -84,7 +83,6 @@ class TestAngleOpComplex(OpTest):
user_defined_grads=[ user_defined_grads=[
angle_grad(self.x, np.ones_like(self.x) / self.x.size) angle_grad(self.x, np.ones_like(self.x) / self.x.size)
], ],
check_eager=True,
) )
......
...@@ -16,7 +16,7 @@ import platform ...@@ -16,7 +16,7 @@ import platform
import unittest import unittest
import numpy as np import numpy as np
from eager_op_test import OpTest from eager_op_test import OpTest, paddle_static_guard
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
...@@ -401,7 +401,7 @@ class TestResizeLinearOpUint8(OpTest): ...@@ -401,7 +401,7 @@ class TestResizeLinearOpUint8(OpTest):
class TestLinearInterpOpError(unittest.TestCase): class TestLinearInterpOpError(unittest.TestCase):
def test_error(self): def test_error(self):
with paddle.fluid.framework._static_guard(): with paddle_static_guard():
with program_guard(Program(), Program()): with program_guard(Program(), Program()):
def input_shape_error(): def input_shape_error():
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册