Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 3 additions & 34 deletions test/cpp_extensions/test_libtorch_agnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TestCase,
xfailIf,
)
from torch.testing._internal.common_utils import xfailIfTorchDynamo


@unittest.skipIf(
Expand All @@ -38,30 +39,20 @@ class TestLibtorchAgnostic(TestCase):
"""
Tests for the libtorch_agnostic extensions, grouped by the release that
introduced the APIs they exercise: libtorch_agn_2_9 through
libtorch_agn_2_14.
libtorch_agn_2_15.
"""

@classmethod
def setUpClass(cls):
base_dir = Path(__file__).parent
for version in ("2_9", "2_10", "2_11", "2_12", "2_13", "2_14"):
for version in ("2_9", "2_10", "2_11", "2_12", "2_13", "2_14", "2_15"):
try:
__import__(f"libtorch_agn_{version}")
except Exception:
install_cpp_extension(
extension_root=base_dir / f"libtorch_agn_{version}_extension"
)

if (current_major > 2) or (current_major == 2 and current_minor >= 15):
try:
import libtorch_agn_2_15 # noqa: F401
except Exception:
install_cpp_extension(
extension_root=base_dir / "libtorch_agn_2_15_extension"
)
else:
print(f"Skipping 2.15 extension (running on PyTorch {torch.__version__})")

@onlyCPU
def test_slow_sgd(self, device):
import libtorch_agn_2_9 as libtorch_agnostic
Expand Down Expand Up @@ -299,8 +290,6 @@ def test_my_is_pinned_cuda_true(self, device):

pinned = torch.randn(2, 3, device="cpu", pin_memory=True)
self.assertTrue(libtorch_agnostic.ops.my_is_pinned(pinned))

@skipIfTorchVersionLessThan(2, 10)
@parametrize("descending", [False, True])
@parametrize("dim", [0, 1, -1, -3])
def test_my_sort(self, device, dim, descending):
Expand All @@ -314,8 +303,6 @@ def test_my_sort(self, device, dim, descending):

values, _ = my_sort(t)
self.assertEqual(values, torch.sort(t).values)

@skipIfTorchVersionLessThan(2, 10)
@parametrize("descending", [False, True])
@parametrize("dim", [0, 1, -1, -3])
def test_my_sort_stable(self, device, dim, descending):
Expand All @@ -336,8 +323,6 @@ def test_my_sort_stable(self, device, dim, descending):
expected = torch.sort(t_view, stable=True, dim=dim, descending=descending)
self.assertEqual(values, expected.values)
self.assertEqual(indices, expected.indices)

@skipIfTorchVersionLessThan(2, 10)
@skipIfTorchDynamo("Dynamo failed to run FX node with fake tensors")
def test_my_masked_select(self, device):
import libtorch_agn_2_10 as libtorch_agnostic
Expand All @@ -358,8 +343,6 @@ def test_my_masked_select(self, device):

with self.assertRaisesRegex(RuntimeError, "expected BoolTensor for mask"):
libtorch_agnostic.ops.my_masked_select(t, mask.to(torch.int64))

@skipIfTorchVersionLessThan(2, 10)
@dtypes(torch.float32, torch.float64)
@parametrize(
"torch_op,batch_shape",
Expand All @@ -379,7 +362,6 @@ def test_my_mm_out_ops(self, device, dtype, torch_op, batch_shape):
self.assertEqual(id(result), id(out))

@onlyCUDA
@skipIfTorchVersionLessThan(2, 10)
@dtypes(torch.float16, torch.bfloat16)
@parametrize(
"torch_op,batch_shape",
Expand All @@ -397,8 +379,6 @@ def test_my_mm_out_dtype_ops(self, device, dtype, torch_op, batch_shape):
result = stable_op(out, a, b, torch.float32)
self.assertEqual(out, torch_op(a, b, out_dtype=torch.float32))
self.assertEqual(id(result), id(out))

@skipIfTorchVersionLessThan(2, 10)
def test_my_flip(self, device):
import libtorch_agn_2_10 as libtorch_agnostic

Expand All @@ -409,7 +389,6 @@ def test_my_flip(self, device):

@skipIfWindows(msg="TemporaryFileName cannot unlink a memory-mapped file")
@onlyCPU
@skipIfTorchVersionLessThan(2, 10)
def test_my_from_file(self, device):
import libtorch_agn_2_10 as libtorch_agnostic

Expand Down Expand Up @@ -462,7 +441,6 @@ def test_pyobject_non_tensor_raises(self, device):
libtorch_agnostic._interop.pyobject_roundtrip("not a tensor")

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
def test_pyobject_is_tensor(self, device):
import libtorch_agn_2_15 as libtorch_agnostic

Expand All @@ -474,7 +452,6 @@ def test_pyobject_is_tensor(self, device):
self.assertFalse(is_tensor(torch.float32))

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
def test_pyobject_tensor_subclass(self, device):
import libtorch_agn_2_14
import libtorch_agn_2_15
Expand All @@ -489,7 +466,6 @@ class TensorSubclass(torch.Tensor):
self.assertEqual(y.data_ptr(), x.data_ptr())

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
@skipIfTorchDynamo("Dynamo intercepts the spoofed __class__")
def test_pyobject_spoofed_tensor_class(self, device):
import libtorch_agn_2_14
Expand All @@ -507,7 +483,6 @@ def __class__(self):
libtorch_agn_2_14._interop.pyobject_roundtrip(obj)

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
@parametrize(
"dtype",
[
Expand All @@ -528,7 +503,6 @@ def test_pyobject_dtype_roundtrip(self, device, dtype):
self.assertIs(out, dtype)

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
# "cuda" (no index) must not come back as cuda:0; constructing the
# device objects needs no GPU.
@parametrize("roundtrip_device", ["cpu", "meta", "cuda", "cuda:1"])
Expand All @@ -542,7 +516,6 @@ def test_pyobject_device_roundtrip(self, device, roundtrip_device):
self.assertEqual(out.index, dev.index)

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
def test_pyobject_tensor_dtype_and_device(self, device):
import libtorch_agn_2_15 as libtorch_agnostic

Expand All @@ -551,31 +524,27 @@ def test_pyobject_tensor_dtype_and_device(self, device):
self.assertEqual(libtorch_agnostic._interop.tensor_device(x), x.device)

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
def test_pyobject_non_dtype_raises(self, device):
import libtorch_agn_2_15 as libtorch_agnostic

with self.assertRaisesRegex(RuntimeError, "expected torch.dtype"):
libtorch_agnostic._interop.dtype_roundtrip("not a dtype")

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
def test_pyobject_unsupported_dtype_raises(self, device):
import libtorch_agn_2_15 as libtorch_agnostic

with self.assertRaisesRegex(RuntimeError, "Not yet supported ScalarType"):
libtorch_agnostic._interop.dtype_roundtrip(torch.qint8)

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
def test_pyobject_non_device_raises(self, device):
import libtorch_agn_2_15 as libtorch_agnostic

with self.assertRaisesRegex(RuntimeError, "expected torch.device"):
libtorch_agnostic._interop.device_roundtrip("not a device")

@onlyCPU
@skipIfTorchVersionLessThan(2, 15)
def test_pyobject_unsupported_device_raises(self, device):
import libtorch_agn_2_15 as libtorch_agnostic

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
funcol = torch.ops.c10d_functional

from torch.testing._internal.common_fsdp import get_devtype
from torch.testing._internal.common_utils import instantiate_parametrized_tests, parametrize


device_type = torch.device(get_devtype())
Expand Down
1 change: 1 addition & 0 deletions test/distributed/checkpoint/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import torch.distributed as dist
import torch.distributed.checkpoint as dcp
from torch.distributed.checkpoint._fsspec_filesystem import (
_FileSystem,
FileSystem,
FsspecReader,
FsspecWriter,
Expand Down
1 change: 1 addition & 0 deletions test/export/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
)
from torch.testing._internal.inductor_utils import HAS_TRITON
from torch.testing._internal.torchbind_impls import init_torchbind_implementations
from torch._export.utils import wrap_method


try:
Expand Down
1 change: 1 addition & 0 deletions test/export/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
subtest,
TestCase,
)
from torch._subclasses.fake_tensor import is_fake_tensor


# Various data types (preserved over operations).
Expand Down
6 changes: 0 additions & 6 deletions test/functorch/test_eager_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5807,12 +5807,6 @@ def f(x):
only_for=only_for,
allow_xpu=True,
)
instantiate_device_type_tests(
TestComposabilityDevice,
globals(),
only_for=only_for,
allow_xpu=True,
)
instantiate_device_type_tests(
TestExamplesCorrectnessDevice,
globals(),
Expand Down
9 changes: 1 addition & 8 deletions test/functorch/test_memory_efficient_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from functorch import make_fx
from torch._functorch.compile_utils import fx_graph_cse
from torch.testing._internal.common_utils import run_tests, TestCase
from torch.testing._internal.common_utils import HardwareClassification


HAS_CUDA = torch.cuda.is_available()
Expand Down Expand Up @@ -316,13 +317,5 @@ def f(x):
check(fx_g, t, -1, graph_input=True)


instantiate_device_type_tests(
TestMemoryEfficientOpAuthoringDevice,
globals(),
only_for=("cuda", "xpu"),
allow_xpu=True,
)


if __name__ == "__main__":
run_tests()
1 change: 1 addition & 0 deletions test/fx/test_lazy_graph_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from torch.fx.experimental.proxy_tensor import make_fx
from torch.testing._internal.common_utils import TestCase
from torch.testing._internal.common_utils import HardwareClassification


class TestLazyGraphModule(TestCase):
Expand Down
1 change: 1 addition & 0 deletions test/inductor/test_aot_inductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
has_triton_experimental_host_tma,
has_triton_tensor_descriptor_host_tma,
)
from torch.testing._internal.common_utils import TEST_WITH_ROCM


requires_cuda_tma = unittest.skipIf(
Expand Down
3 changes: 2 additions & 1 deletion test/inductor/test_device_backend_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
run_tests,
TestCase,
)
import torch
from torch._dynamo.device_interface import CpuInterface, CudaInterface, get_interface_for_device


class TestMultiProcessorCount(TestCase):
Expand Down Expand Up @@ -168,7 +170,6 @@ def test_cuda_overrides_match_inline_conditions(self):
def test_registered_non_cuda_inherits_base_defaults(self):
self.assertIs(get_interface_for_device("cpu"), CpuInterface)
self.assertIs(get_interface_for_device("xpu"), XpuInterface)
self.assertIs(get_interface_for_device("mtia"), MtiaInterface)
self.assertTrue(CpuInterface.is_fp32_attention_fusion_safe(torch.float32))
self.assertTrue(CpuInterface.is_fp32_softmax_attention_fusion_safe())
self.assertFalse(CpuInterface.keep_attention_on_math_path())
Expand Down
1 change: 1 addition & 0 deletions test/inductor/test_fused_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
HAS_CUDA_AND_TRITON,
HAS_XPU_AND_TRITON,
)
from torch.testing._internal.common_utils import recover_orig_fp32_precision


def checkpoint_wrapper(fn):
Expand Down
4 changes: 4 additions & 0 deletions test/inductor/test_inductor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from torch._inductor.utils import do_bench_using_profiling
from torch._inductor.virtualized import NullHandler, V
from torch.autograd import DeviceType
from torch.fx.experimental._constant_symnode import ConstantIntNode
from torch.fx.experimental.symbolic_shapes import DimDynamic, ShapeEnv
from torch.testing._internal.common_utils import instantiate_parametrized_tests, parametrize
from types import SimpleNamespace


log = logging.getLogger(__name__)
Expand Down
15 changes: 0 additions & 15 deletions test/inductor/test_torchinductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4229,8 +4229,6 @@ def fn(a, b):
self.common(fn, (a, b))
b_neg = torch.full_like(a, -divisor)
self.common(fn, (a, b_neg))

@skip_if_halide # floordiv goes through floats, inexact for large values
def test_floordiv_int_min_negative_divisor(self):
# Regression test for https://github.com/pytorch/pytorch/issues/198545
def fn(a, b):
Expand Down Expand Up @@ -6911,7 +6909,6 @@ def test_adaptive_max_pool3d_out_decomposition(self):
# halide/mps take the non-logical-index path in _pool_argmax_inner_fn, so the
# window offsets are still physical there; halide additionally fails to schedule
# the fallback argmax for this shape.
@skip_if_halide
@skip_if_mps
def test_adaptive_max_pool2d_transposed_indices(self):
# transposed input, indices must be logical and not physical offsets
Expand Down Expand Up @@ -7285,7 +7282,6 @@ def fn(x):
# same as test_adaptive_max_pool2d_transposed_indices: halide/mps take the
# non-logical-index path in _pool_argmax_inner_fn and still return physical
# window offsets.
@skip_if_halide
@skip_if_mps
def test_max_pool2d_transposed_indices(self):
# transposed input, indices must be logical and not physical offsets
Expand Down Expand Up @@ -11602,8 +11598,6 @@ def fn(x, w):
x = torch.tensor([-2, 0, 1, 2]).repeat(16).view(8, 8).float()
w = 2 * torch.eye(8)
self.common(fn, (x, w))

@skip_if_halide # won't fuse a read of the buffer it writes in place
def test_masked_fill_of_realized_buffer_kernel_count(self):
# The fill writes the realized mm output in place, in one kernel.
def fn(x, w, m):
Expand Down Expand Up @@ -11691,13 +11685,6 @@ def copy_into_strided_empty(x):

if case == "fsdp_copy_then_mutate" and not hasattr(torch.ops.fsdp, "copy_"):
self.skipTest("needs torch.ops.fsdp.copy_")
if case in (
"foreach_reads_sibling_input",
"foreach_reads_sibling_across_groups",
) and is_halide_backend(self.device):
# Halide gets the inputs right but not x + 0, which misses x's
# in-place update.
self.skipTest("halide: an output misses its input's in-place update")
fn = {
f.__name__: f
for f in (
Expand Down Expand Up @@ -14594,8 +14581,6 @@ def fn(x, y, w):

x = torch.ones(8, dtype=torch.bfloat16)
self.common(fn, (x, torch.zeros_like(x), torch.tensor(0.95)))

@skip_if_halide
def test_fp16_cast_log1p(self):
self.common(lambda x: x.half().log1p(), (torch.rand(8) * 1e-3,))

Expand Down
1 change: 1 addition & 0 deletions test/inductor/test_torchinductor_opinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from torch.utils._dtype_abbrs import dtype_abbrs
from torch.utils._python_dispatch import TorchDispatchMode
from torch.utils._pytree import tree_leaves, tree_map
from torch.testing._internal.common_utils import parametrize


try:
Expand Down
1 change: 1 addition & 0 deletions test/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def upload_adhoc_failure_json(*args, **kwargs):


from torch.testing._internal.common_utils import HardwareClassification
import subprocess


_HC_CHOICES = [e.name for e in HardwareClassification]
Expand Down
1 change: 1 addition & 0 deletions test/test_binary_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
torch_to_numpy_dtype_dict,
xfailIfTorchDynamo,
)
from torch.testing._internal.common_device_type import onlyAccelerator


if TEST_SCIPY:
Expand Down
Loading