Skip to content

Commit 88e1c5c

Browse files
huydhnpytorchmergebot
authored andcommitted
Apply ufmt linter to all py files under test/onnx (pytorch#81335)
Same as pytorch#81285 but for `test/onnx`. The merge conflicts in `linrunner.toml` is expected. I will resolve them depending on the merge order of the PR Pull Request resolved: pytorch#81335 Approved by: https://github.com/BowenBao, https://github.com/kit1980
1 parent 9d3c35d commit 88e1c5c

17 files changed

+61
-62
lines changed

.lintrunner.toml

+1
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ code = 'UFMT'
670670
# After that, we can use **/*.py to apply the formatter to all entries
671671
# currently enforced by BLACK linter
672672
include_patterns = [
673+
'test/onnx/**/*.py',
673674
'tools/**/*.py',
674675
]
675676
command = [

test/onnx/debug_embed_params.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import sys
22

3+
import caffe2.python.onnx.backend as c2
4+
35
import onnx
46
import pytorch_test_common
5-
6-
import caffe2.python.onnx.backend as c2
77
import torch
88
import torch.jit
99
from torch.autograd import Variable

test/onnx/export_onnx_tests_generator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import onnx
77
import onnx_test_common
8-
from onnx import numpy_helper
9-
from test_nn import new_module_tests
108

119
import torch
10+
from onnx import numpy_helper
11+
from test_nn import new_module_tests
1212
from torch.autograd import Variable
1313
from torch.testing._internal.common_nn import module_tests
1414

test/onnx/test_caffe2_common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import glob
44
import os
55

6+
import caffe2.python.onnx.backend as c2
7+
68
import numpy as np
79
import onnx.backend.test
810
from onnx import numpy_helper
911

10-
import caffe2.python.onnx.backend as c2
11-
1212

1313
def load_tensor_as_numpy_array(f):
1414
tensor = onnx.TensorProto()

test/onnx/test_custom_ops.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Owner(s): ["module: onnx"]
22

3+
import caffe2.python.onnx.backend as c2
34
import numpy as np
45
import onnx
56
import onnx_test_common
6-
from test_pytorch_onnx_caffe2 import do_export
7-
8-
import caffe2.python.onnx.backend as c2
97
import torch
108
import torch.utils.cpp_extension
9+
from test_pytorch_onnx_caffe2 import do_export
1110
from torch.onnx import symbolic_helper
1211
from torch.testing._internal import common_utils
1312

test/onnx/test_models.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import unittest
44

5+
import caffe2.python.onnx.backend as backend
6+
import torch
7+
58
from model_defs.dcgan import _netD, _netG, bsz, imgsz, nz, weights_init
69
from model_defs.emb_seq import EmbeddingNetwork1, EmbeddingNetwork2
710
from model_defs.mnist import MNIST
@@ -10,6 +13,11 @@
1013
from model_defs.srresnet import SRResNet
1114
from model_defs.super_resolution import SuperResolutionNet
1215
from pytorch_test_common import skipIfUnsupportedMinOpsetVersion, skipScriptTest
16+
from torch import quantization
17+
from torch.autograd import Variable
18+
from torch.onnx import OperatorExportTypes
19+
from torch.testing._internal import common_utils
20+
from torch.testing._internal.common_utils import skipIfNoLapack
1321
from torchvision.models import shufflenet_v2_x1_0
1422
from torchvision.models.alexnet import alexnet
1523
from torchvision.models.densenet import densenet121
@@ -23,14 +31,6 @@
2331
from torchvision.models.video import mc3_18, r2plus1d_18, r3d_18
2432
from verify import verify
2533

26-
import caffe2.python.onnx.backend as backend
27-
import torch
28-
from torch import quantization
29-
from torch.autograd import Variable
30-
from torch.onnx import OperatorExportTypes
31-
from torch.testing._internal import common_utils
32-
from torch.testing._internal.common_utils import skipIfNoLapack
33-
3434
if torch.cuda.is_available():
3535

3636
def toC(x):

test/onnx/test_models_onnxruntime.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import onnx_test_common
99
import parameterized
1010
import PIL
11+
12+
import torch
1113
import torchvision
1214
from pytorch_test_common import skipIfUnsupportedMinOpsetVersion, skipScriptTest
1315
from test_models import TestModels
16+
from torch import nn
17+
from torch.testing._internal import common_utils
1418
from torchvision import ops
1519
from torchvision.models.detection import (
1620
faster_rcnn,
@@ -22,10 +26,6 @@
2226
transform,
2327
)
2428

25-
import torch
26-
from torch import nn
27-
from torch.testing._internal import common_utils
28-
2929

3030
def exportTest(self, model, inputs, rtol=1e-2, atol=1e-7, opset_versions=None):
3131
opset_versions = opset_versions if opset_versions else [7, 8, 9, 10, 11, 12, 13, 14]

test/onnx/test_operators.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
import shutil
99
import tempfile
1010

11+
import torch
12+
import torch.nn as nn
13+
import torch.nn.functional as F
14+
import torch.onnx
15+
1116
from pytorch_test_common import (
1217
BATCH_SIZE,
18+
flatten,
1319
RNN_HIDDEN_SIZE,
1420
RNN_INPUT_SIZE,
1521
RNN_SEQUENCE_LENGTH,
16-
flatten,
1722
)
18-
19-
import torch
20-
import torch.nn as nn
21-
import torch.nn.functional as F
22-
import torch.onnx
2323
from torch.autograd import Function, Variable
24-
from torch.nn import Module, functional
24+
from torch.nn import functional, Module
2525
from torch.onnx.symbolic_helper import (
2626
_get_tensor_dim_size,
2727
_get_tensor_sizes,

test/onnx/test_pytorch_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import unittest
55

66
import numpy as np
7-
from pytorch_helper import PyTorchModule
87

98
import torch.nn.init as init
109
import torch.onnx
1110
from caffe2.python.core import workspace
1211
from caffe2.python.model_helper import ModelHelper
12+
from pytorch_helper import PyTorchModule
1313
from torch import nn
1414
from torch.testing._internal import common_utils
1515
from torch.testing._internal.common_utils import skipIfNoLapack

test/onnx/test_pytorch_onnx_caffe2.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66
import unittest
77
from typing import Tuple
88

9+
import caffe2.python.onnx.backend as c2
10+
911
import model_defs.dcgan as dcgan
1012
import model_defs.word_language_model as word_language_model
1113
import numpy as np
1214
import onnx
15+
import torch.onnx
16+
import torch.onnx.operators
17+
import torch.utils.model_zoo as model_zoo
1318
import verify
19+
from caffe2.python.operator_test.torch_integration_test import (
20+
create_bbox_transform_inputs,
21+
generate_rois_rotated,
22+
)
1423
from debug_embed_params import run_embed_params
1524
from model_defs.lstm_flattening_result import LstmFlatteningResult
1625
from model_defs.mnist import MNIST
@@ -29,6 +38,12 @@
2938
skipIfUnsupportedMinOpsetVersion,
3039
skipIfUnsupportedOpsetVersion,
3140
)
41+
from torch import nn
42+
from torch.autograd import function, Variable
43+
from torch.nn.utils import rnn as rnn_utils
44+
from torch.onnx import ExportTypes
45+
from torch.testing._internal import common_utils
46+
from torch.testing._internal.common_utils import skipIfNoLapack
3247

3348
# Import various models for testing
3449
from torchvision.models.alexnet import alexnet
@@ -37,21 +52,6 @@
3752
from torchvision.models.resnet import resnet50
3853
from torchvision.models.vgg import vgg16, vgg16_bn, vgg19, vgg19_bn
3954

40-
import caffe2.python.onnx.backend as c2
41-
import torch.onnx
42-
import torch.onnx.operators
43-
import torch.utils.model_zoo as model_zoo
44-
from caffe2.python.operator_test.torch_integration_test import (
45-
create_bbox_transform_inputs,
46-
generate_rois_rotated,
47-
)
48-
from torch import nn
49-
from torch.autograd import Variable, function
50-
from torch.nn.utils import rnn as rnn_utils
51-
from torch.onnx import ExportTypes
52-
from torch.testing._internal import common_utils
53-
from torch.testing._internal.common_utils import skipIfNoLapack
54-
5555
skip = unittest.skip
5656

5757

test/onnx/test_pytorch_onnx_caffe2_quantized.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import io
44

5+
import caffe2.python.onnx.backend as c2
6+
57
import numpy as np
68
import onnx
7-
8-
import caffe2.python.onnx.backend as c2
99
import torch.nn as nn
1010
import torch.nn.quantized as nnq
1111
import torch.onnx

test/onnx/test_pytorch_onnx_no_runtime.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
import io
77
import itertools
88
import unittest
9-
from typing import Dict, Optional, Type, Callable, Iterable, Tuple, Union, List
9+
from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, Union
1010

1111
import onnx
1212

1313
import torch
14+
import torch.nn.functional as F
1415
from torch import Tensor
15-
from torch.onnx import symbolic_helper, utils, symbolic_registry
16+
from torch.onnx import symbolic_helper, symbolic_registry, utils
1617
from torch.onnx._globals import GLOBALS
1718
from torch.testing._internal import common_utils
18-
import torch.nn.functional as F
1919

2020

2121
def export_to_onnx(

test/onnx/test_pytorch_onnx_onnxruntime.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import numpy as np
1313
import onnx_test_common
1414
import parameterized
15+
16+
import torch
1517
import torchvision
1618
from model_defs import (
1719
lstm_flattening_result,
@@ -31,8 +33,6 @@
3133
skipScriptTest,
3234
skipTraceTest,
3335
)
34-
35-
import torch
3636
from torch import Tensor
3737
from torch.nn.utils import rnn as rnn_utils
3838
from torch.onnx import verification

test/onnx/test_pytorch_onnx_onnxruntime_cuda.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import unittest
44

55
import onnxruntime # noqa: F401
6+
7+
import torch
68
from pytorch_test_common import (
79
skipIfNoBFloat16Cuda,
810
skipIfNoCuda,
911
skipIfUnsupportedMinOpsetVersion,
1012
skipScriptTest,
1113
)
1214
from test_pytorch_onnx_onnxruntime import TestONNXRuntime
13-
14-
import torch
1515
from torch.cuda.amp import autocast
1616
from torch.onnx._globals import GLOBALS
1717
from torch.testing._internal import common_utils

test/onnx/test_pytorch_onnx_shape_inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Owner(s): ["module: onnx"]
22

33
import numpy as np
4-
from pytorch_test_common import skipIfUnsupportedMinOpsetVersion
54

65
import torch
6+
from pytorch_test_common import skipIfUnsupportedMinOpsetVersion
77
from torch.onnx import _constants, symbolic_helper
88
from torch.testing._internal import common_utils
99

test/onnx/test_utility_funs.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
import io
55

66
import onnx
7+
8+
import torch
9+
import torch.onnx
10+
import torch.utils.cpp_extension
711
import torchvision
812
from autograd_helper import CustomFunction as CustomFunction2
913
from pytorch_test_common import (
1014
skipIfNoCuda,
1115
skipIfUnsupportedMaxOpsetVersion,
1216
skipIfUnsupportedMinOpsetVersion,
1317
)
14-
from verify import verify
15-
16-
import torch
17-
import torch.onnx
18-
import torch.utils.cpp_extension
1918
from torch.onnx import (
2019
OperatorExportTypes,
21-
TrainingMode,
2220
register_custom_op_symbolic,
21+
TrainingMode,
2322
unregister_custom_op_symbolic,
2423
utils,
2524
)
@@ -31,6 +30,7 @@
3130
parse_args,
3231
)
3332
from torch.testing._internal import common_utils
33+
from verify import verify
3434

3535

3636
class _BaseTestCase(common_utils.TestCase):

test/onnx/test_verify.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Owner(s): ["module: onnx"]
22

3-
from verify import verify
4-
53
import caffe2.python.onnx.backend as backend
64
import torch
75
from torch.autograd import Function
86
from torch.nn import Module, Parameter
97
from torch.testing._internal import common_utils
8+
from verify import verify
109

1110

1211
class TestVerify(common_utils.TestCase):

0 commit comments

Comments
 (0)