Refactor internal methods into debugging utilities (#51737)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/51737
Test Plan: Imported from OSS
Reviewed By: pbelevich
Differential Revision: D26288613
Pulled By: ansley
fbshipit-source-id: 4504b1af5be7a200c1a6a376d432d7224eb8a796