Skip to content

Commit ad373ef

Browse files
titaiwangmspytorchmergebot
authored andcommitted
[ONNX] Skip flaky dynamic tests before ORT==1.15 in fx exporter (pytorch#98856)
Disable all flaky dynamic tests From pytorch#98626 (comment) Rerun all test cases and update skip reasons. The cases failing on both static and dynamic shapes are unittest.skipped. If it only fails on dynamic, it's skipped by skip_dynamic_test. There are a few skipped with skip_ort_min_version, since ORT is not supporting dynamic fx exporter until next version. Pull Request resolved: pytorch#98856 Approved by: https://github.com/BowenBao
1 parent 6cbe5c5 commit ad373ef

File tree

2 files changed

+95
-29
lines changed

2 files changed

+95
-29
lines changed

test/onnx/pytorch_test_common.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,19 @@ def wrapper(self, *args, **kwargs):
158158
return skip_dec
159159

160160

161-
def skip_min_ort_version(reason: str, version: str):
161+
# TODO(titaiwang): dynamic_only is specific to the situation that dynamic fx exporter
162+
# is not yet supported by ORT until 1.15.0. Remove dynamic_only once ORT 1.15.0 is released.
163+
def skip_min_ort_version(reason: str, version: str, dynamic_only: bool = False):
162164
def skip_dec(func):
163165
@functools.wraps(func)
164166
def wrapper(self, *args, **kwargs):
165167
if (
166168
packaging.version.parse(self.ort_version).release
167169
< packaging.version.parse(version).release
168170
):
171+
if dynamic_only and not self.dynamic_shapes:
172+
return func(self, *args, **kwargs)
173+
169174
raise unittest.SkipTest(
170175
f"ONNX Runtime version: {version} is older than required version {version}. "
171176
f"Reason: {reason}."
@@ -194,6 +199,7 @@ def wrapper(self, *args, **kwargs):
194199
raise unittest.SkipTest(
195200
f"Skip verify dynamic shapes test for FX. {reason}"
196201
)
202+
return func(self, *args, **kwargs)
197203

198204
return wrapper
199205

test/onnx/test_fx_to_onnx_with_onnxruntime.py

+88-28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import itertools
88
import os
99
import tempfile
10+
import unittest
1011
import warnings
1112

1213
from typing import Any, Callable, Generator, Optional, Sequence, Tuple, Union
@@ -34,6 +35,16 @@
3435
_InputArgsType = Union[torch.Tensor, Tuple[Any, ...]]
3536
_OutputsType = Sequence[_NumericType]
3637

38+
try:
39+
import torchvision
40+
41+
HAS_TORCHVISION = True
42+
except ImportError:
43+
HAS_TORCHVISION = False
44+
except RuntimeError:
45+
HAS_TORCHVISION = False
46+
skip_if_no_torchvision = unittest.skipIf(not HAS_TORCHVISION, "no torchvision")
47+
3748

3849
@_beartype.beartype
3950
def _run_ort(
@@ -179,6 +190,11 @@ def tearDown(self):
179190
)
180191
super().tearDown()
181192

193+
@pytorch_test_common.skip_min_ort_version(
194+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
195+
version="1.15",
196+
dynamic_only=True,
197+
)
182198
def test_simple_function(self):
183199
def func(x):
184200
# TODO(justinchuby): Replicate torch's type casting policy
@@ -191,6 +207,11 @@ def func(x):
191207

192208
_run_test_with_fx_to_onnx_exporter_and_onnx_runtime(self, func, (tensor_x,))
193209

210+
@pytorch_test_common.skip_min_ort_version(
211+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
212+
version="1.15",
213+
dynamic_only=True,
214+
)
194215
def test_func_with_args_and_kwargs(self):
195216
# Non-tensor optional kwargs are always folded into constant and
196217
# removed from input list in Dynamo-traced graph, so we can't
@@ -223,7 +244,11 @@ def func(x, b=torch.tensor(1.0)):
223244
self, func, (tensor_x,), b=torch.tensor(5.0)
224245
)
225246

226-
@pytorch_test_common.skip_min_ort_version(reason="SegFault", version="1.15")
247+
@pytorch_test_common.skip_min_ort_version(
248+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
249+
version="1.15",
250+
dynamic_only=True,
251+
)
227252
def test_mnist(self):
228253
class MNISTModel(nn.Module):
229254
def __init__(self):
@@ -249,6 +274,11 @@ def forward(self, tensor_x: torch.Tensor):
249274
self, MNISTModel(), (tensor_x,)
250275
)
251276

277+
@pytorch_test_common.skip_min_ort_version(
278+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
279+
version="1.15",
280+
dynamic_only=True,
281+
)
252282
# test single op with no kwargs
253283
def test_sigmoid(self):
254284
x = torch.randn(1, 4, 2, 3)
@@ -263,13 +293,15 @@ def forward(self, x):
263293

264294
_run_test_with_fx_to_onnx_exporter_and_onnx_runtime(self, SigmoidModel(), (x,))
265295

266-
@pytorch_test_common.skip_dynamic_fx_test(
267-
"_aten_convolution_onnx: _add_attribute_to_torchscript_node()"
268-
" parameter value=[None, None] violates type hint"
269-
"typing.Union[float, int, str, bytes, typing.Sequence[float],"
270-
" typing.Sequence[int], torch.Tensor], as [None, None]:"
296+
@unittest.skip(
297+
"RuntimeError: false INTERNAL ASSERT FAILED at "
298+
"'/home/titaiwang/pytorch/build/aten/src/ATen/RegisterFunctionalization_0.cpp':3725,"
299+
" please report a bug to PyTorch. mutating a non-functional tensor with a "
300+
"functional tensor is not allowed. Please ensure that all of your inputs are "
301+
"wrapped inside of a functionalize() call."
271302
)
272-
def test_shufflenet_v2_dynamic_axes(self):
303+
@skip_if_no_torchvision
304+
def test_shufflenet_v2(self):
273305
model = torchvision.models.shufflenet_v2_x0_5(pretrained=False)
274306
dummy_input = torch.randn(1, 3, 224, 224, requires_grad=True)
275307
test_inputs = torch.randn(3, 3, 224, 224, requires_grad=True)
@@ -283,6 +315,11 @@ def test_shufflenet_v2_dynamic_axes(self):
283315
atol=1e-5,
284316
)
285317

318+
@pytorch_test_common.skip_min_ort_version(
319+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
320+
version="1.15",
321+
dynamic_only=True,
322+
)
286323
def test_add(self):
287324
class DynamicAdd(torch.nn.Module):
288325
def forward(self, x, y):
@@ -297,6 +334,11 @@ def forward(self, x, y):
297334
self, DynamicAdd(), (x, y), additional_test_inputs=[(another_x, another_y)]
298335
)
299336

337+
@pytorch_test_common.skip_min_ort_version(
338+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
339+
version="1.15",
340+
dynamic_only=True,
341+
)
300342
def test_sigmoid_add(self):
301343
class DynamicAdd(torch.nn.Module):
302344
def __init__(self, *args, **kwargs) -> None:
@@ -318,7 +360,11 @@ def forward(self, x, y):
318360
self, DynamicAdd(), (x, y), additional_test_inputs=[(input_x, input_y)]
319361
)
320362

321-
@pytorch_test_common.skip_min_ort_version(reason="SegFault", version="1.15")
363+
@pytorch_test_common.skip_min_ort_version(
364+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
365+
version="1.15",
366+
dynamic_only=True,
367+
)
322368
def test_matmul(self):
323369
class DynamicMatMul(torch.nn.Module):
324370
def forward(self, x, y):
@@ -333,9 +379,8 @@ def forward(self, x, y):
333379
self, DynamicMatMul(), (x, y), additional_test_inputs=[(input_x, input_y)]
334380
)
335381

336-
@pytorch_test_common.skip_dynamic_fx_test(
337-
"fx.graph: doesn't handle scalar like normal tensor, so this is not yet "
338-
"supported! TypeError: forward() takes 1 positional argument but 2 were given"
382+
@unittest.skip(
383+
"RuntimeError: The two modules have different number of arguments. module: 1, reference_module: 0"
339384
)
340385
def test_scalar_tensor(self):
341386
class test(torch.nn.Module):
@@ -353,12 +398,6 @@ def forward(self, x):
353398
additional_test_inputs=[(y,)],
354399
)
355400

356-
@pytorch_test_common.skip_dynamic_fx_test(
357-
"_aten_convolution_onnx: _add_attribute_to_torchscript_node()"
358-
" parameter value=[None, None] violates type hint"
359-
"typing.Union[float, int, str, bytes, typing.Sequence[float],"
360-
" typing.Sequence[int], torch.Tensor], as [None, None]:"
361-
)
362401
def test_transpose_infer_shape(self):
363402
class TransposeModule(torch.nn.Module):
364403
def __init__(self):
@@ -378,7 +417,7 @@ def forward(self, x):
378417
additional_test_inputs=[(y,)],
379418
)
380419

381-
@pytorch_test_common.skip_dynamic_fx_test("torch._dynamo.exc.TorchRuntimeError")
420+
@unittest.skip("torch._dynamo.exc.TorchRuntimeError")
382421
def test_squeeze_runtime_dim(self):
383422
class Squeeze(torch.nn.Module):
384423
def forward(self, d1, d2):
@@ -417,7 +456,13 @@ def forward(self, x):
417456
additional_test_inputs=[(y,)],
418457
)
419458

420-
@pytorch_test_common.skip_min_ort_version(reason="SegFault", version="1.15")
459+
# TODO(titaiwang): This is also detected flaky in static shape:
460+
# https://github.com/pytorch/pytorch/issues/98622
461+
@pytorch_test_common.skip_min_ort_version(
462+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
463+
version="1.15",
464+
dynamic_only=False,
465+
)
421466
def test_mutation(self):
422467
class MutationModel(torch.nn.Module):
423468
def forward(self, x):
@@ -428,9 +473,8 @@ def forward(self, x):
428473
self, MutationModel(), (torch.randn(12),), input_mutation=True
429474
)
430475

431-
@pytorch_test_common.skip_dynamic_fx_test(
432-
"fx.graph: doesn't handle scalar like normal tensor, so this is not yet"
433-
"supported! TypeError: forward() takes 1 positional argument but 2 were given"
476+
@unittest.skip(
477+
"RuntimeError: The two modules have different number of arguments. module: 1, reference_module: 0"
434478
)
435479
def test_arange(self):
436480
class ArangeModel(torch.nn.Module):
@@ -450,7 +494,7 @@ def forward(self, input):
450494
additional_test_inputs=[(y,)],
451495
)
452496

453-
@pytorch_test_common.skip_dynamic_fx_test(
497+
@unittest.skip(
454498
"fx.graph: torch._subclasses.fake_tensor.DataDependentOutputException: "
455499
"aten._local_scalar_dense.default"
456500
)
@@ -469,10 +513,7 @@ def forward(self, x):
469513
additional_test_inputs=[(x2,)],
470514
)
471515

472-
@pytorch_test_common.skip_dynamic_fx_test(
473-
"ATenLib: INVALID_ARGUMENT : Failed to load model with error: "
474-
"ONNX Schema aten_copy: failed validating the check: !(it.GetName().empty())"
475-
)
516+
@unittest.skip("RuntimeError: Unknown call_function target: aten.copy.default")
476517
def test_expand_as_fill_tensor(self):
477518
class Model(torch.nn.Module):
478519
def forward(self, x):
@@ -488,6 +529,11 @@ def forward(self, x):
488529
additional_test_inputs=[(x2,)],
489530
)
490531

532+
@pytorch_test_common.skip_min_ort_version(
533+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
534+
version="1.15",
535+
dynamic_only=True,
536+
)
491537
def test_expand_as_fill_seperate_tensor(self):
492538
class Model(torch.nn.Module):
493539
def forward(self, x):
@@ -503,6 +549,11 @@ def forward(self, x):
503549
additional_test_inputs=[(x2,)],
504550
)
505551

552+
@pytorch_test_common.skip_min_ort_version(
553+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
554+
version="1.15",
555+
dynamic_only=True,
556+
)
506557
def test_view_dynamic_zero_dim(self):
507558
class ViewModel(torch.nn.Module):
508559
def forward(self, input):
@@ -518,6 +569,11 @@ def forward(self, input):
518569
additional_test_inputs=[(another_x,)],
519570
)
520571

572+
@pytorch_test_common.skip_min_ort_version(
573+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
574+
version="1.15",
575+
dynamic_only=True,
576+
)
521577
def test_flatten_dynamic_axes(self):
522578
class MyModule(torch.nn.Module):
523579
def forward(self, x):
@@ -531,7 +587,11 @@ def forward(self, x):
531587
self, model, (x,), additional_test_inputs=[(y,)]
532588
)
533589

534-
@pytorch_test_common.skip_min_ort_version(reason="SegFault", version="1.15")
590+
@pytorch_test_common.skip_min_ort_version(
591+
reason="ORT doesn't support dynamic fx exporter yet making SegFault flaky test",
592+
version="1.15",
593+
dynamic_only=True,
594+
)
535595
def test_gpt2_tiny(self):
536596
model_name = "sshleifer/tiny-gpt2"
537597
# Download pytorch model

0 commit comments

Comments
 (0)