Skip to content

Commit

Permalink
add print to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaishaonvjituizi committed May 4, 2022
1 parent f353873 commit 3a21267
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/paddle/fluid/tests/unittests/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ def forward(self, x):
asgd = paddle.optimizer.ASGD(learning_rate=1., parameters=model.parameters(), t0=1)

loss = model(x)
print(f'1: w grad before bw: {model._w.grad}')
loss.backward()
print(f'1: w grad: {model._w.grad}')
asgd.step()
assert np.allclose(model._w.numpy(), np_neg_ones)
assert np.allclose(asgd.averaged_parameters()[0].numpy(), np_neg_ones)
asgd.clear_grad()

loss = model(x)
print(f'2: w grad before bw: {model._w.grad}')
loss.backward()
print(f'2: w grad: {model._w.grad}')
asgd.step()
assert np.allclose(model._w.numpy(), np_neg_ones * 2)
assert np.allclose(asgd.averaged_parameters()[0].numpy(), np_neg_ones * 2)
Expand Down

0 comments on commit 3a21267

Please sign in to comment.