Skip to content

Commit 1274297

Browse files
swolchokpytorchmergebot
authored andcommitted
Remove __torch_dispatch__ check in THPVariable_make_dtensor (#162337)
We control DTensor, so we can just guarantee there isn't a programming error with __torch_dispatch__. (The guard is already less-than-perfect; see the note that the deleted comment refers to.) Pull Request resolved: #162337 Approved by: https://github.com/Skylion007 ghstack dependencies: #161591, #161595, #161633, #161634, #161692, #162219, #162220, #162218, #161596
1 parent f68f76d commit 1274297

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

torch/csrc/autograd/python_variable.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,14 +808,18 @@ static PyObject* THPVariable_make_dtensor(
808808
"cls must be a type (got ",
809809
Py_TYPE(cls)->tp_name,
810810
")");
811-
// See note about the __torch_dispatch__ check in
812-
// THPVariable_make_wrapper_subclass above.
811+
812+
#ifndef NDEBUG
813+
// This is specifically for making a DTensor, which we know defines
814+
// __torch_dispatch__. Check anyway in debug builds in case somebody
815+
// removes it.
813816
py::object attr = PyObject_FastGetAttrString(cls, "__torch_dispatch__");
814817
TORCH_CHECK_TYPE(
815818
attr.ptr() != nullptr &&
816819
attr.ptr() != torch::disabled_torch_dispatch_impl(),
817820
((PyTypeObject*)cls)->tp_name,
818821
" must define __torch_dispatch__");
822+
#endif
819823

820824
const auto& local_tensor = r.tensor(3);
821825
const auto options = TensorOptions()

0 commit comments

Comments
 (0)