7
7
import itertools
8
8
import os
9
9
import tempfile
10
+ import unittest
10
11
import warnings
11
12
12
13
from typing import Any , Callable , Generator , Optional , Sequence , Tuple , Union
34
35
_InputArgsType = Union [torch .Tensor , Tuple [Any , ...]]
35
36
_OutputsType = Sequence [_NumericType ]
36
37
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
+
37
48
38
49
@_beartype .beartype
39
50
def _run_ort (
@@ -179,6 +190,11 @@ def tearDown(self):
179
190
)
180
191
super ().tearDown ()
181
192
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
+ )
182
198
def test_simple_function (self ):
183
199
def func (x ):
184
200
# TODO(justinchuby): Replicate torch's type casting policy
@@ -191,6 +207,11 @@ def func(x):
191
207
192
208
_run_test_with_fx_to_onnx_exporter_and_onnx_runtime (self , func , (tensor_x ,))
193
209
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
+ )
194
215
def test_func_with_args_and_kwargs (self ):
195
216
# Non-tensor optional kwargs are always folded into constant and
196
217
# removed from input list in Dynamo-traced graph, so we can't
@@ -223,7 +244,11 @@ def func(x, b=torch.tensor(1.0)):
223
244
self , func , (tensor_x ,), b = torch .tensor (5.0 )
224
245
)
225
246
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
+ )
227
252
def test_mnist (self ):
228
253
class MNISTModel (nn .Module ):
229
254
def __init__ (self ):
@@ -249,6 +274,11 @@ def forward(self, tensor_x: torch.Tensor):
249
274
self , MNISTModel (), (tensor_x ,)
250
275
)
251
276
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
+ )
252
282
# test single op with no kwargs
253
283
def test_sigmoid (self ):
254
284
x = torch .randn (1 , 4 , 2 , 3 )
@@ -263,13 +293,15 @@ def forward(self, x):
263
293
264
294
_run_test_with_fx_to_onnx_exporter_and_onnx_runtime (self , SigmoidModel (), (x ,))
265
295
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."
271
302
)
272
- def test_shufflenet_v2_dynamic_axes (self ):
303
+ @skip_if_no_torchvision
304
+ def test_shufflenet_v2 (self ):
273
305
model = torchvision .models .shufflenet_v2_x0_5 (pretrained = False )
274
306
dummy_input = torch .randn (1 , 3 , 224 , 224 , requires_grad = True )
275
307
test_inputs = torch .randn (3 , 3 , 224 , 224 , requires_grad = True )
@@ -283,6 +315,11 @@ def test_shufflenet_v2_dynamic_axes(self):
283
315
atol = 1e-5 ,
284
316
)
285
317
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
+ )
286
323
def test_add (self ):
287
324
class DynamicAdd (torch .nn .Module ):
288
325
def forward (self , x , y ):
@@ -297,6 +334,11 @@ def forward(self, x, y):
297
334
self , DynamicAdd (), (x , y ), additional_test_inputs = [(another_x , another_y )]
298
335
)
299
336
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
+ )
300
342
def test_sigmoid_add (self ):
301
343
class DynamicAdd (torch .nn .Module ):
302
344
def __init__ (self , * args , ** kwargs ) -> None :
@@ -318,7 +360,11 @@ def forward(self, x, y):
318
360
self , DynamicAdd (), (x , y ), additional_test_inputs = [(input_x , input_y )]
319
361
)
320
362
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
+ )
322
368
def test_matmul (self ):
323
369
class DynamicMatMul (torch .nn .Module ):
324
370
def forward (self , x , y ):
@@ -333,9 +379,8 @@ def forward(self, x, y):
333
379
self , DynamicMatMul (), (x , y ), additional_test_inputs = [(input_x , input_y )]
334
380
)
335
381
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"
339
384
)
340
385
def test_scalar_tensor (self ):
341
386
class test (torch .nn .Module ):
@@ -353,12 +398,6 @@ def forward(self, x):
353
398
additional_test_inputs = [(y ,)],
354
399
)
355
400
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
- )
362
401
def test_transpose_infer_shape (self ):
363
402
class TransposeModule (torch .nn .Module ):
364
403
def __init__ (self ):
@@ -378,7 +417,7 @@ def forward(self, x):
378
417
additional_test_inputs = [(y ,)],
379
418
)
380
419
381
- @pytorch_test_common . skip_dynamic_fx_test ("torch._dynamo.exc.TorchRuntimeError" )
420
+ @unittest . skip ("torch._dynamo.exc.TorchRuntimeError" )
382
421
def test_squeeze_runtime_dim (self ):
383
422
class Squeeze (torch .nn .Module ):
384
423
def forward (self , d1 , d2 ):
@@ -417,7 +456,13 @@ def forward(self, x):
417
456
additional_test_inputs = [(y ,)],
418
457
)
419
458
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
+ )
421
466
def test_mutation (self ):
422
467
class MutationModel (torch .nn .Module ):
423
468
def forward (self , x ):
@@ -428,9 +473,8 @@ def forward(self, x):
428
473
self , MutationModel (), (torch .randn (12 ),), input_mutation = True
429
474
)
430
475
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"
434
478
)
435
479
def test_arange (self ):
436
480
class ArangeModel (torch .nn .Module ):
@@ -450,7 +494,7 @@ def forward(self, input):
450
494
additional_test_inputs = [(y ,)],
451
495
)
452
496
453
- @pytorch_test_common . skip_dynamic_fx_test (
497
+ @unittest . skip (
454
498
"fx.graph: torch._subclasses.fake_tensor.DataDependentOutputException: "
455
499
"aten._local_scalar_dense.default"
456
500
)
@@ -469,10 +513,7 @@ def forward(self, x):
469
513
additional_test_inputs = [(x2 ,)],
470
514
)
471
515
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" )
476
517
def test_expand_as_fill_tensor (self ):
477
518
class Model (torch .nn .Module ):
478
519
def forward (self , x ):
@@ -488,6 +529,11 @@ def forward(self, x):
488
529
additional_test_inputs = [(x2 ,)],
489
530
)
490
531
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
+ )
491
537
def test_expand_as_fill_seperate_tensor (self ):
492
538
class Model (torch .nn .Module ):
493
539
def forward (self , x ):
@@ -503,6 +549,11 @@ def forward(self, x):
503
549
additional_test_inputs = [(x2 ,)],
504
550
)
505
551
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
+ )
506
557
def test_view_dynamic_zero_dim (self ):
507
558
class ViewModel (torch .nn .Module ):
508
559
def forward (self , input ):
@@ -518,6 +569,11 @@ def forward(self, input):
518
569
additional_test_inputs = [(another_x ,)],
519
570
)
520
571
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
+ )
521
577
def test_flatten_dynamic_axes (self ):
522
578
class MyModule (torch .nn .Module ):
523
579
def forward (self , x ):
@@ -531,7 +587,11 @@ def forward(self, x):
531
587
self , model , (x ,), additional_test_inputs = [(y ,)]
532
588
)
533
589
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
+ )
535
595
def test_gpt2_tiny (self ):
536
596
model_name = "sshleifer/tiny-gpt2"
537
597
# Download pytorch model
0 commit comments