avoid TLS in has_names (#53003)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/53003
Test Plan: Imported from OSS
Reviewed By: pbelevich
Differential Revision: D26719724
Pulled By: bhosmer
fbshipit-source-id: b575e2cec6509e287ed216d9926bbf1108eb7636