[package] pre-emptively install submodules (#48799)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/48799
Python's IMPORT_FROM bytecode will bypass the import infrastructure
when a packaging being loaded as part of a cirular dependency is being
accessed from the module _before_ that package has finished loading
and is installed on the module. Since we cannot override the lookup
on sys.modules, this PR pre-emptively does the module assignment before
running the submodules initialization code.
Note: this appears to work, but it is not clear to me why python doesn't
do this by default. It is possible that the logic for creating modules
is flexible enough in generic python that this interception between creating
the module and running its code is not always possible.
Test Plan: Imported from OSS
Reviewed By: suo
Differential Revision: D25312467
Pulled By: zdevito
fbshipit-source-id: 6fe3132af29364ccb2b3cabdd2b847d0a09eb515