Fix freeze_module pass for sharedtype (#42457)
Summary:
During cleanup phase, calling recordReferencedAttrs would record
the attributes which are referenced and hence kept.
However, if you have two instances of the same type which are preserved
through freezing process, as the added testcase shows, then during
recording the attributes which are referenced, we iterate through the
type INSTANCES that we have seen so far and record those ones.
Thus if we have another instance of the same type, we will just look at
the first instance in the list, and record that instances.
This PR fixes that by traversing the getattr chains and getting the
actual instance of the getattr output.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/42457
Test Plan:
python test/test_jit.py TestFreezing
Fixes #{issue number}
Reviewed By: zou3519
Differential Revision: D22898051
Pulled By: kimishpatel
fbshipit-source-id: 8b1d80f0eb40ab99244f931d4a1fdb28290a4683