diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 852345c997641e79a5aa97f4ca2bd181f23def49..c4cfe141c9dfd9406e2260a8f18633d77de0833b 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 bc939a5ac7be182aa22e6bafd7d3fc06f6bbbb5f..9aca04cabd1f144a59b25a0d15d931d4de73fe70 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):