未验证 提交 5d73bfdb 编写于 作者: C Chen Weihang 提交者: GitHub

fix test_weight_decay_extend error (#28178)

上级 4873c20d
...@@ -149,17 +149,20 @@ class TestWeightDecay(unittest.TestCase): ...@@ -149,17 +149,20 @@ class TestWeightDecay(unittest.TestCase):
avg_cost = model(data, label, self.word_dict_len) avg_cost = model(data, label, self.word_dict_len)
optimizer = fluid.optimizer.Adam(learning_rate=self.learning_rate)
params_grads = optimizer.backward(avg_cost)
param_list = [(var, var * self.learning_rate) param_list = [(var, var * self.learning_rate)
for var in main_prog.block(0).all_parameters()] for var in main_prog.block(0).all_parameters()]
optimizer = fluid.optimizer.Adam(learning_rate=self.learning_rate)
optimizer.minimize(avg_cost)
for params in param_list: for params in param_list:
updated_p = fluid.layers.elementwise_sub( updated_p = fluid.layers.elementwise_sub(
x=params[0], y=params[1]) x=params[0], y=params[1])
fluid.layers.assign(input=updated_p, output=params[0]) fluid.layers.assign(input=updated_p, output=params[0])
optimizer.apply_optimize(avg_cost, startup_prog, params_grads)
param_sum = self.run_program(place, [data, label]) param_sum = self.run_program(place, [data, label])
return param_sum return param_sum
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册