diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 40a60f78a371aa23a8f424d7212cf14a73a59012..26486ef08f71e535a60114fc849af247fc08c971 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -17885,7 +17885,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0): inputs = dict() attrs = {'seed': seed, 'min': min, 'max': max} if in_dygraph_mode(): - attrs = {'shape': shape} + attrs['shape'] = shape else: if isinstance(shape, Variable): shape.stop_gradient = True 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 92ac6be3c2d2d231a970af6f9a9028bdd64f97ab..53a1e1ea167c2d2fb88e203d4dfeb2a1aca7cc81 100644 --- a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py +++ b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py @@ -335,5 +335,15 @@ class TestUniformRandomOpSelectedRowsShapeTensorList(unittest.TestCase): hist, prob, rtol=0, atol=0.01), "hist: " + str(hist)) +class TestUniformRandomDygraphMode(unittest.TestCase): + def test_check_output(self): + with fluid.dygraph.guard(): + x = fluid.layers.uniform_random( + [10], dtype="float32", min=0.0, max=1.0) + x_np = x.numpy() + for i in range(10): + self.assertTrue((x_np[i] > 0 and x_np[i] < 1.0)) + + if __name__ == "__main__": unittest.main()