diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 1fdccdb285b806be4dcb3a3ffbc2e03668da0447..1d91630eb2f1e968013caf4f2eea0bb1173a7d9b 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -17236,7 +17236,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0): helper = LayerHelper("uniform_random", **locals()) inputs = dict() - attrs = dict() + attrs = {'seed': seed, 'min': min, 'max': max} 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 ca18a07753b473d6dd06c39615b4994c3ffae407..92ac6be3c2d2d231a970af6f9a9028bdd64f97ab 100644 --- a/python/paddle/fluid/tests/unittests/test_uniform_random_op.py +++ b/python/paddle/fluid/tests/unittests/test_uniform_random_op.py @@ -243,6 +243,32 @@ class TestUniformRandomOp_attr_tensor_API(unittest.TestCase): outs = exe.run(train_program, fetch_list=[ret]) +class TestUniformRandomOp_API_seed(unittest.TestCase): + def test_attr_tensor_API(self): + startup_program = fluid.Program() + train_program = fluid.Program() + with fluid.program_guard(train_program, startup_program): + _min = 5 + _max = 10 + _seed = 10 + ret = fluid.layers.nn.uniform_random( + [2, 3, 2], min=_min, max=_max, seed=_seed) + ret_2 = fluid.layers.nn.uniform_random( + [2, 3, 2], min=_min, max=_max, seed=_seed) + res = fluid.layers.equal(ret, ret_2) + place = fluid.CPUPlace() + if fluid.core.is_compiled_with_cuda(): + place = fluid.CUDAPlace(0) + exe = fluid.Executor(place) + + exe.run(startup_program) + ret_value, cmp_value = exe.run(train_program, fetch_list=[ret, res]) + self.assertTrue(np.array(cmp_value).all()) + for i in ret_value.flatten(): + self.assertGreaterEqual(i, _min) + self.assertLess(i, _max) + + class TestUniformRandomOpSelectedRowsShapeTensor(unittest.TestCase): def get_places(self): places = [core.CPUPlace()]