Skip to content
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ markers = [
]
filterwarnings = [
"error::FutureWarning",
# torch reads this deprecated dynamo config at import time, as a default argument in
# torch/testing/_internal/common_utils.py, which fails collection of the distributed tests
# todo: drop once torch stops reading it
"ignore:torch._dynamo.config.inline_inbuilt_nn_modules is deprecated:FutureWarning",
]
timeout = 900
# xfail_strict = true # todo
Expand Down
1 change: 0 additions & 1 deletion requirements/devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ datasets>=3.5.0
peft>=0.15.2

torchvision
torchaudio
7 changes: 7 additions & 0 deletions thunder/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import operator

from lightning_utilities.core.imports import compare_version

# PyTorch version constants
# `use_base_version` so that dev builds like "2.13.0a0+gitabc123" compare as "2.13.0"
_TORCH_GREATER_EQUAL_2_13 = compare_version("torch", operator.ge, "2.13.0", use_base_version=True)
11 changes: 11 additions & 0 deletions thunder/tests/test_auto_register_torchops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
import thunder
import thunder.torch.default_torch_ops as ops
from thunder.constants import _TORCH_GREATER_EQUAL_2_13
from thunder.torch import _get_torch_function_name
import torch

Expand Down Expand Up @@ -248,3 +249,13 @@ def fn_none(a):
cfn(a)
ops = thunder.get_auto_registered_torch_op_names(cfn)
assert expect == ops


def test_named_tensor_ops_follow_torch():
# torch 2.13 removed named tensors, and this table is built at import time.
named_tensor_methods = {"align_as", "align_to", "has_names", "refine_names", "rename"}
registered = {fn.__name__ for fn in ops.torch_auto_registered_ops[torch.Tensor]}
if _TORCH_GREATER_EQUAL_2_13:
assert not (named_tensor_methods & registered)
else:
assert named_tensor_methods <= registered
23 changes: 18 additions & 5 deletions thunder/torch/default_torch_ops.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import torch

from thunder.constants import _TORCH_GREATER_EQUAL_2_13

# torch 2.13 removed named tensors (pytorch/pytorch#173895), and this table is built at import
# time, so referencing the removed methods would break `import thunder` there.
_named_tensor_methods = (
[]
if _TORCH_GREATER_EQUAL_2_13
else [
torch.Tensor.align_as,
torch.Tensor.align_to,
torch.Tensor.has_names,
torch.Tensor.refine_names,
torch.Tensor.rename,
]
)

torch_auto_registered_ops = {
torch: [
torch._native_multi_head_attention,
Expand Down Expand Up @@ -358,8 +374,8 @@
torch.Tensor.addmv,
torch.Tensor.addr,
torch.Tensor.adjoint,
torch.Tensor.align_as,
torch.Tensor.align_to,
# align_as, align_to, has_names, refine_names and rename, on torch versions that still have them
*_named_tensor_methods,
torch.Tensor.aminmax,
torch.Tensor.angle,
torch.Tensor.arccos,
Expand Down Expand Up @@ -432,7 +448,6 @@
torch.Tensor.greater,
torch.Tensor.greater_equal,
torch.Tensor.half,
torch.Tensor.has_names,
torch.Tensor.heaviside,
torch.Tensor.histc,
torch.Tensor.histogram,
Expand Down Expand Up @@ -520,8 +535,6 @@
torch.Tensor.quantile,
torch.Tensor.rad2deg,
torch.Tensor.ravel,
torch.Tensor.refine_names,
torch.Tensor.rename,
torch.Tensor.renorm,
torch.Tensor.reshape_as,
torch.Tensor.resize,
Expand Down
Loading