Skip to content

Commit

Permalink
add ut for save/load
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiu committed May 12, 2021
1 parent b6d5a69 commit 8b12bdc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/paddle/fluid/tests/unittests/test_adam_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,28 @@ def test_adam_exception(self):
type=core.VarDesc.VarType.LOD_TENSOR)
paddle.disable_static()

def test_adam_save_load(self):
paddle.disable_static()
a = paddle.rand([4, 10])
linear = paddle.nn.Linear(10, 10)
b = linear(a)
state_dict = linear.state_dict()
fluid.save_dygraph(state_dict, "paddle_dy")

scheduler = paddle.optimizer.lr.NoamDecay(
d_model=0.01, warmup_steps=100, verbose=True)
adam = paddle.fluid.optimizer.Adam(
learning_rate=scheduler,
parameter_list=linear.parameters(),
use_global_beta_pow=True)
adam.minimize(b)
state_dict = adam.state_dict()
fluid.save_dygraph(state_dict, "paddle_dy")
para_state_dict, opti_state_dict = fluid.load_dygraph("paddle_dy")
adam.set_state_dict(opti_state_dict)

paddle.enable_static()


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

1 comment on commit 8b12bdc

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

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

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.