Extract TensorPipeAgent's collectNames to be a standalone utility function (#53202)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/53202
Test Plan: Imported from OSS
Reviewed By: H-Huang
Differential Revision: D26791525
Pulled By: mrshenli
fbshipit-source-id: 8234c4d0350a5cd61926dce4ecc9e918960d30d2