diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 0bf24f2e13deed0982bba6eac09c3950400978d4..df65e057471ffdaf9f91cb219a185be93abdb51b 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -17854,7 +17854,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 65d534b79b0ef702ccf2cff689368a076b5102e0..1d388816608c66eda18f308c713011dbc99c164a 100644 --- a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py +++ b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py @@ -416,5 +416,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()