Skip to content

Commit ba48cf6

Browse files
XuehaiPanpytorchmergebot
authored andcommitted
[BE][Easy][6/19] enforce style for empty lines in import segments in test/ (#129757)
See pytorch/pytorch#129751 (comment). Most changes are auto-generated by linter. You can review these PRs via: ```bash git diff --ignore-all-space --ignore-blank-lines HEAD~1 ``` Pull Request resolved: pytorch/pytorch#129757 Approved by: https://github.com/ezyang
1 parent e51e971 commit ba48cf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+91
-74
lines changed

test/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from _pytest.reports import TestReport
1818
from _pytest.stash import StashKey
1919
from _pytest.terminal import _get_raw_skip_reason
20+
2021
from pytest_shard_custom import pytest_addoptions as shard_addoptions, PytestShardPlugin
2122

23+
2224
if TYPE_CHECKING:
2325
from _pytest._code.code import ReprFileLocation
2426

test/load_torchscript_model.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import torch
44

5+
56
if __name__ == "__main__":
67
script_mod = torch.jit.load(sys.argv[1])
78
mod = torch.load(sys.argv[1] + ".orig")

test/run_test.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
TEST_WITH_SLOW_GRADCHECK,
3939
)
4040

41-
REPO_ROOT = Path(__file__).resolve().parent.parent
4241

4342
# using tools/ to optimize test run.
43+
REPO_ROOT = Path(__file__).resolve().parent.parent
4444
sys.path.insert(0, str(REPO_ROOT))
45+
4546
from tools.stats.import_test_stats import (
4647
ADDITIONAL_CI_FILES_FOLDER,
4748
TEST_CLASS_TIMES_FILE,
@@ -71,10 +72,11 @@
7172
)
7273

7374

74-
HAVE_TEST_SELECTION_TOOLS = True
7575
# Make sure to remove REPO_ROOT after import is done
7676
sys.path.remove(str(REPO_ROOT))
7777

78+
79+
HAVE_TEST_SELECTION_TOOLS = True
7880
TEST_CONFIG = os.getenv("TEST_CONFIG", "")
7981
BUILD_ENVIRONMENT = os.getenv("BUILD_ENVIRONMENT", "")
8082
RERUN_DISABLED_TESTS = os.getenv("PYTORCH_TEST_RERUN_DISABLED_TESTS", "0") == "1"

test/simulate_nccl_errors.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66
import torch.distributed as c10d
77

8+
89
logging.basicConfig(
910
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
1011
)

test/test_ao_sparsity.py

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

33
# Kernels
4-
from ao.sparsity.test_kernels import ( # noqa: F401 # noqa: F401
4+
from ao.sparsity.test_kernels import ( # noqa: F401
55
TestQuantizedSparseKernels,
66
TestQuantizedSparseLayers,
77
)
@@ -10,30 +10,28 @@
1010
from ao.sparsity.test_parametrization import TestFakeSparsity # noqa: F401
1111

1212
# Scheduler
13-
from ao.sparsity.test_scheduler import ( # noqa: F401 # noqa: F401
14-
TestCubicScheduler,
15-
TestScheduler,
16-
)
13+
from ao.sparsity.test_scheduler import TestCubicScheduler, TestScheduler # noqa: F401
1714

1815
# Sparsifier
19-
from ao.sparsity.test_sparsifier import ( # noqa: F401 # noqa: F401 # noqa: F401
16+
from ao.sparsity.test_sparsifier import ( # noqa: F401
2017
TestBaseSparsifier,
2118
TestNearlyDiagonalSparsifier,
2219
TestWeightNormSparsifier,
2320
)
2421

2522
# Structured Pruning
26-
from ao.sparsity.test_structured_sparsifier import ( # noqa: F401 # noqa: F401 # noqa: F401
23+
from ao.sparsity.test_structured_sparsifier import ( # noqa: F401
2724
TestBaseStructuredSparsifier,
2825
TestFPGMPruner,
2926
TestSaliencyPruner,
3027
)
3128

3229
from torch.testing._internal.common_utils import IS_ARM64, run_tests
3330

31+
3432
# Composability
3533
if not IS_ARM64:
36-
from ao.sparsity.test_composability import ( # noqa: F401 # noqa: F401
34+
from ao.sparsity.test_composability import ( # noqa: F401
3735
TestComposability,
3836
TestFxComposability,
3937
)
@@ -47,7 +45,7 @@
4745
from ao.sparsity.test_data_scheduler import TestBaseDataScheduler # noqa: F401
4846

4947
# Data Sparsifier
50-
from ao.sparsity.test_data_sparsifier import ( # noqa: F401 # noqa: F401 # noqa: F401
48+
from ao.sparsity.test_data_sparsifier import ( # noqa: F401
5149
TestBaseDataSparsifier,
5250
TestNormDataSparsifiers,
5351
TestQuantizationUtils,
@@ -56,5 +54,6 @@
5654
# Utilities
5755
from ao.sparsity.test_sparsity_utils import TestSparsityUtilFunctions # noqa: F401
5856

57+
5958
if __name__ == "__main__":
6059
run_tests()

test/test_autograd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import torch
3030
import torch.autograd._functions
3131
import torch.autograd.forward_ad as fwAD
32-
3332
from torch import inf, nan, nn
3433
from torch.autograd import (
3534
_calculate_shape,
@@ -14064,6 +14063,7 @@ def log_grad_order(grad: torch.Tensor, name: str, order):
1406414063
from autograd.test_functional import TestAutogradFunctional # noqa: F401
1406514064
from autograd.test_logging import TestAutogradLogging # noqa: F401
1406614065

14066+
1406714067
# e.g., TestAutogradDeviceTypeCPU and TestAutogradDeviceTypeCUDA
1406814068
instantiate_device_type_tests(TestAutogradDeviceType, globals(), except_for=None)
1406914069

test/test_binary_ufuncs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import numpy as np
1313

1414
import torch
15-
1615
import torch.autograd.forward_ad as fwAD
1716
from torch import inf, nan
1817
from torch.testing import make_tensor
@@ -68,6 +67,7 @@
6867
xfailIfTorchDynamo,
6968
)
7069

70+
7171
if TEST_SCIPY:
7272
import scipy.integrate
7373
import scipy.special

test/test_bundled_images.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import torch.utils.bundled_inputs
1111
from torch.testing._internal.common_utils import TestCase
1212

13+
1314
torch.ops.load_library("//caffe2/torch/fb/operators:decode_bundled_image")
1415

1516

test/test_compile_benchmark_util.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import torch._dynamo as torchdynamo
77
from torch.testing._internal.common_utils import run_tests, TEST_CUDA, TestCase
88

9+
910
try:
1011
import tabulate # noqa: F401 # type: ignore[import]
1112

test/test_complex.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from torch.testing._internal.common_dtype import complex_types
1111
from torch.testing._internal.common_utils import run_tests, set_default_dtype, TestCase
1212

13+
1314
devices = (torch.device("cpu"), torch.device("cuda:0"))
1415

1516

test/test_cpp_api_parity.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import torch.testing._internal.common_nn as common_nn
1717
import torch.testing._internal.common_utils as common
1818

19+
1920
# NOTE: turn this on if you want to print source code of all C++ tests (e.g. for debugging purpose)
2021
PRINT_CPP_SOURCE = False
2122

test/test_cpp_extensions_aot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
import torch
1010
import torch.backends.cudnn
11-
1211
import torch.testing._internal.common_utils as common
1312
import torch.utils.cpp_extension
1413
from torch.testing._internal.common_cuda import TEST_CUDA
1514
from torch.testing._internal.common_utils import IS_WINDOWS, skipIfTorchDynamo
1615

16+
1717
try:
1818
import pytest
1919

test/test_cpp_extensions_jit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import torch
1414
import torch.backends.cudnn
1515
import torch.multiprocessing as mp
16-
1716
import torch.testing._internal.common_utils as common
1817
import torch.utils.cpp_extension
1918
from torch.testing._internal.common_cuda import TEST_CUDA, TEST_CUDNN
@@ -27,6 +26,7 @@
2726
ROCM_HOME,
2827
)
2928

29+
3030
# define TEST_ROCM before changing TEST_CUDA
3131
TEST_ROCM = TEST_CUDA and torch.version.hip is not None and ROCM_HOME is not None
3232
TEST_CUDA = TEST_CUDA and CUDA_HOME is not None

test/test_cpp_extensions_open_device_registration.py

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from unittest.mock import patch
1111

1212
import torch
13-
1413
import torch.testing._internal.common_utils as common
1514
import torch.utils.cpp_extension
1615
from torch.testing._internal.common_utils import (

test/test_cuda.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import torch
2121
import torch.cuda
22-
2322
from torch import inf, nan
2423
from torch.cuda._memory_viz import (
2524
_profile_to_snapshot,
@@ -72,6 +71,7 @@
7271
from torch.utils.checkpoint import checkpoint_sequential
7372
from torch.utils.viz._cycles import observe_tensor_cycles
7473

74+
7575
# load_tests from common_utils is used to automatically filter tests for
7676
# sharding on sandcastle. This line silences flake warnings
7777
load_tests = load_tests

test/test_cuda_expandable_segments.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
)
1212

1313
import torch
14-
1514
from torch.testing._internal.common_cuda import IS_JETSON, IS_WINDOWS
1615
from torch.testing._internal.common_utils import run_tests, TEST_WITH_ROCM
1716

18-
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent
1917

18+
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent
2019
sys.path.insert(0, str(REPO_ROOT))
20+
2121
from tools.stats.import_test_stats import get_disabled_tests
2222

23+
2324
# Make sure to remove REPO_ROOT after import is done
2425
sys.path.remove(str(REPO_ROOT))
2526

test/test_cuda_multigpu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import tempfile
1111
import threading
1212
import unittest
13-
1413
from itertools import chain, repeat
1514
from typing import NamedTuple
1615

@@ -37,6 +36,7 @@
3736
TestCase,
3837
)
3938

39+
4040
TEST_CUDAMALLOCASYNC = TEST_CUDA and (
4141
torch.cuda.get_allocator_backend() == "cudaMallocAsync"
4242
)

test/test_cuda_nvml_based_avail.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import torch
1010

11+
1112
# NOTE: Each of the tests in this module need to be run in a brand new process to ensure CUDA is uninitialized
1213
# prior to test initiation.
1314
with patch.dict(os.environ, {"PYTORCH_NVML_BASED_CUDA_CHECK": "1"}):

test/test_cuda_primary_ctx.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
TestCase,
1313
)
1414

15+
1516
# NOTE: this needs to be run in a brand new process
1617

1718
if not TEST_CUDA:

test/test_cuda_trace.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import torch.cuda._gpu_trace as gpu_trace
99
from torch.testing._internal.common_utils import NoTest, run_tests, TEST_CUDA, TestCase
1010

11+
1112
# NOTE: Each test needs to be run in a brand new process, to reset the registered hooks
1213
# and make sure the CUDA streams are initialized for each test that uses them.
1314

test/test_custom_ops.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
11
# Owner(s): ["module: custom-operators"]
22

3-
from torch.testing._internal.common_utils import * # noqa: F403
4-
from torch.testing._internal.common_device_type import * # noqa: F403
53
import collections
6-
74
import itertools
85
import os
96
import re
7+
import subprocess
8+
import sys
109
import typing
10+
import unittest
11+
from typing import * # noqa: F403
1112

12-
import torch._custom_ops as custom_ops
13+
import numpy as np
1314

15+
import torch._custom_ops as custom_ops
1416
import torch.testing._internal.optests as optests
17+
import torch.utils._pytree as pytree
1518
import torch.utils.cpp_extension
16-
1719
from functorch import make_fx
1820
from torch import Tensor
19-
from torch._custom_op.impl import custom_op, CustomOp, infer_schema
21+
from torch._custom_op.impl import CustomOp, infer_schema
2022
from torch._library.infer_schema import tuple_to_list
2123
from torch._utils_internal import get_file_path_2
2224
from torch.testing._internal import custom_op_db
2325
from torch.testing._internal.common_cuda import TEST_CUDA
26+
from torch.testing._internal.common_device_type import (
27+
instantiate_device_type_tests,
28+
OpDTypes,
29+
ops,
30+
)
31+
from torch.testing._internal.common_utils import (
32+
instantiate_parametrized_tests,
33+
IS_WINDOWS,
34+
parametrize,
35+
run_tests,
36+
skipIfTorchDynamo,
37+
subtest,
38+
TestCase,
39+
)
2440
from torch.testing._internal.custom_op_db import numpy_nonzero
25-
from typing import * # noqa: F403
26-
import numpy as np
41+
42+
43+
# Shadowed by `torch.testing._internal.common_utils.custom_op`
44+
from torch._custom_op.impl import custom_op # usort: skip
2745

2846

2947
def requires_compile(fun):

test/test_decomp.py

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

33
import functools
4-
54
import itertools
65
import re
76
import unittest
@@ -43,9 +42,9 @@
4342
)
4443
from torch.utils import _pytree as pytree
4544
from torch.utils._python_dispatch import TorchDispatchMode
46-
4745
from torch.utils._pytree import tree_flatten, tree_map, tree_unflatten
4846

47+
4948
aten = torch.ops.aten
5049

5150

test/test_deploy.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import types
55

66
from torch.testing._internal.common_utils import run_tests, TestCase
7-
87
from torch.utils._freeze import Freezer, PATH_MARKER
98

109

test/test_dispatch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import itertools
44
import os
55
import re
6-
76
from collections import namedtuple
87

98
import torch._C as C
109
import torch.utils.cpp_extension
1110
from torch._python_dispatcher import PythonDispatcher
1211
from torch.testing._internal.common_utils import run_tests, TestCase
1312

13+
1414
# TODO: Expand the dispatcher API to be a generic API for interfacing with
1515
# the dispatcher from Python!
1616
#

0 commit comments

Comments
 (0)