[BE][Easy][5/19] enforce style for empty lines in import segments in tools/ and torchgen/ (#129756)

See https://github.com/pytorch/pytorch/pull/129751#issue-2380881501. 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: https://github.com/pytorch/pytorch/pull/129756
Approved by: https://github.com/ezyang
This commit is contained in:
Xuehai Pan
2024-07-16 11:38:57 +08:00
committed by PyTorch MergeBot
parent ba48cf6535
commit f6838d521a
31 changed files with 47 additions and 15 deletions

View File

@ -5,6 +5,7 @@ import argparse
import os import os
import sys import sys
sys.path.append( sys.path.append(
os.path.realpath( os.path.realpath(
os.path.join( os.path.join(
@ -15,6 +16,7 @@ sys.path.append(
from hipify import hipify_python # type: ignore[import] from hipify import hipify_python # type: ignore[import]
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Top-level script for HIPifying, filling in most common parameters" description="Top-level script for HIPifying, filling in most common parameters"
) )

View File

@ -24,7 +24,7 @@ from torchgen.api.types import (
OptionalCType, OptionalCType,
symIntArrayRefT, symIntArrayRefT,
SymIntT, SymIntT,
tensorT, # See Note [Nested Arg Types] tensorT,
) )
from torchgen.code_template import CodeTemplate from torchgen.code_template import CodeTemplate
from torchgen.context import with_native_function from torchgen.context import with_native_function

View File

@ -2,6 +2,7 @@ import argparse
import sys import sys
from os.path import abspath, dirname from os.path import abspath, dirname
# By appending pytorch_root to sys.path, this module can import other torch # By appending pytorch_root to sys.path, this module can import other torch
# modules even when run as a standalone script. i.e., it's okay either you # modules even when run as a standalone script. i.e., it's okay either you
# do `python build_libtorch.py` or `python -m tools.build_libtorch`. # do `python build_libtorch.py` or `python -m tools.build_libtorch`.
@ -11,6 +12,7 @@ sys.path.append(pytorch_root)
from tools.build_pytorch_libs import build_caffe2 from tools.build_pytorch_libs import build_caffe2
from tools.setup_helpers.cmake import CMake from tools.setup_helpers.cmake import CMake
if __name__ == "__main__": if __name__ == "__main__":
# Placeholder for future interface. For now just gives a nice -h. # Placeholder for future interface. For now just gives a nice -h.
parser = argparse.ArgumentParser(description="Build libtorch") parser = argparse.ArgumentParser(description="Build libtorch")

View File

@ -11,6 +11,7 @@ import urllib.error
import urllib.request import urllib.request
from pathlib import Path from pathlib import Path
# String representing the host platform (e.g. Linux, Darwin). # String representing the host platform (e.g. Linux, Darwin).
HOST_PLATFORM = platform.system() HOST_PLATFORM = platform.system()
HOST_PLATFORM_ARCH = platform.system() + "-" + platform.processor() HOST_PLATFORM_ARCH = platform.system() + "-" + platform.processor()

View File

@ -36,9 +36,7 @@ ISORT_WHITELIST = re.compile(
# functorch/** # functorch/**
"functorch/**", "functorch/**",
# tools/** # tools/**
"tools/**",
# torchgen/** # torchgen/**
"torchgen/**",
# test/** # test/**
# test/[a-c]*/** # test/[a-c]*/**
"test/[a-c]*/**", "test/[a-c]*/**",

View File

@ -3,9 +3,11 @@
import os.path import os.path
import sys import sys
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, root) sys.path.insert(0, root)
import torchgen.gen import torchgen.gen
torchgen.gen.main() torchgen.gen.main()

View File

@ -3,9 +3,11 @@
import os.path import os.path
import sys import sys
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, root) sys.path.insert(0, root)
import tools.jit.gen_unboxing import tools.jit.gen_unboxing
tools.jit.gen_unboxing.main(sys.argv[1:]) tools.jit.gen_unboxing.main(sys.argv[1:])

View File

@ -8,6 +8,7 @@ from typing import Any, cast
import yaml import yaml
try: try:
# use faster C loader if available # use faster C loader if available
from yaml import CSafeLoader as YamlLoader from yaml import CSafeLoader as YamlLoader
@ -30,6 +31,7 @@ def generate_code(
) -> None: ) -> None:
from tools.autograd.gen_annotated_fn_args import gen_annotated from tools.autograd.gen_annotated_fn_args import gen_annotated
from tools.autograd.gen_autograd import gen_autograd, gen_autograd_python from tools.autograd.gen_autograd import gen_autograd, gen_autograd_python
from torchgen.selective_build.selector import SelectiveBuilder from torchgen.selective_build.selector import SelectiveBuilder
# Build ATen based Variable classes # Build ATen based Variable classes

View File

@ -1,6 +1,7 @@
import sys import sys
from pathlib import Path from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))
from tools.stats.import_test_stats import get_test_class_times, get_test_times from tools.stats.import_test_stats import get_test_class_times, get_test_times

View File

@ -10,6 +10,7 @@ from pathlib import Path
from typing import Any, Callable, cast, Dict from typing import Any, Callable, cast, Dict
from urllib.request import urlopen from urllib.request import urlopen
REPO_ROOT = Path(__file__).resolve().parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent

View File

@ -4,7 +4,6 @@ import gzip
import io import io
import json import json
import os import os
import time import time
import zipfile import zipfile
from pathlib import Path from pathlib import Path

View File

@ -9,8 +9,10 @@ from pathlib import Path
from typing import Any from typing import Any
from unittest import mock from unittest import mock
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))
from tools.test.heuristics.test_interface import TestTD from tools.test.heuristics.test_interface import TestTD
from tools.testing.target_determination.determinator import TestPrioritizations from tools.testing.target_determination.determinator import TestPrioritizations
from tools.testing.target_determination.heuristics.filepath import ( from tools.testing.target_determination.heuristics.filepath import (
@ -25,6 +27,7 @@ from tools.testing.target_determination.heuristics.previously_failed_in_pr impor
) )
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
sys.path.remove(str(REPO_ROOT)) sys.path.remove(str(REPO_ROOT))
HEURISTIC_CLASS = "tools.testing.target_determination.heuristics.historical_class_failure_correlation." HEURISTIC_CLASS = "tools.testing.target_determination.heuristics.historical_class_failure_correlation."

View File

@ -5,11 +5,14 @@ import unittest
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))
import tools.testing.target_determination.heuristics.interface as interface import tools.testing.target_determination.heuristics.interface as interface
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
sys.path.remove(str(REPO_ROOT)) sys.path.remove(str(REPO_ROOT))

View File

@ -8,9 +8,11 @@ from typing import Any
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))
import tools.testing.target_determination.heuristics.utils as utils import tools.testing.target_determination.heuristics.utils as utils
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
sys.path.remove(str(REPO_ROOT)) sys.path.remove(str(REPO_ROOT))

View File

@ -9,9 +9,9 @@ import unittest
import expecttest import expecttest
from torchgen.gen import _GLOBAL_PARSE_NATIVE_YAML_CACHE # noqa: F401 from torchgen.gen import _GLOBAL_PARSE_NATIVE_YAML_CACHE # noqa: F401
from torchgen.gen_backend_stubs import run from torchgen.gen_backend_stubs import run
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
gen_backend_stubs_path = os.path.join(path, "../torchgen/gen_backend_stubs.py") gen_backend_stubs_path = os.path.join(path, "../torchgen/gen_backend_stubs.py")

View File

@ -2,6 +2,7 @@ import sys
import unittest import unittest
from pathlib import Path from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent
try: try:
# using tools/ to optimize test run. # using tools/ to optimize test run.

View File

@ -7,6 +7,7 @@ import unittest
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent
try: try:
# using tools/ to optimize test run. # using tools/ to optimize test run.

View File

@ -8,12 +8,14 @@ from pathlib import Path
from typing import Any from typing import Any
from unittest import mock from unittest import mock
REPO_ROOT = Path(__file__).resolve().parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.stats.upload_metrics import add_global_metric, emit_metric
from tools.stats.upload_metrics import add_global_metric, emit_metric
from tools.stats.upload_stats_lib import BATCH_SIZE, upload_to_rockset from tools.stats.upload_stats_lib import BATCH_SIZE, upload_to_rockset
sys.path.remove(str(REPO_ROOT)) sys.path.remove(str(REPO_ROOT))
# default values # default values

View File

@ -5,6 +5,7 @@ import os
import sys import sys
from pathlib import Path from pathlib import Path
CPP_TEST_PREFIX = "cpp" CPP_TEST_PREFIX = "cpp"
CPP_TEST_PATH = "build/bin" CPP_TEST_PATH = "build/bin"
CPP_TESTS_DIR = os.path.abspath(os.getenv("CPP_TESTS_DIR", default=CPP_TEST_PATH)) CPP_TESTS_DIR = os.path.abspath(os.getenv("CPP_TESTS_DIR", default=CPP_TEST_PATH))

View File

@ -18,7 +18,6 @@ from tools.stats.import_test_stats import (
get_test_times, get_test_times,
) )
from tools.stats.upload_metrics import emit_metric from tools.stats.upload_metrics import emit_metric
from tools.testing.discover_tests import TESTS from tools.testing.discover_tests import TESTS
from tools.testing.target_determination.determinator import ( from tools.testing.target_determination.determinator import (
AggregatedHeuristics, AggregatedHeuristics,
@ -26,6 +25,7 @@ from tools.testing.target_determination.determinator import (
TestPrioritizations, TestPrioritizations,
) )
sys.path.remove(str(REPO_ROOT)) sys.path.remove(str(REPO_ROOT))

View File

@ -7,6 +7,7 @@ import warnings
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
REPO_ROOT = Path(__file__).resolve().parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent
# These tests are slow enough that it's worth calculating whether the patch # These tests are slow enough that it's worth calculating whether the patch

View File

@ -5,6 +5,7 @@ import os
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent

View File

@ -10,13 +10,13 @@ from tools.testing.target_determination.heuristics.interface import (
HeuristicInterface, HeuristicInterface,
TestPrioritizations, TestPrioritizations,
) )
from tools.testing.target_determination.heuristics.utils import ( from tools.testing.target_determination.heuristics.utils import (
normalize_ratings, normalize_ratings,
query_changed_files, query_changed_files,
) )
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
REPO_ROOT = Path(__file__).parent.parent.parent.parent REPO_ROOT = Path(__file__).parent.parent.parent.parent
keyword_synonyms: dict[str, list[str]] = { keyword_synonyms: dict[str, list[str]] = {

View File

@ -10,7 +10,6 @@ from tools.stats.import_test_stats import (
TD_HEURISTIC_PREVIOUSLY_FAILED, TD_HEURISTIC_PREVIOUSLY_FAILED,
TD_HEURISTIC_PREVIOUSLY_FAILED_ADDITIONAL, TD_HEURISTIC_PREVIOUSLY_FAILED_ADDITIONAL,
) )
from tools.testing.target_determination.heuristics.interface import ( from tools.testing.target_determination.heuristics.interface import (
HeuristicInterface, HeuristicInterface,
TestPrioritizations, TestPrioritizations,
@ -20,6 +19,7 @@ from tools.testing.target_determination.heuristics.utils import (
) )
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent.parent

View File

@ -9,6 +9,7 @@ from typing import Callable, Sequence
from tools.stats.import_test_stats import get_disabled_tests, get_slow_tests from tools.stats.import_test_stats import get_disabled_tests, get_slow_tests
from tools.testing.test_run import ShardedTest, TestRun from tools.testing.test_run import ShardedTest, TestRun
REPO_ROOT = Path(__file__).resolve().parent.parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent.parent
IS_MEM_LEAK_CHECK = os.getenv("PYTORCH_TEST_CUDA_MEM_LEAK_CHECK", "0") == "1" IS_MEM_LEAK_CHECK = os.getenv("PYTORCH_TEST_CUDA_MEM_LEAK_CHECK", "0") == "1"

View File

@ -2,6 +2,7 @@
from pathlib import Path from pathlib import Path
try: try:
# VS Code settings allow comments and trailing commas, which are not valid JSON. # VS Code settings allow comments and trailing commas, which are not valid JSON.
import json5 as json # type: ignore[import] import json5 as json # type: ignore[import]

View File

@ -1,3 +1,5 @@
from torchgen.api.types.types import * from torchgen.api.types.types import *
from torchgen.api.types.types_base import * from torchgen.api.types.types_base import *
from torchgen.api.types.signatures import * # usort:skip
from torchgen.api.types.signatures import * # usort: skip

View File

@ -1,18 +1,19 @@
import argparse import argparse
import random import random
import time import time
from typing import Any, Tuple from typing import Any, Tuple
from tqdm import tqdm # type: ignore[import-untyped] from tqdm import tqdm # type: ignore[import-untyped]
import torch import torch
torch.set_default_device("cuda") torch.set_default_device("cuda")
from torch._inductor.fx_passes.pad_mm import get_alignment_size_dtype from torch._inductor.fx_passes.pad_mm import get_alignment_size_dtype
from torch._inductor.utils import fresh_inductor_cache from torch._inductor.utils import fresh_inductor_cache
# A100: 81920MiB # A100: 81920MiB
# without a threshold we sometimes run out of memory # without a threshold we sometimes run out of memory
threshold_memory = 85899345920 / 4 threshold_memory = 85899345920 / 4

View File

@ -5,15 +5,14 @@ import sys
import warnings import warnings
import numpy as np import numpy as np
import pandas as pd # type: ignore[import-untyped] import pandas as pd # type: ignore[import-untyped]
from scipy.stats import gmean # type: ignore[import-untyped] from scipy.stats import gmean # type: ignore[import-untyped]
from sklearn.model_selection import train_test_split # type: ignore[import-untyped] from sklearn.model_selection import train_test_split # type: ignore[import-untyped]
from sklearn.tree import DecisionTreeRegressor # type: ignore[import-untyped] from sklearn.tree import DecisionTreeRegressor # type: ignore[import-untyped]
from torch._inductor.autoheuristic.autoheuristic import deserialize_data from torch._inductor.autoheuristic.autoheuristic import deserialize_data
# TODO (AlnisM): Fix these warnings # TODO (AlnisM): Fix these warnings
warnings.filterwarnings( warnings.filterwarnings(
"ignore", "ignore",

View File

@ -6,8 +6,9 @@ from typing import Sequence, TYPE_CHECKING
from torchgen import dest from torchgen import dest
# disable import sorting to avoid circular dependency. # disable import sorting to avoid circular dependency.
from torchgen.api.types import DispatcherSignature # usort:skip from torchgen.api.types import DispatcherSignature # usort: skip
from torchgen.context import method_with_native_function from torchgen.context import method_with_native_function
from torchgen.model import BaseTy, BaseType, DispatchKey, NativeFunction, Variant from torchgen.model import BaseTy, BaseType, DispatchKey, NativeFunction, Variant
from torchgen.utils import concatMap, Target from torchgen.utils import concatMap, Target

View File

@ -1,2 +1,4 @@
from torchgen.executorch.api.types.types import * from torchgen.executorch.api.types.types import *
from torchgen.executorch.api.types.signatures import * # usort:skip
from torchgen.executorch.api.types.signatures import * # usort: skip