Revert "Revert D18171156: Merge Tensor and Variable." (#29299)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29299
This reverts commit 9c43b16df9dad3dfb4da1efab68d8c88e6437e8f, but also
with the changes from D18348622. Comments there:
thpp-compatibility is used by admarket/adreview/service:adreviewservice and
libtorch is too big for the service to deal with.
thpp-compatibility doesn't support autograd, so we hack around dispatching
variables by using AutoNonVariableTypeMode everywhere we call into ATen,
so we never attempt to call into Variable stubs. If you get it wrong,
you'll get an error like:
```
what(): Could not run 'aten::empty' with arguments from the 'VariableTensorId' backend. 'aten::empty' is only available for these backends: [SparseCPUTensorId, CPUTensorId, MkldnnCPUTensorId]. (lookup_ at caffe2/aten/src/ATen/core/dispatch/DispatchTable.h:298)
```
Test Plan:
Imported from OSS
```
buck test //thpp-compatibility/...
buck build mode/opt-clang admarket/adreview/service:adreviewservice
```
adreviewservice canary: https://our.intern.facebook.com/intern/ads/canary/422290029716387895 (comparing against parent comment due to current breakage) ==> experiment store https://our.intern.facebook.com/intern/experiment_store/experiment/43990006/
adfinder canary: https://our.intern.facebook.com/intern/ads/canary/422268535840333934
adindexer canary: https://our.intern.facebook.com/intern/ads/canary/422268550559034675
adreview second canary: https://our.intern.facebook.com/intern/ads/canary/422307863515591925
canary without thpp-compat fixups https://our.intern.facebook.com/intern/ads/canary/422308951649168772
Reviewed By: dreiss
Differential Revision: D18353504
Pulled By: ezyang
fbshipit-source-id: 65feaba39fa07bb66762810909aeb38868668a30