Mask all high dispatch keys in BackendSelect kernels (#37257)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37257
Previously, we were relying on fragile invariants to avoid collecting
and feeding high precedence, non-backend dispatch keys to backend
initialization machinery, which would assert on them. (These same
keys are then used for redispatch, so a second latent problem lurks
behind the first.) Here we mask off the BackendDispatch key and all
keys to its left.
Followup: move backend init code to backend-specific wrappers
(`CPUType` etc.). This will let us remove the backend init code from
both BackendSelect and STATIC_DISPATCH wrappers. (Though BackendSelect
will still need to compute a dispatch key, so the logic introduced
here will still be necessary.)
Test Plan: Imported from OSS
Differential Revision: D21235856
Pulled By: bhosmer
fbshipit-source-id: 1b8bd7897ed4b41a95718f3cfceddf4ee094744a