Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions python/paddle/fluid/tests/unittests/test_weight_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def test_weight_decay(self):
for place in get_places():
loss = self.check_weight_decay(place, model, use_parallel_exe=False)

# TODO(zcd): should test use_reduce=True
loss2 = self.check_weight_decay(
place, model, use_parallel_exe=True, use_reduce=False)

Expand All @@ -175,16 +176,6 @@ def test_weight_decay(self):
"Expect " + str(loss[i]) + "\n" + "But Got" + str(loss2[i])
+ " in class " + self.__class__.__name__)

loss3 = self.check_weight_decay(
place, model, use_parallel_exe=True, use_reduce=True)

for i in range(len(loss)):
self.assertTrue(
np.isclose(
a=loss[i], b=loss3[i], rtol=5e-5),
"Expect " + str(loss[i]) + "\n" + "But Got" + str(loss2[i])
+ " in class " + self.__class__.__name__)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After analysis of this unit test, the reduce model doesn't support this usage:

            param_list = [(var, var * self.learning_rate)
                          for var in main_prog.block(0).all_parameters()]

            optimizer = fluid.optimizer.Adagrad(
                learning_rate=self.learning_rate)
            optimizer.minimize(avg_cost)

            for params in param_list:
                updated_p = fluid.layers.elementwise_sub(
                    x=params[0], y=params[1])
                fluid.layers.assign(input=updated_p, output=params[0])

Because, in Reduce mode, all the optimizer ops are scattered to different cards equally according to the op's role(which is opt_role) to update different parameter in a specified card, and after that, the updated parameters are broadcast to other cards. But the op_role of the above ops(below optimizer.minimize(avg_cost)) are forward, so the results are not right.



if __name__ == '__main__':
unittest.main()