From 02202d024fdb0654fccc3cf97534ecd6a581b2a0 Mon Sep 17 00:00:00 2001 From: Guanghua Yu <742925032@qq.com> Date: Sat, 29 May 2021 15:46:01 +0800 Subject: [PATCH] add `uint8` when check_dtype in assign (#33157) * fix uint8 check in assign * fix assign unittests * fix xpu test_assign --- python/paddle/fluid/layers/tensor.py | 3 ++- .../paddle/fluid/tests/unittests/test_assign_op.py | 14 ++++---------- .../tests/unittests/xpu/test_assign_op_xpu.py | 7 ++----- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index 987918493d3..a62217c628c 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -587,7 +587,8 @@ def assign(input, output=None): # after this api. if isinstance(input, (Variable, core.VarBase)): check_dtype(input.dtype, 'input', [ - 'float16', 'uint16', 'float32', 'float64', 'int32', 'int64', 'bool' + 'float16', 'uint16', 'float32', 'float64', 'int32', 'int64', + 'uint8', 'bool' ], 'assign', '(When the type of input in assign is Variable.)') if output is None: output = helper.create_variable_for_type_inference( diff --git a/python/paddle/fluid/tests/unittests/test_assign_op.py b/python/paddle/fluid/tests/unittests/test_assign_op.py index fe82b23b73b..694fd3c6561 100644 --- a/python/paddle/fluid/tests/unittests/test_assign_op.py +++ b/python/paddle/fluid/tests/unittests/test_assign_op.py @@ -90,12 +90,9 @@ class TestAssignOpError(unittest.TestCase): x1 = fluid.create_lod_tensor( np.array([[-1]]), [[1]], fluid.CPUPlace()) self.assertRaises(TypeError, fluid.layers.assign, x1) - # When the type of input is Variable, the dtype of input must be float16, float32, float64, int32, int64, bool. - x3 = fluid.layers.data(name='x3', shape=[4], dtype="uint8") - self.assertRaises(TypeError, fluid.layers.assign, x3) # When the type of input is numpy.ndarray, the dtype of input must be float32, int32. - x4 = np.array([[2.5, 2.5]], dtype='uint8') - self.assertRaises(TypeError, fluid.layers.assign, x4) + x2 = np.array([[2.5, 2.5]], dtype='uint8') + self.assertRaises(TypeError, fluid.layers.assign, x2) class TestAssignOApi(unittest.TestCase): @@ -180,12 +177,9 @@ class TestAssignOpErrorApi(unittest.TestCase): x1 = fluid.create_lod_tensor( np.array([[-1]]), [[1]], fluid.CPUPlace()) self.assertRaises(TypeError, paddle.assign, x1) - # When the type of input is Variable, the dtype of input must be float16, float32, float64, int32, int64, bool. - x3 = fluid.layers.data(name='x3', shape=[4], dtype="uint8") - self.assertRaises(TypeError, paddle.assign, x3) # When the type of input is numpy.ndarray, the dtype of input must be float32, int32. - x4 = np.array([[2.5, 2.5]], dtype='uint8') - self.assertRaises(TypeError, paddle.assign, x4) + x2 = np.array([[2.5, 2.5]], dtype='uint8') + self.assertRaises(TypeError, paddle.assign, x2) if __name__ == '__main__': diff --git a/python/paddle/fluid/tests/unittests/xpu/test_assign_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_assign_op_xpu.py index 3eefa0bce88..7b74a8bb383 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_assign_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_assign_op_xpu.py @@ -82,11 +82,8 @@ class TestAssignOpError(unittest.TestCase): x1 = fluid.create_lod_tensor( np.array([[-1]]), [[1]], fluid.XPUPlace(0)) self.assertRaises(TypeError, fluid.layers.assign, x1) - # When the type of input is Variable, the dtype of input must be float16, float32, float64, int32, int64, bool. - x3 = fluid.layers.data(name='x3', shape=[4], dtype="uint8") - self.assertRaises(TypeError, fluid.layers.assign, x3) - x4 = np.array([[2.5, 2.5]], dtype='uint8') - self.assertRaises(TypeError, fluid.layers.assign, x4) + x2 = np.array([[2.5, 2.5]], dtype='uint8') + self.assertRaises(TypeError, fluid.layers.assign, x2) if __name__ == '__main__': -- GitLab