[PyTorch] Fix return value of IValue::to for Tensor/String (#51463)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51463
We can make the return type of the `to()` template match the return type of toFoo() by using the same technique we use for `list_element_to_const_ref`. Also simplifies `list_element_to_const_ref`.
ghstack-source-id: 121363468
Test Plan:
CI
built and ran AdIndexer benchmark w/ batch size 1 under perf stat
--repeat 5 to make sure it didn't regress
Reviewed By: bhosmer
Differential Revision: D26163848
fbshipit-source-id: b8563263b9f9fa5311c7d7cedc89e28bc5badda0