Skip to content

Commit

Permalink
Windows Dynamo Error Removal CI Check (#121026)
Browse files Browse the repository at this point in the history
Link to landed trunk PR (if applicable):
* #115969

Criteria Category:
* Low risk critical fixes for backwards compatibility

Approved-by: PaliC, thiagocrepaldi
  • Loading branch information
Thiago Crepaldi committed Mar 12, 2024
1 parent 3184b6f commit d37ef49
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 15 deletions.
3 changes: 2 additions & 1 deletion test/export/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
parametrize,
run_tests,
TestCase,
IS_WINDOWS
)


@unittest.skipIf(IS_WINDOWS, "Windows not supported for this test")
@unittest.skipIf(not torchdynamo.is_dynamo_supported(), "dynamo doesn't support")
class ExampleTests(TestCase):
# TODO Maybe we should make this tests actually show up in a file?
Expand Down
8 changes: 6 additions & 2 deletions test/export/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
from torch.export import Constraint, Dim, export
from torch.fx.experimental.proxy_tensor import make_fx
from torch.testing import FileCheck
from torch.testing._internal.common_utils import run_tests, TestCase
from torch.testing._internal.common_utils import (
run_tests,
TestCase,
IS_WINDOWS,
)
from torch.utils._pytree import (
LeafSpec,
tree_flatten,
Expand Down Expand Up @@ -95,7 +99,7 @@ def branch_on_shape(x: torch.Tensor):
# Being able to export means shape is preserved as static
export(branch_on_shape, inp)


@unittest.skipIf(IS_WINDOWS, "Windows isn't supported for this case")
@unittest.skipIf(not torchdynamo.is_dynamo_supported(), "dynamo isn't support")
class TestExport(TestCase):

Expand Down
3 changes: 2 additions & 1 deletion test/export/test_pass_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from torch._dynamo.eval_frame import is_dynamo_supported
from torch._export import export
from torch._export.pass_base import _ExportPassBase
from torch.testing._internal.common_utils import run_tests, TestCase
from torch.testing._internal.common_utils import run_tests, TestCase, IS_WINDOWS


@unittest.skipIf(not is_dynamo_supported(), "Dynamo not supported")
Expand Down Expand Up @@ -37,6 +37,7 @@ class NullPass(_ExportPassBase):
self.assertEqual(new_node.op, old_node.op)
self.assertEqual(new_node.target, old_node.target)

@unittest.skipIf(IS_WINDOWS, "Windows not supported")
def test_cond(self) -> None:
class M(torch.nn.Module):
def __init__(self):
Expand Down
4 changes: 3 additions & 1 deletion test/export/test_passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import operator

import torch
from torch.testing._internal.common_utils import run_tests, TestCase
from torch.testing._internal.common_utils import run_tests, TestCase, IS_WINDOWS
from torch.testing import FileCheck
from torch._dynamo.eval_frame import is_dynamo_supported
from torch._export import export
Expand All @@ -26,6 +26,7 @@
from functorch.experimental.control_flow import cond
from torch.fx.passes.operator_support import OperatorSupport
from torch.fx.passes.infra.partitioner import Partition

from torch.utils import _pytree as pytree


Expand Down Expand Up @@ -274,6 +275,7 @@ def forward(self, x):
new_inp = torch.tensor([1, 1, 1, 1])
self.assertEqual(mod(new_inp), ep(new_inp))

@unittest.skipIf(IS_WINDOWS, "Windows not supported")
def test_runtime_assert_inline_constraints_for_cond(self) -> None:
class M(torch.nn.Module):
def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion test/export/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def f(x: torch.Tensor) -> torch.Tensor:
self.assertEqual(node.inputs[3].name, "side")
self.assertEqual(node.inputs[3].arg.as_string, "right")


@unittest.skipIf(IS_WINDOWS, "Windows not supported for this test")
@unittest.skipIf(not torchdynamo.is_dynamo_supported(), "dynamo doesn't support")
class TestDeserialize(TestCase):
def check_graph(self, fn, inputs, dynamic_shapes=None, _check_meta=True) -> None:
Expand Down
7 changes: 6 additions & 1 deletion test/export/test_unflatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
)
from torch.fx.experimental.proxy_tensor import make_fx
from torch.testing import FileCheck
from torch.testing._internal.common_utils import run_tests, TestCase
from torch.testing._internal.common_utils import (
run_tests,
TestCase,
IS_WINDOWS,
)
from torch.utils._pytree import (
LeafSpec,
tree_flatten,
Expand Down Expand Up @@ -188,6 +192,7 @@ def forward(self, x):
id(getattr(unflattened_module.sub_net, "2")),
)

@unittest.skipIf(IS_WINDOWS, "Windows not supported for this test")
def test_unflatten_preserve_signature(self):
class NestedChild(torch.nn.Module):
def forward(self, zx, y):
Expand Down
2 changes: 2 additions & 0 deletions test/export/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from torch.testing._internal.common_utils import (
run_tests,
TestCase,
IS_WINDOWS,
)

TEST_UPGRADERS = {
Expand Down Expand Up @@ -112,6 +113,7 @@ def fn(a: torch.Tensor, b):
custom_op_count = count_op(upgraded.graph, "aten::div__Scalar_mode_0_3")
self.assertEqual(custom_op_count, 1)

@unittest.skipIf(IS_WINDOWS, "Test case not supported on Windows")
def test_div_upgrader_pass_return_new_op_after_retrace(self):
def fn(a: torch.Tensor, b):
return torch.ops.aten.div.Scalar_mode(a, b, rounding_mode='trunc')
Expand Down
4 changes: 3 additions & 1 deletion test/export/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from torch._export.verifier import SpecViolationError, Verifier
from torch.export.exported_program import InputKind, InputSpec, TensorArgument
from torch.testing._internal.common_utils import run_tests, TestCase
from torch.testing._internal.common_utils import run_tests, TestCase, IS_WINDOWS

@unittest.skipIf(not is_dynamo_supported(), "dynamo isn't supported")
class TestVerifier(TestCase):
Expand Down Expand Up @@ -50,6 +50,7 @@ def f(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
with self.assertRaises(SpecViolationError):
verifier.check(ep)

@unittest.skipIf(IS_WINDOWS, "Windows not supported for this test")
def test_verifier_higher_order(self) -> None:
def f(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
def true_fn(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
Expand All @@ -67,6 +68,7 @@ def false_fn(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
verifier = Verifier()
verifier.check(ep)

@unittest.skipIf(IS_WINDOWS, "Windows not supported for this test")
def test_verifier_nested_invalid_module(self) -> None:
def f(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
def true_fn(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
Expand Down
2 changes: 2 additions & 0 deletions test/functorch/test_aotdispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
run_tests,
IS_ARM64,
IS_MACOS,
IS_WINDOWS,
IS_X86,
compare_equal_outs_and_grads,
outs_and_grads,
Expand Down Expand Up @@ -2940,6 +2941,7 @@ def fn(p, x):
):
aot_export_module(mod, [inp], trace_joint=True, output_loss_index=1)

@unittest.skipIf(IS_WINDOWS, "Windows isn't supported for this case")
@unittest.skipIf(not torch._dynamo.is_dynamo_supported(), "Cond needs dynamo to run")
def test_aot_export_with_torch_cond(self):
class M(torch.nn.Module):
Expand Down
5 changes: 3 additions & 2 deletions test/functorch/test_control_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functorch.experimental import control_flow
from functorch.experimental.control_flow import UnsupportedAliasMutationException, cond
from torch.fx.experimental.proxy_tensor import make_fx
from torch.testing._internal.common_utils import run_tests, TestCase
from torch.testing._internal.common_utils import run_tests, TestCase, IS_WINDOWS
from torch.testing._internal.common_quantization import skipIfNoDynamoSupport
from torch._subclasses.functional_tensor import FunctionalTensor

Expand Down Expand Up @@ -77,7 +77,7 @@ def forward(self, *operands):
return self._reduce(*operands)



@unittest.skipIf(IS_WINDOWS, "Windows not supported for this test")
@skipIfNoDynamoSupport
class TestControlFlow(TestCase):
def setUp(self):
Expand Down Expand Up @@ -250,6 +250,7 @@ def fwbw(map_op, f, x, y):
self.assertEqual(true_outs, fake_outs)


@unittest.skipIf(IS_WINDOWS, "Windows not supported for this test")
@skipIfNoDynamoSupport
class TestControlFlowTraced(TestCase):
def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions test/quantization/pt2e/test_x86inductor_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
NodeSpec as ns,
QuantizationTestCase,
skipIfNoX86,
skipIfNoDynamoSupport,
skipIfNoInductorSupport,
)
from torch.testing._internal.common_quantized import override_quantized_engine
from enum import Enum
Expand Down Expand Up @@ -321,7 +321,7 @@ def _test_quantizer(
)
return export_model, prepare_model, convert_model

@skipIfNoDynamoSupport
@skipIfNoInductorSupport
class TestQuantizePT2EX86Inductor(X86InductorQuantTestCase):
@skipIfNoX86
def test_conv2d(self):
Expand Down
9 changes: 8 additions & 1 deletion test/test_content_store.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# Owner(s): ["oncall: pt2"]

import tempfile
import unittest

import torch
from torch._prims.debug_prims import load_tensor_reader
from torch._subclasses.fake_tensor import FakeTensor, FakeTensorMode
from torch.multiprocessing.reductions import StorageWeakRef
from torch.testing._internal.common_device_type import instantiate_device_type_tests
from torch.testing._internal.common_utils import run_tests, skipIfRocm, TestCase
from torch.testing._internal.common_utils import (
IS_WINDOWS,
run_tests,
skipIfRocm,
TestCase,
)
from torch.utils._content_store import (
ContentStoreReader,
ContentStoreWriter,
hash_storage,
)


@unittest.skipIf(IS_WINDOWS, "Test case not supported on Windows")
class TestContentStore(TestCase):
def test_basic(self, device):
# setup test data
Expand Down
1 change: 1 addition & 0 deletions torch/_dynamo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
explain,
export,
is_dynamo_supported,
is_inductor_supported,
optimize,
optimize_assert,
OptimizedModule,
Expand Down
7 changes: 7 additions & 0 deletions torch/_dynamo/backends/inductor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# mypy: ignore-errors

import sys

from torch._dynamo import register_backend


@register_backend
def inductor(*args, **kwargs):
if sys.platform == "win32":
raise RuntimeError("Windows not yet supported for inductor")

# do import here to avoid loading inductor into memory when it is not used
from torch._inductor.compile_fx import compile_fx

Expand Down
17 changes: 15 additions & 2 deletions torch/_dynamo/eval_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,6 @@ def __call__(self, fn):


def check_if_dynamo_supported():
if sys.platform == "win32":
raise RuntimeError("Windows not yet supported for torch.compile")
if sys.version_info >= (3, 12):
raise RuntimeError("Python 3.12+ not yet supported for torch.compile")

Expand All @@ -712,6 +710,21 @@ def is_dynamo_supported():
return False


def check_if_inductor_supported():
check_if_dynamo_supported()

if sys.platform == "win32":
raise RuntimeError("Windows not yet supported for inductor")


def is_inductor_supported():
try:
check_if_inductor_supported()
return True
except Exception:
return False


def optimize(
backend="inductor",
*,
Expand Down
16 changes: 16 additions & 0 deletions torch/testing/_internal/common_quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,22 @@ def wrapper(*args, **kwargs):
fn(*args, **kwargs)
return wrapper

def skipIfNoInductorSupport(fn):
reason = "inductor doesn't support."
if isinstance(fn, type):
if not torchdynamo.is_inductor_supported():
fn.__unittest_skip__ = True
fn.__unittest_skip_why__ = reason
return fn

@functools.wraps(fn)
def wrapper(*args, **kwargs):
if not torchdynamo.is_inductor_supported():
raise unittest.SkipTest(reason)
else:
fn(*args, **kwargs)
return wrapper

try:
import torchvision # noqa: F401
HAS_TORCHVISION = True
Expand Down

0 comments on commit d37ef49

Please sign in to comment.