diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 852345c997..c4cfe141c9 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -14322,7 +14322,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0): helper = LayerHelper("uniform_random", **locals()) inputs = dict() - attrs = {'seed': seed, 'min': min, 'max': max} + attrs = {'seed': seed, 'min': min, 'max': max, 'dtype': dtype} if in_dygraph_mode(): attrs['shape'] = shape else: diff --git a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py index bc939a5ac7..9aca04cabd 100644 --- a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py +++ b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py @@ -190,6 +190,12 @@ class TestUniformRandomOpError(unittest.TestCase): self.assertRaises(TypeError, test_dtype) + def test_out_dtype(): + out = fluid.layers.uniform_random(shape=[3, 4], dtype='float64') + self.assertEqual(out.dtype, fluid.core.VarDesc.VarType.FP64) + + test_out_dtype() + class TestUniformRandomOpWithDiagInit(TestUniformRandomOp): def init_attrs(self):