Skip to content

Commit 00b8ec9

Browse files
leofangemcastilloclaude
committed
Add upper bound to torch version check (cap at 2.11)
The pyobj_to_aten_handle trick and AtenTensorHandle == at::Tensor* identity are undocumented internals that could change. Cap at the latest tested version so unknown future versions fall back to the standard DLPack/CAI paths. Bump after verifying each new release. Co-Authored-By: Emilio Castillo <ecastillo@nvidia.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 74798e7 commit 00b8ec9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cuda_core/cuda/core/_memoryview.pyx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ cdef dict _torch_type_cache = {}
4343
cdef object _torch_version_ok = None
4444

4545
cdef inline bint _torch_version_check():
46-
"""Return True if torch >= 2.3 (AOTI ABI requirement). Memoized."""
46+
"""Return True if 2.3 <= torch <= 2.11 (known AOTI ABI range). Memoized.
47+
48+
Lower bound: AOTI functions we use were introduced in PyTorch 2.3.
49+
Upper bound: the ``pyobj_to_aten_handle`` trick relies on the
50+
THPVariable struct layout (PyObject_HEAD followed by at::Tensor cdata)
51+
and the identity ``AtenTensorHandle == at::Tensor*``. Both are
52+
undocumented internals that could change in a future PyTorch version.
53+
We cap at the latest version we have tested against; unknown versions
54+
fall back to the standard DLPack/CAI paths. Bump the upper bound
55+
after verifying a new PyTorch release.
56+
"""
4757
global _torch_version_ok
4858
if _torch_version_ok is not None:
4959
return <bint>_torch_version_ok
@@ -54,7 +64,7 @@ cdef inline bint _torch_version_check():
5464
try:
5565
major, minor = int(torch.__version__.split(".")[0]), \
5666
int(torch.__version__.split(".")[1])
57-
_torch_version_ok = (major, minor) >= (2, 3)
67+
_torch_version_ok = (2, 3) <= (major, minor) <= (2, 11)
5868
except (ValueError, IndexError):
5969
_torch_version_ok = False
6070
return <bint>_torch_version_ok

0 commit comments

Comments
 (0)