Move stuff to cpp files (#18301)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18301
Move code out of headers and templates into source files and non-templates.
Reviewed By: dzhulgakov
Differential Revision: D14572347
fbshipit-source-id: 9fd5d62d54000a95e93076cd73f591ba2c5c2653