Reland fix dispatch (#73231)
Summary:
Reland of https://github.com/pytorch/pytorch/issues/73045
Tweak class visibility to avoid windows linking issues.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73231
Reviewed By: bdhirsh
Differential Revision: D34402767
Pulled By: albanD
fbshipit-source-id: 50aaadf5389ca516fa6a5034d42eee56abe3c7f7
(cherry picked from commit 0fe53bdfb770f8e39eb3017f98e1d210f85eb78b)