提交 0fa0080d 编写于 作者: S silingtong123 提交者: liuwei1031

add unittest of seed failed work (#20487) cherry-pick (#20485)

* add unittest  of seed failed work

* tadd unittest  of seed failed work

* fix the parameter seed failed to work
上级 0fad5ef2
...@@ -17236,7 +17236,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0): ...@@ -17236,7 +17236,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0):
helper = LayerHelper("uniform_random", **locals()) helper = LayerHelper("uniform_random", **locals())
inputs = dict() inputs = dict()
attrs = dict() attrs = {'seed': seed, 'min': min, 'max': max}
if in_dygraph_mode(): if in_dygraph_mode():
attrs = {'shape': shape} attrs = {'shape': shape}
else: else:
......
...@@ -243,6 +243,32 @@ class TestUniformRandomOp_attr_tensor_API(unittest.TestCase): ...@@ -243,6 +243,32 @@ class TestUniformRandomOp_attr_tensor_API(unittest.TestCase):
outs = exe.run(train_program, fetch_list=[ret]) 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): class TestUniformRandomOpSelectedRowsShapeTensor(unittest.TestCase):
def get_places(self): def get_places(self):
places = [core.CPUPlace()] places = [core.CPUPlace()]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册