未验证 提交 358d6bc9 编写于 作者: C Chen Weihang 提交者: GitHub

Fix test_weight_decay_extend random failed on windows (#28643)

* add debuging code

* change seed & add debug message
上级 5050e761
......@@ -24,6 +24,8 @@ import contextlib
paddle.enable_static()
SEED = 2020
def fake_imdb_reader(word_dict_size,
sample_num,
......@@ -87,6 +89,11 @@ def bow_net(data,
class TestWeightDecay(unittest.TestCase):
def setUp(self):
# set seed
np.random.seed(SEED)
paddle.seed(SEED)
paddle.framework.random._manual_program_seed(SEED)
# configs
self.word_dict_len = 5147
batch_size = 2
reader = fake_imdb_reader(self.word_dict_len, batch_size * 100)
......@@ -114,8 +121,6 @@ class TestWeightDecay(unittest.TestCase):
return param_sum
def check_weight_decay(self, place, model):
paddle.seed(1)
paddle.framework.random._manual_program_seed(1)
main_prog = fluid.framework.Program()
startup_prog = fluid.framework.Program()
......@@ -137,8 +142,6 @@ class TestWeightDecay(unittest.TestCase):
return param_sum
def check_weight_decay2(self, place, model):
paddle.seed(1)
paddle.framework.random._manual_program_seed(1)
main_prog = fluid.framework.Program()
startup_prog = fluid.framework.Program()
......@@ -173,7 +176,12 @@ class TestWeightDecay(unittest.TestCase):
param_sum2 = self.check_weight_decay2(place, model)
for i in range(len(param_sum1)):
assert np.isclose(a=param_sum1[i], b=param_sum2[i], rtol=5e-5)
self.assertTrue(
np.allclose(param_sum1[i], param_sum2[i]),
"Current place: {}, i: {}, sum1: {}, sum2: {}".format(
place, i, param_sum1[i][~np.isclose(param_sum1[
i], param_sum2[i])], param_sum2[i][~np.isclose(
param_sum1[i], param_sum2[i])]))
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册