[package] use WeakValueDictionary for global imported module registry (#51666)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51666
This ensures the modules will get properly unloaded when all references
to them die
Test Plan: Imported from OSS
Reviewed By: Lilyjjo
Differential Revision: D26232574
Pulled By: suo
fbshipit-source-id: a9889965aa35ba2f6cbbfbdd13e02357cc706cab