Fix static linkage cases and NO_DISTRIBUTED=1 + CUDA (#16705) (#17337)
Summary:
Attempt #2 (attempt 1 is https://github.com/pytorch/pytorch/pull/16705 and got reverted because of CI failures)
Fixes https://github.com/pytorch/pytorch/issues/14805
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17337
Differential Revision: D14175626
Pulled By: soumith
fbshipit-source-id: 66f2e10e219a1bf88ed342ec5c89da6f2994d8eb