Re apply optional ScalarType changes (#22237)
Summary:
This is (mostly) the re-application of:
https://github.com/pytorch/pytorch/pull/21088
which was reverted due to an issue conflicting with changes in:
https://github.com/pytorch/pytorch/pull/22104
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22237
Differential Revision: D16012838
Pulled By: nairbv
fbshipit-source-id: 35f4a73c97ab68b4e2648aca96b2176f07b5a883