Allow attributes of OrderedDict to be saved (#3862)
Allow attributes of OrderedDict to be saved (#3862)

Summary:
Pull Request resolved: https://github.com/pytorch/fairseq/pull/3862

We resolved a bug for missing "_metadata" attribute for pytorch models during checkpoing saving and loading using forced state["model"]["_metadata"], but it's not an efficient solution due to expensive model.state_dict() invocation. This diff offers an alternative solution.

Reviewed By: zhengwy888

Differential Revision: D30857147

fbshipit-source-id: 5daa978e2a558ad4159e2da55470253950151bde

pytorch/fairseq,pytorch/fairseq,pytorch/fairseq