Optimize module path finding (#52990)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52990
This PR changes module path finding from O(N^2) to O(1)
Test Plan: Imported from OSS
Reviewed By: anjali411
Differential Revision: D26779399
Pulled By: ansley
fbshipit-source-id: ff49d8e10bb4f82583ab4757926198ed46507c29