diff --git a/android/test_app/make_assets.py b/android/test_app/make_assets.py index 98afc63125fb..a6fd9e9315d2 100644 --- a/android/test_app/make_assets.py +++ b/android/test_app/make_assets.py @@ -1,6 +1,7 @@ -import torch from torchvision import models +import torch + print(torch.version.__version__) resnet18 = models.resnet18(weights=models.ResNet18_Weights.IMAGENET1K_V1) diff --git a/android/test_app/make_assets_custom.py b/android/test_app/make_assets_custom.py index 1e0b35dae51b..e1e50f17202a 100644 --- a/android/test_app/make_assets_custom.py +++ b/android/test_app/make_assets_custom.py @@ -4,10 +4,11 @@ MobileNetV2 TorchScript model, and dumps root ops used by the model for custom build script to create a tailored build which only contains these used ops. """ -import torch import yaml from torchvision import models +import torch + # Download and trace the model. model = models.mobilenet_v2(weights=models.MobileNet_V2_Weights.IMAGENET1K_V1) model.eval() diff --git a/benchmarks/distributed/ddp/benchmark.py b/benchmarks/distributed/ddp/benchmark.py index 483f53afe082..ee7fde14a60f 100644 --- a/benchmarks/distributed/ddp/benchmark.py +++ b/benchmarks/distributed/ddp/benchmark.py @@ -18,11 +18,12 @@ import sys import time import numpy as np +import torchvision + import torch import torch.distributed as dist import torch.nn as nn import torch.optim as optim -import torchvision def allgather_object(obj): diff --git a/benchmarks/distributed/pipeline/pipe.py b/benchmarks/distributed/pipeline/pipe.py index 670c1d5c1518..c465c2488565 100644 --- a/benchmarks/distributed/pipeline/pipe.py +++ b/benchmarks/distributed/pipeline/pipe.py @@ -3,10 +3,10 @@ import math import os import time +from benchmark_dataset import BenchmarkLMDataset, collate_sentences_lm + import torch import torch.nn as nn - -from benchmark_dataset import BenchmarkLMDataset, collate_sentences_lm from torch.distributed import rpc from torch.distributed.pipeline.sync import Pipe diff --git a/benchmarks/distributed/rpc/parameter_server/launcher.py b/benchmarks/distributed/rpc/parameter_server/launcher.py index 5ab8c51e2fa5..a084d1757e6e 100644 --- a/benchmarks/distributed/rpc/parameter_server/launcher.py +++ b/benchmarks/distributed/rpc/parameter_server/launcher.py @@ -3,18 +3,10 @@ import json import os from pathlib import Path -import torch -import torch.distributed as c10d -import torch.distributed.rpc as rpc -import torch.multiprocessing as mp - from data import data_map from metrics.ProcessedMetricsPrinter import ProcessedMetricsPrinter from models import model_map from server import server_map -from torch.distributed.rpc import TensorPipeRpcBackendOptions -from torch.futures import wait_all -from torch.utils.data import DataLoader from trainer import ( criterion_map, ddp_hook_map, @@ -25,6 +17,14 @@ from trainer import ( trainer_map, ) +import torch +import torch.distributed as c10d +import torch.distributed.rpc as rpc +import torch.multiprocessing as mp +from torch.distributed.rpc import TensorPipeRpcBackendOptions +from torch.futures import wait_all +from torch.utils.data import DataLoader + def get_name(rank, args): r""" diff --git a/benchmarks/distributed/rpc/parameter_server/server/server.py b/benchmarks/distributed/rpc/parameter_server/server/server.py index 639088a3b103..0f9a88aa48b8 100644 --- a/benchmarks/distributed/rpc/parameter_server/server/server.py +++ b/benchmarks/distributed/rpc/parameter_server/server/server.py @@ -3,12 +3,12 @@ import threading import time from abc import ABC, abstractmethod -import torch -import torch.distributed.rpc as rpc - from metrics.MetricsLogger import MetricsLogger from utils import sparse_rpc_format_to_tensor, sparse_tensor_to_rpc_format +import torch +import torch.distributed.rpc as rpc + class ParameterServerBase(ABC): PARAMETER_SERVER_BATCH_METRIC = "parameter_server_batch_metric" diff --git a/benchmarks/distributed/rpc/parameter_server/trainer/hooks.py b/benchmarks/distributed/rpc/parameter_server/trainer/hooks.py index 2e9b73084621..c4ebbb9a2ea3 100644 --- a/benchmarks/distributed/rpc/parameter_server/trainer/hooks.py +++ b/benchmarks/distributed/rpc/parameter_server/trainer/hooks.py @@ -1,6 +1,7 @@ +from utils import process_bucket_with_remote_server + import torch import torch.distributed as c10d -from utils import process_bucket_with_remote_server def allreduce_hook(state, bucket): diff --git a/benchmarks/distributed/rpc/parameter_server/trainer/trainer.py b/benchmarks/distributed/rpc/parameter_server/trainer/trainer.py index 47cae3bf64f6..d1483b7970b7 100644 --- a/benchmarks/distributed/rpc/parameter_server/trainer/trainer.py +++ b/benchmarks/distributed/rpc/parameter_server/trainer/trainer.py @@ -2,10 +2,10 @@ import functools import time from abc import ABC, abstractmethod -import torch - from metrics.MetricsLogger import MetricsLogger +import torch + class TrainerBase(ABC): BATCH_LEVEL_METRIC = "batch_level_metric" diff --git a/benchmarks/distributed/rpc/rl/coordinator.py b/benchmarks/distributed/rpc/rl/coordinator.py index 87f11407f2cb..75b1780a34f7 100644 --- a/benchmarks/distributed/rpc/rl/coordinator.py +++ b/benchmarks/distributed/rpc/rl/coordinator.py @@ -2,12 +2,12 @@ import time import numpy as np -import torch -import torch.distributed.rpc as rpc - from agent import AgentBase from observer import ObserverBase +import torch +import torch.distributed.rpc as rpc + COORDINATOR_NAME = "coordinator" AGENT_NAME = "agent" OBSERVER_NAME = "observer{}" diff --git a/benchmarks/distributed/rpc/rl/launcher.py b/benchmarks/distributed/rpc/rl/launcher.py index 0f682c16a815..22ae89629757 100644 --- a/benchmarks/distributed/rpc/rl/launcher.py +++ b/benchmarks/distributed/rpc/rl/launcher.py @@ -4,11 +4,11 @@ import json import os import time +from coordinator import CoordinatorBase + import torch.distributed.rpc as rpc import torch.multiprocessing as mp -from coordinator import CoordinatorBase - COORDINATOR_NAME = "coordinator" AGENT_NAME = "agent" OBSERVER_NAME = "observer{}" diff --git a/benchmarks/distributed/rpc/rl/observer.py b/benchmarks/distributed/rpc/rl/observer.py index 98ff0e59ccd5..c74c925d0478 100644 --- a/benchmarks/distributed/rpc/rl/observer.py +++ b/benchmarks/distributed/rpc/rl/observer.py @@ -1,10 +1,10 @@ import random import time +from agent import AgentBase + import torch import torch.distributed.rpc as rpc - -from agent import AgentBase from torch.distributed.rpc import rpc_sync diff --git a/benchmarks/dynamo/common.py b/benchmarks/dynamo/common.py index 9bd9893ed10a..a44ec5b67338 100644 --- a/benchmarks/dynamo/common.py +++ b/benchmarks/dynamo/common.py @@ -36,20 +36,21 @@ from typing import ( Type, TYPE_CHECKING, ) - from typing_extensions import Self from unittest.mock import MagicMock import numpy as np import pandas as pd import psutil +from scipy.stats import gmean, ttest_ind +from tqdm.auto import tqdm, trange + import torch import torch._dynamo import torch._dynamo.utils import torch._export import torch.distributed import torch.multiprocessing as mp -from scipy.stats import gmean, ttest_ind from torch._C import _has_cuda as HAS_CUDA, _has_xpu as HAS_XPU from torch._dynamo.profiler import fx_insert_profiling, Profiler from torch._dynamo.testing import ( @@ -59,8 +60,6 @@ from torch._dynamo.testing import ( same, ) -from tqdm.auto import tqdm, trange - try: from torch._dynamo.utils import ( clone_inputs, @@ -74,15 +73,14 @@ except ImportError: graph_break_reasons, maybe_enable_compiled_autograd, ) + import torch._functorch.config from torch._functorch.aot_autograd import set_model_name from torch._inductor import config as inductor_config, metrics from torch._subclasses.fake_tensor import FakeTensorMode - from torch.utils import _pytree as pytree from torch.utils._pytree import tree_map, tree_map_only - try: import torch_xla import torch_xla.core.xla_model as xm @@ -2343,17 +2341,17 @@ class BenchmarkRunner: def get_fsdp_auto_wrap_policy(self, model_name: str): from diffusers.models.transformer_2d import Transformer2DModel - - from torch.distributed.fsdp.wrap import ( - ModuleWrapPolicy, - size_based_auto_wrap_policy, - ) from torchbenchmark.models.nanogpt.model import Block from transformers.models.llama.modeling_llama import LlamaDecoderLayer from transformers.models.t5.modeling_t5 import T5Block from transformers.models.whisper.modeling_whisper import WhisperEncoderLayer + from torch.distributed.fsdp.wrap import ( + ModuleWrapPolicy, + size_based_auto_wrap_policy, + ) + # handcrafted wrap policy MODEL_FSDP_WRAP = { "stable_diffusion_unet": (Transformer2DModel,), diff --git a/benchmarks/dynamo/huggingface.py b/benchmarks/dynamo/huggingface.py index a998d10bf33c..5e139783c196 100755 --- a/benchmarks/dynamo/huggingface.py +++ b/benchmarks/dynamo/huggingface.py @@ -7,9 +7,10 @@ import subprocess import sys import warnings -import torch from common import BenchmarkRunner, download_retry_decorator, main, reset_rng_state +import torch + from torch._dynamo.testing import collect_results from torch._dynamo.utils import clone_inputs diff --git a/benchmarks/dynamo/microbenchmarks/bench_mm_fusion.py b/benchmarks/dynamo/microbenchmarks/bench_mm_fusion.py index fe1a15de9cae..424edac2b8f1 100644 --- a/benchmarks/dynamo/microbenchmarks/bench_mm_fusion.py +++ b/benchmarks/dynamo/microbenchmarks/bench_mm_fusion.py @@ -1,10 +1,11 @@ # flake8: noqa +import triton +from prettytable import PrettyTable + import torch import torch._dynamo import torch._inductor.config -import triton -from prettytable import PrettyTable # torch._inductor.config.debug = True torch._inductor.config.triton.dense_indexing = True diff --git a/benchmarks/dynamo/microbenchmarks/inductor_bmm.py b/benchmarks/dynamo/microbenchmarks/inductor_bmm.py index 7ac296a58ad8..5c5326beef62 100644 --- a/benchmarks/dynamo/microbenchmarks/inductor_bmm.py +++ b/benchmarks/dynamo/microbenchmarks/inductor_bmm.py @@ -1,9 +1,10 @@ +from benchmark_helper import time_with_torch_timer + import torch import torch._dynamo import torch._dynamo.config import torch._inductor.config as config -from benchmark_helper import time_with_torch_timer @torch._dynamo.optimize("inductor", nopython=True) diff --git a/benchmarks/dynamo/microbenchmarks/inductor_cpu_atomic.py b/benchmarks/dynamo/microbenchmarks/inductor_cpu_atomic.py index 679cce6d9156..7eeb6983a884 100644 --- a/benchmarks/dynamo/microbenchmarks/inductor_cpu_atomic.py +++ b/benchmarks/dynamo/microbenchmarks/inductor_cpu_atomic.py @@ -1,8 +1,9 @@ import itertools +from benchmark_helper import time_with_torch_timer + import torch import torch._dynamo -from benchmark_helper import time_with_torch_timer @torch._dynamo.optimize("inductor", nopython=True) diff --git a/benchmarks/dynamo/microbenchmarks/inductor_mm.py b/benchmarks/dynamo/microbenchmarks/inductor_mm.py index deb3d8f8b604..2db6fc0e7222 100644 --- a/benchmarks/dynamo/microbenchmarks/inductor_mm.py +++ b/benchmarks/dynamo/microbenchmarks/inductor_mm.py @@ -1,10 +1,11 @@ +import triton +from benchmark_helper import time_with_torch_timer + import torch import torch._dynamo import torch._dynamo.config import torch._inductor.config as config -import triton -from benchmark_helper import time_with_torch_timer # The flag below controls whether to allow TF32 on matmul. This flag defaults to True. torch.backends.cuda.matmul.allow_tf32 = True diff --git a/benchmarks/dynamo/microbenchmarks/matmul_relu.py b/benchmarks/dynamo/microbenchmarks/matmul_relu.py index 629b574617ec..9baf893af96d 100644 --- a/benchmarks/dynamo/microbenchmarks/matmul_relu.py +++ b/benchmarks/dynamo/microbenchmarks/matmul_relu.py @@ -1,8 +1,9 @@ +from benchmark_helper import time_with_torch_timer + import torch import torch._dynamo import torch._inductor.config as inductor_config -from benchmark_helper import time_with_torch_timer inductor_config.triton.mm = "triton" diff --git a/benchmarks/dynamo/microbenchmarks/microbench.py b/benchmarks/dynamo/microbenchmarks/microbench.py index c4fbafe4667e..f41ec9198fdf 100755 --- a/benchmarks/dynamo/microbenchmarks/microbench.py +++ b/benchmarks/dynamo/microbenchmarks/microbench.py @@ -5,6 +5,7 @@ import sys import numpy as np import tabulate + import torch import torch._inductor diff --git a/benchmarks/dynamo/microbenchmarks/operatorbench.py b/benchmarks/dynamo/microbenchmarks/operatorbench.py index 22e267dfc187..dcc2b428d2e2 100644 --- a/benchmarks/dynamo/microbenchmarks/operatorbench.py +++ b/benchmarks/dynamo/microbenchmarks/operatorbench.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 import click import numpy as np -import torch from operator_inp_utils import OperatorInputsLoader +import torch + from torch._dynamo.backends.cudagraphs import cudagraphs_inner from torch._dynamo.testing import same from torch._inductor.compile_fx import compile_fx diff --git a/benchmarks/dynamo/runner.py b/benchmarks/dynamo/runner.py index 2a2161387472..54cff5658257 100755 --- a/benchmarks/dynamo/runner.py +++ b/benchmarks/dynamo/runner.py @@ -47,13 +47,14 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd -import torch - -import torch._dynamo from matplotlib import rcParams from scipy.stats import gmean from tabulate import tabulate +import torch + +import torch._dynamo + rcParams.update({"figure.autolayout": True}) plt.rc("axes", axisbelow=True) diff --git a/benchmarks/dynamo/timm_models.py b/benchmarks/dynamo/timm_models.py index 1d291e8d1d75..db29a9bf365a 100755 --- a/benchmarks/dynamo/timm_models.py +++ b/benchmarks/dynamo/timm_models.py @@ -7,9 +7,10 @@ import subprocess import sys import warnings -import torch from common import BenchmarkRunner, download_retry_decorator, main +import torch + from torch._dynamo.testing import collect_results, reduce_to_scalar_loss from torch._dynamo.utils import clone_inputs diff --git a/benchmarks/dynamo/torchbench.py b/benchmarks/dynamo/torchbench.py index bf497a2b1997..fd11e984bbdc 100755 --- a/benchmarks/dynamo/torchbench.py +++ b/benchmarks/dynamo/torchbench.py @@ -10,9 +10,10 @@ import warnings from collections import namedtuple from os.path import abspath, exists -import torch import yaml +import torch + try: from .common import BenchmarkRunner, main except ImportError: diff --git a/benchmarks/dynamo/training_loss.py b/benchmarks/dynamo/training_loss.py index 8886553c9736..f90d8e5b0bd4 100644 --- a/benchmarks/dynamo/training_loss.py +++ b/benchmarks/dynamo/training_loss.py @@ -5,12 +5,13 @@ import sys import time from datetime import timedelta +from datasets import load_dataset, load_metric +from transformers import AutoModelForSequenceClassification, AutoTokenizer + import torch import torch._dynamo -from datasets import load_dataset, load_metric from torch.utils.data import DataLoader -from transformers import AutoModelForSequenceClassification, AutoTokenizer torch.backends.cuda.matmul.allow_tf32 = True diff --git a/benchmarks/fastrnns/runner.py b/benchmarks/fastrnns/runner.py index 6f8d38be5dc3..435b4a9594bf 100644 --- a/benchmarks/fastrnns/runner.py +++ b/benchmarks/fastrnns/runner.py @@ -1,9 +1,10 @@ from collections import namedtuple from functools import partial -import torch import torchvision.models as cnn +import torch + from .factory import ( dropoutlstm_creator, imagenet_cnn_creator, diff --git a/benchmarks/fastrnns/test_bench.py b/benchmarks/fastrnns/test_bench.py index d7fea21049b6..fe5bd310d8cc 100644 --- a/benchmarks/fastrnns/test_bench.py +++ b/benchmarks/fastrnns/test_bench.py @@ -1,4 +1,5 @@ import pytest + import torch from .fuser import set_fuser diff --git a/benchmarks/framework_overhead_benchmark/SimpleAddModule.py b/benchmarks/framework_overhead_benchmark/SimpleAddModule.py index bdf2c199f518..54453ba687f6 100644 --- a/benchmarks/framework_overhead_benchmark/SimpleAddModule.py +++ b/benchmarks/framework_overhead_benchmark/SimpleAddModule.py @@ -1,6 +1,7 @@ -import torch from utils import NUM_LOOP_ITERS +import torch + def add_tensors_loop(x, y): z = torch.add(x, y) diff --git a/benchmarks/functional_autograd_benchmark/audio_text_models.py b/benchmarks/functional_autograd_benchmark/audio_text_models.py index abe1a8a58698..3add9b7e3d55 100644 --- a/benchmarks/functional_autograd_benchmark/audio_text_models.py +++ b/benchmarks/functional_autograd_benchmark/audio_text_models.py @@ -1,10 +1,10 @@ -import torch - import torchaudio_models as models -from torch import nn, Tensor from utils import check_for_functorch, extract_weights, GetterReturnType, load_weights +import torch +from torch import nn, Tensor + has_functorch = check_for_functorch() diff --git a/benchmarks/functional_autograd_benchmark/ppl_models.py b/benchmarks/functional_autograd_benchmark/ppl_models.py index aa61e43c344c..3aba795e7362 100644 --- a/benchmarks/functional_autograd_benchmark/ppl_models.py +++ b/benchmarks/functional_autograd_benchmark/ppl_models.py @@ -1,9 +1,9 @@ +from utils import GetterReturnType + import torch import torch.distributions as dist from torch import Tensor -from utils import GetterReturnType - def get_simple_regression(device: torch.device) -> GetterReturnType: N = 10 diff --git a/benchmarks/functional_autograd_benchmark/vision_models.py b/benchmarks/functional_autograd_benchmark/vision_models.py index ee919b040975..4f1050b29397 100644 --- a/benchmarks/functional_autograd_benchmark/vision_models.py +++ b/benchmarks/functional_autograd_benchmark/vision_models.py @@ -1,11 +1,12 @@ from typing import cast -import torch import torchvision_models as models -from torch import Tensor from utils import check_for_functorch, extract_weights, GetterReturnType, load_weights +import torch +from torch import Tensor + has_functorch = check_for_functorch() diff --git a/benchmarks/fuser/run_benchmarks.py b/benchmarks/fuser/run_benchmarks.py index cc6a84dd70f1..40d1b5e9d0f2 100644 --- a/benchmarks/fuser/run_benchmarks.py +++ b/benchmarks/fuser/run_benchmarks.py @@ -4,6 +4,7 @@ import sys import time import click + import torch torch.set_num_threads(1) diff --git a/benchmarks/gpt_fast/benchmark.py b/benchmarks/gpt_fast/benchmark.py index efc332d110f6..083c98e4a92b 100644 --- a/benchmarks/gpt_fast/benchmark.py +++ b/benchmarks/gpt_fast/benchmark.py @@ -6,8 +6,6 @@ import os import time from typing import Optional, Tuple -import torch -import torch._inductor.config from mixtral_moe_model import Transformer as MixtralMoE from mixtral_moe_quantize import ( WeightOnlyInt8QuantHandler as MixtralMoEWeightOnlyInt8QuantHandler, @@ -15,6 +13,9 @@ from mixtral_moe_quantize import ( from model import Transformer as LLaMA from quantize import WeightOnlyInt8QuantHandler as LLaMAWeightOnlyInt8QuantHandler +import torch +import torch._inductor.config + torch._inductor.config.coordinate_descent_tuning = True torch._inductor.config.triton.unique_kernel_names = True torch._inductor.config.fx_graph_cache = True # Experimental feature to reduce compilation times, will be on by default in future diff --git a/benchmarks/gpt_fast/mixtral_moe_quantize.py b/benchmarks/gpt_fast/mixtral_moe_quantize.py index fbf8caa8964a..6dfac4a9938d 100644 --- a/benchmarks/gpt_fast/mixtral_moe_quantize.py +++ b/benchmarks/gpt_fast/mixtral_moe_quantize.py @@ -1,10 +1,10 @@ # flake8: noqa: E266, C417, B950 +from mixtral_moe_model import ConditionalFeedForward + import torch import torch.nn as nn import torch.nn.functional as F -from mixtral_moe_model import ConditionalFeedForward - ##### Quantization Primitives ###### diff --git a/benchmarks/inference/server.py b/benchmarks/inference/server.py index 28dfa58ed3c0..6c33980b887b 100644 --- a/benchmarks/inference/server.py +++ b/benchmarks/inference/server.py @@ -187,9 +187,10 @@ class BackendWorker: def _setup(self): import time - import torch from torchvision.models.resnet import BasicBlock, ResNet + import torch + # Create ResNet18 on meta device with torch.device("meta"): m = ResNet(BasicBlock, [2, 2, 2, 2]) diff --git a/benchmarks/instruction_counts/core/utils.py b/benchmarks/instruction_counts/core/utils.py index 484909dcd979..0602b540fcb9 100644 --- a/benchmarks/instruction_counts/core/utils.py +++ b/benchmarks/instruction_counts/core/utils.py @@ -4,11 +4,11 @@ import shutil import textwrap from typing import List, Optional, Tuple -from torch.utils.benchmark.utils.common import _make_temp_dir - from core.api import GroupedBenchmark, TimerArgs from core.types import Definition, FlatIntermediateDefinition, Label +from torch.utils.benchmark.utils.common import _make_temp_dir + _TEMPDIR: Optional[str] = None diff --git a/benchmarks/operator_benchmark/benchmark_core.py b/benchmarks/operator_benchmark/benchmark_core.py index ec4d244bb5a2..c315382d1538 100644 --- a/benchmarks/operator_benchmark/benchmark_core.py +++ b/benchmarks/operator_benchmark/benchmark_core.py @@ -7,6 +7,7 @@ from collections import namedtuple import benchmark_utils import numpy as np + import torch # needs to be imported after torch diff --git a/benchmarks/operator_benchmark/benchmark_pytorch.py b/benchmarks/operator_benchmark/benchmark_pytorch.py index 8d898b2803de..40daf7ad43fe 100644 --- a/benchmarks/operator_benchmark/benchmark_pytorch.py +++ b/benchmarks/operator_benchmark/benchmark_pytorch.py @@ -2,6 +2,7 @@ import json import time import benchmark_cpp_extension # noqa: F401 + import torch diff --git a/benchmarks/operator_benchmark/common/repeat_benchmark.py b/benchmarks/operator_benchmark/common/repeat_benchmark.py index 6e8170ce6fbc..8f8f5fffb8ac 100644 --- a/benchmarks/operator_benchmark/common/repeat_benchmark.py +++ b/benchmarks/operator_benchmark/common/repeat_benchmark.py @@ -1,6 +1,7 @@ import time import numpy as np + import torch """Microbenchmarks for Tensor repeat operator. Supports PyTorch.""" diff --git a/benchmarks/operator_benchmark/common/tests/add_ops_list_test.py b/benchmarks/operator_benchmark/common/tests/add_ops_list_test.py index 5ac29ee20ec9..48ad9a044f5b 100644 --- a/benchmarks/operator_benchmark/common/tests/add_ops_list_test.py +++ b/benchmarks/operator_benchmark/common/tests/add_ops_list_test.py @@ -1,4 +1,5 @@ import operator_benchmark as op_bench + import torch diff --git a/benchmarks/operator_benchmark/common/tests/jit_forward_test.py b/benchmarks/operator_benchmark/common/tests/jit_forward_test.py index 92f766084afa..339b2856c708 100644 --- a/benchmarks/operator_benchmark/common/tests/jit_forward_test.py +++ b/benchmarks/operator_benchmark/common/tests/jit_forward_test.py @@ -1,4 +1,5 @@ import operator_benchmark as op_bench + import torch intraop_bench_configs = op_bench.config_list( diff --git a/benchmarks/operator_benchmark/common/tests/pt_backward_test.py b/benchmarks/operator_benchmark/common/tests/pt_backward_test.py index 385b87aaeb55..3870e58b861c 100644 --- a/benchmarks/operator_benchmark/common/tests/pt_backward_test.py +++ b/benchmarks/operator_benchmark/common/tests/pt_backward_test.py @@ -1,4 +1,5 @@ import operator_benchmark as op_bench + import torch diff --git a/benchmarks/operator_benchmark/common/tests/pt_configs_list_test.py b/benchmarks/operator_benchmark/common/tests/pt_configs_list_test.py index 79da6b7da0c1..8e92f5bca183 100644 --- a/benchmarks/operator_benchmark/common/tests/pt_configs_list_test.py +++ b/benchmarks/operator_benchmark/common/tests/pt_configs_list_test.py @@ -1,4 +1,5 @@ import operator_benchmark as op_bench + import torch """Microbenchmarks for element-wise Add operator. Supports both Caffe2/PyTorch.""" diff --git a/benchmarks/operator_benchmark/common/tests/pt_cpu_gpu_forward_backward_test.py b/benchmarks/operator_benchmark/common/tests/pt_cpu_gpu_forward_backward_test.py index 6e685bd7d705..5c12f48f66f6 100644 --- a/benchmarks/operator_benchmark/common/tests/pt_cpu_gpu_forward_backward_test.py +++ b/benchmarks/operator_benchmark/common/tests/pt_cpu_gpu_forward_backward_test.py @@ -1,4 +1,5 @@ import operator_benchmark as op_bench + import torch diff --git a/benchmarks/operator_benchmark/common/tests/random_sample_test.py b/benchmarks/operator_benchmark/common/tests/random_sample_test.py index 92b0d96cf691..f12f64f3fc5b 100644 --- a/benchmarks/operator_benchmark/common/tests/random_sample_test.py +++ b/benchmarks/operator_benchmark/common/tests/random_sample_test.py @@ -1,4 +1,5 @@ import operator_benchmark as op_bench + import torch diff --git a/benchmarks/operator_benchmark/pt/add_test.py b/benchmarks/operator_benchmark/pt/add_test.py index 3b63187dbce2..8431e4d398de 100644 --- a/benchmarks/operator_benchmark/pt/add_test.py +++ b/benchmarks/operator_benchmark/pt/add_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for add_ operator. Supports both Caffe2/PyTorch.""" diff --git a/benchmarks/operator_benchmark/pt/ao_sparsifier_test.py b/benchmarks/operator_benchmark/pt/ao_sparsifier_test.py index ba1bf0c1b9e0..a00e0dc3b211 100644 --- a/benchmarks/operator_benchmark/pt/ao_sparsifier_test.py +++ b/benchmarks/operator_benchmark/pt/ao_sparsifier_test.py @@ -1,10 +1,9 @@ +import operator_benchmark as op_bench import torch from torch import nn from torch.ao import pruning -import operator_benchmark as op_bench - """Microbenchmarks for sparsifier.""" diff --git a/benchmarks/operator_benchmark/pt/as_strided_test.py b/benchmarks/operator_benchmark/pt/as_strided_test.py index 793e82cf11b5..d699b4bde476 100644 --- a/benchmarks/operator_benchmark/pt/as_strided_test.py +++ b/benchmarks/operator_benchmark/pt/as_strided_test.py @@ -1,9 +1,9 @@ from typing import List -import torch - import operator_benchmark as op_bench +import torch + """Microbenchmarks for as_strided operator""" diff --git a/benchmarks/operator_benchmark/pt/batchnorm_test.py b/benchmarks/operator_benchmark/pt/batchnorm_test.py index 3f0dbf99e192..4524c307797b 100644 --- a/benchmarks/operator_benchmark/pt/batchnorm_test.py +++ b/benchmarks/operator_benchmark/pt/batchnorm_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.nn.functional as F -import operator_benchmark as op_bench - """Microbenchmarks for batchnorm operator.""" diff --git a/benchmarks/operator_benchmark/pt/binary_test.py b/benchmarks/operator_benchmark/pt/binary_test.py index ddc8276da0b9..a8c9256610da 100644 --- a/benchmarks/operator_benchmark/pt/binary_test.py +++ b/benchmarks/operator_benchmark/pt/binary_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for binary operators.""" diff --git a/benchmarks/operator_benchmark/pt/bmm_test.py b/benchmarks/operator_benchmark/pt/bmm_test.py index 61c9dc470e82..3fcdb70cc6ad 100644 --- a/benchmarks/operator_benchmark/pt/bmm_test.py +++ b/benchmarks/operator_benchmark/pt/bmm_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for add_ operator. Supports both Caffe2/PyTorch.""" diff --git a/benchmarks/operator_benchmark/pt/cat_test.py b/benchmarks/operator_benchmark/pt/cat_test.py index f0655b749b4c..ee376d02469f 100644 --- a/benchmarks/operator_benchmark/pt/cat_test.py +++ b/benchmarks/operator_benchmark/pt/cat_test.py @@ -1,10 +1,10 @@ import random from typing import List -import torch - import operator_benchmark as op_bench +import torch + """Microbenchmarks for Cat operator""" diff --git a/benchmarks/operator_benchmark/pt/channel_shuffle_test.py b/benchmarks/operator_benchmark/pt/channel_shuffle_test.py index bbc5708d15ad..40742b45d3f0 100644 --- a/benchmarks/operator_benchmark/pt/channel_shuffle_test.py +++ b/benchmarks/operator_benchmark/pt/channel_shuffle_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for channel_shuffle operator.""" diff --git a/benchmarks/operator_benchmark/pt/chunk_test.py b/benchmarks/operator_benchmark/pt/chunk_test.py index e471d801db01..d6c203efe423 100644 --- a/benchmarks/operator_benchmark/pt/chunk_test.py +++ b/benchmarks/operator_benchmark/pt/chunk_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for Chunk operator""" diff --git a/benchmarks/operator_benchmark/pt/clip_ranges_test.py b/benchmarks/operator_benchmark/pt/clip_ranges_test.py index 07ba18a21d3f..0e4889af44fc 100644 --- a/benchmarks/operator_benchmark/pt/clip_ranges_test.py +++ b/benchmarks/operator_benchmark/pt/clip_ranges_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for ClipRanges operator.""" diff --git a/benchmarks/operator_benchmark/pt/conv_test.py b/benchmarks/operator_benchmark/pt/conv_test.py index 09b5d83a62e8..e01473a04f5b 100644 --- a/benchmarks/operator_benchmark/pt/conv_test.py +++ b/benchmarks/operator_benchmark/pt/conv_test.py @@ -1,9 +1,8 @@ -import torch -import torch.nn as nn - from pt import configs import operator_benchmark as op_bench +import torch +import torch.nn as nn """ Microbenchmarks for Conv1d and ConvTranspose1d operators. diff --git a/benchmarks/operator_benchmark/pt/diag_test.py b/benchmarks/operator_benchmark/pt/diag_test.py index 0f3a15a939a5..bb128a56bfa1 100644 --- a/benchmarks/operator_benchmark/pt/diag_test.py +++ b/benchmarks/operator_benchmark/pt/diag_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for diag operator""" diff --git a/benchmarks/operator_benchmark/pt/embeddingbag_test.py b/benchmarks/operator_benchmark/pt/embeddingbag_test.py index e9a3ade5ce29..f73fbc5425b0 100644 --- a/benchmarks/operator_benchmark/pt/embeddingbag_test.py +++ b/benchmarks/operator_benchmark/pt/embeddingbag_test.py @@ -1,8 +1,8 @@ import numpy -import torch from pt import configs import operator_benchmark as op_bench +import torch """Embedding and EmbeddingBag Operator Benchmark""" diff --git a/benchmarks/operator_benchmark/pt/fill_test.py b/benchmarks/operator_benchmark/pt/fill_test.py index 71fbee459bd2..1252e81982ca 100644 --- a/benchmarks/operator_benchmark/pt/fill_test.py +++ b/benchmarks/operator_benchmark/pt/fill_test.py @@ -1,9 +1,8 @@ +import operator_benchmark as op_bench import torch from torch.testing._internal.common_device_type import get_all_device_types -import operator_benchmark as op_bench - """Microbenchmark for Fill_ operator.""" fill_short_configs = op_bench.config_list( diff --git a/benchmarks/operator_benchmark/pt/gather_test.py b/benchmarks/operator_benchmark/pt/gather_test.py index 6bedf8027320..8a4db487b75d 100644 --- a/benchmarks/operator_benchmark/pt/gather_test.py +++ b/benchmarks/operator_benchmark/pt/gather_test.py @@ -1,7 +1,7 @@ import numpy -import torch import operator_benchmark as op_bench +import torch """Microbenchmarks for gather operator.""" diff --git a/benchmarks/operator_benchmark/pt/gelu_test.py b/benchmarks/operator_benchmark/pt/gelu_test.py index 260566b00489..ab83f6659e19 100644 --- a/benchmarks/operator_benchmark/pt/gelu_test.py +++ b/benchmarks/operator_benchmark/pt/gelu_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """ diff --git a/benchmarks/operator_benchmark/pt/groupnorm_test.py b/benchmarks/operator_benchmark/pt/groupnorm_test.py index bd555eb78330..ead09808ece3 100644 --- a/benchmarks/operator_benchmark/pt/groupnorm_test.py +++ b/benchmarks/operator_benchmark/pt/groupnorm_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.nn.functional as F -import operator_benchmark as op_bench - """Microbenchmarks for groupnorm operator.""" diff --git a/benchmarks/operator_benchmark/pt/hardsigmoid_test.py b/benchmarks/operator_benchmark/pt/hardsigmoid_test.py index 6b2d038afc06..7e9b51a0c84d 100644 --- a/benchmarks/operator_benchmark/pt/hardsigmoid_test.py +++ b/benchmarks/operator_benchmark/pt/hardsigmoid_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.nn as nn -import operator_benchmark as op_bench - """ Microbenchmarks for the hardsigmoid operator. diff --git a/benchmarks/operator_benchmark/pt/hardswish_test.py b/benchmarks/operator_benchmark/pt/hardswish_test.py index 8d53d34721aa..d93fe298d2e4 100644 --- a/benchmarks/operator_benchmark/pt/hardswish_test.py +++ b/benchmarks/operator_benchmark/pt/hardswish_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.nn as nn -import operator_benchmark as op_bench - """ Microbenchmarks for the hardswish operators. diff --git a/benchmarks/operator_benchmark/pt/index_select_test.py b/benchmarks/operator_benchmark/pt/index_select_test.py index 304dd86bac40..c4a0c233e91d 100644 --- a/benchmarks/operator_benchmark/pt/index_select_test.py +++ b/benchmarks/operator_benchmark/pt/index_select_test.py @@ -1,7 +1,7 @@ import numpy -import torch import operator_benchmark as op_bench +import torch """Microbenchmarks for index_select operator.""" diff --git a/benchmarks/operator_benchmark/pt/instancenorm_test.py b/benchmarks/operator_benchmark/pt/instancenorm_test.py index 9edd846d586e..47f8243817ca 100644 --- a/benchmarks/operator_benchmark/pt/instancenorm_test.py +++ b/benchmarks/operator_benchmark/pt/instancenorm_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.nn.functional as F -import operator_benchmark as op_bench - """Microbenchmarks for instancenorm operator.""" diff --git a/benchmarks/operator_benchmark/pt/interpolate_test.py b/benchmarks/operator_benchmark/pt/interpolate_test.py index 9679f9f363a5..0ae487bc8320 100644 --- a/benchmarks/operator_benchmark/pt/interpolate_test.py +++ b/benchmarks/operator_benchmark/pt/interpolate_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for interpolate operator.""" diff --git a/benchmarks/operator_benchmark/pt/layernorm_test.py b/benchmarks/operator_benchmark/pt/layernorm_test.py index 8ad3cd925c1a..82f12cbaf587 100644 --- a/benchmarks/operator_benchmark/pt/layernorm_test.py +++ b/benchmarks/operator_benchmark/pt/layernorm_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.nn.functional as F -import operator_benchmark as op_bench - """Microbenchmarks for layernorm operator.""" diff --git a/benchmarks/operator_benchmark/pt/linear_prepack_fp16_test.py b/benchmarks/operator_benchmark/pt/linear_prepack_fp16_test.py index b8532b9de356..e2c72bec92a7 100644 --- a/benchmarks/operator_benchmark/pt/linear_prepack_fp16_test.py +++ b/benchmarks/operator_benchmark/pt/linear_prepack_fp16_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for linear_prepack_fp16_ operator. Supports both Caffe2/PyTorch.""" diff --git a/benchmarks/operator_benchmark/pt/linear_test.py b/benchmarks/operator_benchmark/pt/linear_test.py index c51949b8369b..cf7a87f0ec0a 100644 --- a/benchmarks/operator_benchmark/pt/linear_test.py +++ b/benchmarks/operator_benchmark/pt/linear_test.py @@ -1,9 +1,8 @@ -import torch -import torch.nn as nn - from pt import configs import operator_benchmark as op_bench +import torch +import torch.nn as nn """Microbenchmarks for Linear operator.""" diff --git a/benchmarks/operator_benchmark/pt/linear_unpack_fp16_test.py b/benchmarks/operator_benchmark/pt/linear_unpack_fp16_test.py index f2615bfbef55..3b2ef5bc1345 100644 --- a/benchmarks/operator_benchmark/pt/linear_unpack_fp16_test.py +++ b/benchmarks/operator_benchmark/pt/linear_unpack_fp16_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for linear_unpack_fp16_ operator. Supports both Caffe2/PyTorch.""" diff --git a/benchmarks/operator_benchmark/pt/matmul_test.py b/benchmarks/operator_benchmark/pt/matmul_test.py index 73e6c7e20498..5a2d52e05202 100644 --- a/benchmarks/operator_benchmark/pt/matmul_test.py +++ b/benchmarks/operator_benchmark/pt/matmul_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for MatMul operator""" diff --git a/benchmarks/operator_benchmark/pt/matrix_mult_test.py b/benchmarks/operator_benchmark/pt/matrix_mult_test.py index 38b069f96994..f95c28c663cf 100644 --- a/benchmarks/operator_benchmark/pt/matrix_mult_test.py +++ b/benchmarks/operator_benchmark/pt/matrix_mult_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """ Microbenchmarks for batch matrix mult with einsum and torch.bmm. diff --git a/benchmarks/operator_benchmark/pt/nan_to_num_test.py b/benchmarks/operator_benchmark/pt/nan_to_num_test.py index 7067fc8ae8e1..77aa92464496 100644 --- a/benchmarks/operator_benchmark/pt/nan_to_num_test.py +++ b/benchmarks/operator_benchmark/pt/nan_to_num_test.py @@ -1,9 +1,9 @@ import math -import torch - import operator_benchmark as op_bench +import torch + """Microbenchmarks for torch.nan_to_num / nan_to_num_ operators""" diff --git a/benchmarks/operator_benchmark/pt/pool_test.py b/benchmarks/operator_benchmark/pt/pool_test.py index 266aa40ea934..6ac67cece9b3 100644 --- a/benchmarks/operator_benchmark/pt/pool_test.py +++ b/benchmarks/operator_benchmark/pt/pool_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.nn as nn -import operator_benchmark as op_bench - """ Microbenchmarks for MaxPool1d and AvgPool1d operators. """ diff --git a/benchmarks/operator_benchmark/pt/qactivation_test.py b/benchmarks/operator_benchmark/pt/qactivation_test.py index 980c8e2d2747..65e8516a2522 100644 --- a/benchmarks/operator_benchmark/pt/qactivation_test.py +++ b/benchmarks/operator_benchmark/pt/qactivation_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.ao.nn.quantized.functional as qF -import operator_benchmark as op_bench - r"""Microbenchmarks for the quantized activations.""" qactivation_long_configs = op_bench.cross_product_configs( diff --git a/benchmarks/operator_benchmark/pt/qarithmetic_test.py b/benchmarks/operator_benchmark/pt/qarithmetic_test.py index 96db3f99cd8a..7a8def81bc5a 100644 --- a/benchmarks/operator_benchmark/pt/qarithmetic_test.py +++ b/benchmarks/operator_benchmark/pt/qarithmetic_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch from torch._ops import ops -import operator_benchmark as op_bench - qarithmetic_binary_configs = op_bench.cross_product_configs( N=(2, 8, 64, 512), dtype=(torch.quint8, torch.qint8, torch.qint32), diff --git a/benchmarks/operator_benchmark/pt/qatembedding_ops_test.py b/benchmarks/operator_benchmark/pt/qatembedding_ops_test.py index b5b8e6efb4e9..2e72dbe14223 100644 --- a/benchmarks/operator_benchmark/pt/qatembedding_ops_test.py +++ b/benchmarks/operator_benchmark/pt/qatembedding_ops_test.py @@ -1,10 +1,10 @@ import numpy -import torch -import torch.ao.nn.qat as nnqat from pt import configs -from torch.ao.quantization import default_embedding_qat_qconfig import operator_benchmark as op_bench +import torch +import torch.ao.nn.qat as nnqat +from torch.ao.quantization import default_embedding_qat_qconfig """ Microbenchmarks for QAT Embedding + EmbeddingBag operators. diff --git a/benchmarks/operator_benchmark/pt/qbatchnorm_test.py b/benchmarks/operator_benchmark/pt/qbatchnorm_test.py index 38a11acbb588..b8cee3ae02ba 100644 --- a/benchmarks/operator_benchmark/pt/qbatchnorm_test.py +++ b/benchmarks/operator_benchmark/pt/qbatchnorm_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for quantized batchnorm operator.""" diff --git a/benchmarks/operator_benchmark/pt/qcat_test.py b/benchmarks/operator_benchmark/pt/qcat_test.py index 09c0f9290011..86882e05f551 100644 --- a/benchmarks/operator_benchmark/pt/qcat_test.py +++ b/benchmarks/operator_benchmark/pt/qcat_test.py @@ -1,10 +1,10 @@ from typing import List +import operator_benchmark as op_bench + import torch import torch.ao.nn.quantized as nnq -import operator_benchmark as op_bench - """Microbenchmarks for quantized Cat operator""" diff --git a/benchmarks/operator_benchmark/pt/qcomparators_test.py b/benchmarks/operator_benchmark/pt/qcomparators_test.py index 73b2f4d6db56..9a251d6417aa 100644 --- a/benchmarks/operator_benchmark/pt/qcomparators_test.py +++ b/benchmarks/operator_benchmark/pt/qcomparators_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch qcomparators_configs = op_bench.cross_product_configs( N=(8, 64), diff --git a/benchmarks/operator_benchmark/pt/qconv_test.py b/benchmarks/operator_benchmark/pt/qconv_test.py index 4d7b77ffa43a..52374acf95be 100644 --- a/benchmarks/operator_benchmark/pt/qconv_test.py +++ b/benchmarks/operator_benchmark/pt/qconv_test.py @@ -1,9 +1,8 @@ -import torch -import torch.ao.nn.quantized as nnq - from pt import configs import operator_benchmark as op_bench +import torch +import torch.ao.nn.quantized as nnq """ Microbenchmarks for qConv operators. diff --git a/benchmarks/operator_benchmark/pt/qembedding_bag_lookups_test.py b/benchmarks/operator_benchmark/pt/qembedding_bag_lookups_test.py index c9b34215cc45..7ee0792d1ef6 100644 --- a/benchmarks/operator_benchmark/pt/qembedding_bag_lookups_test.py +++ b/benchmarks/operator_benchmark/pt/qembedding_bag_lookups_test.py @@ -1,12 +1,12 @@ from typing import Optional import numpy as np + +import operator_benchmark as op_bench import torch from torch.testing._internal.common_quantization import lengths_to_offsets -import operator_benchmark as op_bench - torch.ops.load_library("//caffe2/torch/fb/sparsenn:sparsenn_operators") diff --git a/benchmarks/operator_benchmark/pt/qembedding_pack_test.py b/benchmarks/operator_benchmark/pt/qembedding_pack_test.py index 7bf756751250..cfc6c51024ac 100644 --- a/benchmarks/operator_benchmark/pt/qembedding_pack_test.py +++ b/benchmarks/operator_benchmark/pt/qembedding_pack_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch embeddingbag_conversion_short_configs = op_bench.cross_product_configs( num_embeddings=(80,), embedding_dim=(128, 256, 512), tags=("short",) diff --git a/benchmarks/operator_benchmark/pt/qembeddingbag_test.py b/benchmarks/operator_benchmark/pt/qembeddingbag_test.py index 5ee6c38d787d..fe563af0bc80 100644 --- a/benchmarks/operator_benchmark/pt/qembeddingbag_test.py +++ b/benchmarks/operator_benchmark/pt/qembeddingbag_test.py @@ -1,9 +1,9 @@ import numpy -import torch -import torch.ao.nn.quantized as nnq from pt import configs import operator_benchmark as op_bench +import torch +import torch.ao.nn.quantized as nnq """ Microbenchmarks for qEmbeddingBag operators. diff --git a/benchmarks/operator_benchmark/pt/qgroupnorm_test.py b/benchmarks/operator_benchmark/pt/qgroupnorm_test.py index fc6f85c8c0e9..0148800450e8 100644 --- a/benchmarks/operator_benchmark/pt/qgroupnorm_test.py +++ b/benchmarks/operator_benchmark/pt/qgroupnorm_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for quantized groupnorm operator.""" diff --git a/benchmarks/operator_benchmark/pt/qinstancenorm_test.py b/benchmarks/operator_benchmark/pt/qinstancenorm_test.py index d949ec7f6379..4dcec4f2a886 100644 --- a/benchmarks/operator_benchmark/pt/qinstancenorm_test.py +++ b/benchmarks/operator_benchmark/pt/qinstancenorm_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for quantized instancenorm operator.""" diff --git a/benchmarks/operator_benchmark/pt/qinterpolate_test.py b/benchmarks/operator_benchmark/pt/qinterpolate_test.py index 95fa9327cb56..c3afc308f6ba 100644 --- a/benchmarks/operator_benchmark/pt/qinterpolate_test.py +++ b/benchmarks/operator_benchmark/pt/qinterpolate_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for the quantized interpolate op. diff --git a/benchmarks/operator_benchmark/pt/qlayernorm_test.py b/benchmarks/operator_benchmark/pt/qlayernorm_test.py index 27855e938d65..c2015b920d67 100644 --- a/benchmarks/operator_benchmark/pt/qlayernorm_test.py +++ b/benchmarks/operator_benchmark/pt/qlayernorm_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for quantized layernorm operator.""" diff --git a/benchmarks/operator_benchmark/pt/qlinear_test.py b/benchmarks/operator_benchmark/pt/qlinear_test.py index bde440afe094..1e96b3a75d1f 100644 --- a/benchmarks/operator_benchmark/pt/qlinear_test.py +++ b/benchmarks/operator_benchmark/pt/qlinear_test.py @@ -1,10 +1,9 @@ -import torch -import torch.ao.nn.quantized as nnq -import torch.ao.nn.quantized.dynamic as nnqd - from pt import configs import operator_benchmark as op_bench +import torch +import torch.ao.nn.quantized as nnq +import torch.ao.nn.quantized.dynamic as nnqd """ Microbenchmarks for Quantized Linear operators. diff --git a/benchmarks/operator_benchmark/pt/qobserver_test.py b/benchmarks/operator_benchmark/pt/qobserver_test.py index ab17e995f7f3..c4ab625f936d 100644 --- a/benchmarks/operator_benchmark/pt/qobserver_test.py +++ b/benchmarks/operator_benchmark/pt/qobserver_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.ao.quantization.observer as obs -import operator_benchmark as op_bench - qobserver_short_configs_dict = { "attr_names": ("C", "M", "N", "dtype", "device"), "attrs": ( diff --git a/benchmarks/operator_benchmark/pt/qpool_test.py b/benchmarks/operator_benchmark/pt/qpool_test.py index 5fc8ee3f9e8e..b2e1118ac890 100644 --- a/benchmarks/operator_benchmark/pt/qpool_test.py +++ b/benchmarks/operator_benchmark/pt/qpool_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch # 2D pooling will have input matrix of rank 3 or 4 qpool2d_long_configs = op_bench.config_list( diff --git a/benchmarks/operator_benchmark/pt/qrnn_test.py b/benchmarks/operator_benchmark/pt/qrnn_test.py index 56cab92f6008..5c4600683f76 100644 --- a/benchmarks/operator_benchmark/pt/qrnn_test.py +++ b/benchmarks/operator_benchmark/pt/qrnn_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch from torch import nn -import operator_benchmark as op_bench - """ Microbenchmarks for RNNs. """ diff --git a/benchmarks/operator_benchmark/pt/qtensor_method_test.py b/benchmarks/operator_benchmark/pt/qtensor_method_test.py index cc099c91c27d..3e545c36874e 100644 --- a/benchmarks/operator_benchmark/pt/qtensor_method_test.py +++ b/benchmarks/operator_benchmark/pt/qtensor_method_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch # Configs for pointwise and reduction unary ops qmethods_configs_short = op_bench.config_list( diff --git a/benchmarks/operator_benchmark/pt/quantization_test.py b/benchmarks/operator_benchmark/pt/quantization_test.py index b2bef9b2f1a3..73b0ef09dba9 100644 --- a/benchmarks/operator_benchmark/pt/quantization_test.py +++ b/benchmarks/operator_benchmark/pt/quantization_test.py @@ -1,10 +1,9 @@ +import operator_benchmark as op_bench import torch import torch.ao.nn.quantized as nnq import torch.ao.quantization as tq import torch.nn as nn -import operator_benchmark as op_bench - """Microbenchmarks for general quantization operations.""" # mode is used to show the direction of the benchmark: diff --git a/benchmarks/operator_benchmark/pt/qunary_test.py b/benchmarks/operator_benchmark/pt/qunary_test.py index 452c7d851f6c..f1f92cbf72cc 100644 --- a/benchmarks/operator_benchmark/pt/qunary_test.py +++ b/benchmarks/operator_benchmark/pt/qunary_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for quantized unary operators (point-wise and reduction).""" diff --git a/benchmarks/operator_benchmark/pt/remainder_test.py b/benchmarks/operator_benchmark/pt/remainder_test.py index be308ad4e917..7b069d4386b8 100644 --- a/benchmarks/operator_benchmark/pt/remainder_test.py +++ b/benchmarks/operator_benchmark/pt/remainder_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for remainder operators.""" diff --git a/benchmarks/operator_benchmark/pt/softmax_test.py b/benchmarks/operator_benchmark/pt/softmax_test.py index a7d3918f399a..d7c6e170f513 100644 --- a/benchmarks/operator_benchmark/pt/softmax_test.py +++ b/benchmarks/operator_benchmark/pt/softmax_test.py @@ -1,8 +1,7 @@ +import operator_benchmark as op_bench import torch import torch.nn as nn -import operator_benchmark as op_bench - """ Microbenchmarks for the softmax operators. diff --git a/benchmarks/operator_benchmark/pt/split_test.py b/benchmarks/operator_benchmark/pt/split_test.py index 23c875fe164d..74c388e42481 100644 --- a/benchmarks/operator_benchmark/pt/split_test.py +++ b/benchmarks/operator_benchmark/pt/split_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for Split operator""" diff --git a/benchmarks/operator_benchmark/pt/stack_test.py b/benchmarks/operator_benchmark/pt/stack_test.py index 222c478ca2b8..4ebe5b8c2929 100644 --- a/benchmarks/operator_benchmark/pt/stack_test.py +++ b/benchmarks/operator_benchmark/pt/stack_test.py @@ -1,10 +1,10 @@ import random from typing import List -import torch - import operator_benchmark as op_bench +import torch + """Microbenchmarks for Stack operator""" diff --git a/benchmarks/operator_benchmark/pt/sum_test.py b/benchmarks/operator_benchmark/pt/sum_test.py index 90198d8207eb..493c950569c5 100644 --- a/benchmarks/operator_benchmark/pt/sum_test.py +++ b/benchmarks/operator_benchmark/pt/sum_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for sum reduction operator.""" diff --git a/benchmarks/operator_benchmark/pt/tensor_to_test.py b/benchmarks/operator_benchmark/pt/tensor_to_test.py index b73058df9b82..dfd682e02463 100644 --- a/benchmarks/operator_benchmark/pt/tensor_to_test.py +++ b/benchmarks/operator_benchmark/pt/tensor_to_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch tensor_conversion_short_configs = op_bench.cross_product_configs( M=( diff --git a/benchmarks/operator_benchmark/pt/unary_test.py b/benchmarks/operator_benchmark/pt/unary_test.py index bc1257f7d2b1..a5f617fd50cf 100644 --- a/benchmarks/operator_benchmark/pt/unary_test.py +++ b/benchmarks/operator_benchmark/pt/unary_test.py @@ -1,6 +1,5 @@ -import torch - import operator_benchmark as op_bench +import torch """Microbenchmarks for point-wise unary operator.""" diff --git a/benchmarks/operator_benchmark/pt_extension/cpp_extension_test.py b/benchmarks/operator_benchmark/pt_extension/cpp_extension_test.py index 2b20dc4ff661..25c1818b42bc 100644 --- a/benchmarks/operator_benchmark/pt_extension/cpp_extension_test.py +++ b/benchmarks/operator_benchmark/pt_extension/cpp_extension_test.py @@ -1,6 +1,7 @@ import unittest import benchmark_cpp_extension # noqa: F401 + import torch diff --git a/benchmarks/operator_benchmark/pt_extension/setup.py b/benchmarks/operator_benchmark/pt_extension/setup.py index 52492075f845..53db50f4436c 100644 --- a/benchmarks/operator_benchmark/pt_extension/setup.py +++ b/benchmarks/operator_benchmark/pt_extension/setup.py @@ -1,4 +1,5 @@ from setuptools import setup + from torch.utils.cpp_extension import BuildExtension, CppExtension setup( diff --git a/benchmarks/overrides_benchmark/bench.py b/benchmarks/overrides_benchmark/bench.py index 93c7f1b130d4..72dcf89bedb5 100644 --- a/benchmarks/overrides_benchmark/bench.py +++ b/benchmarks/overrides_benchmark/bench.py @@ -1,10 +1,10 @@ import argparse import time -import torch - from common import SubTensor, SubWithTorchFunction, WithTorchFunction +import torch + NUM_REPEATS = 1000 NUM_REPEAT_OF_REPEATS = 1000 diff --git a/benchmarks/overrides_benchmark/pyspybench.py b/benchmarks/overrides_benchmark/pyspybench.py index 66e20c494d13..69745162dfef 100644 --- a/benchmarks/overrides_benchmark/pyspybench.py +++ b/benchmarks/overrides_benchmark/pyspybench.py @@ -1,8 +1,9 @@ import argparse -import torch from common import SubTensor, SubWithTorchFunction, WithTorchFunction # noqa: F401 +import torch + Tensor = torch.tensor NUM_REPEATS = 1000000 diff --git a/benchmarks/profiler_benchmark/resnet_memory_profiler.py b/benchmarks/profiler_benchmark/resnet_memory_profiler.py index eafb8a0c8b9a..85212b982180 100644 --- a/benchmarks/profiler_benchmark/resnet_memory_profiler.py +++ b/benchmarks/profiler_benchmark/resnet_memory_profiler.py @@ -1,7 +1,8 @@ +import torchvision.models as models + import torch import torch.autograd.profiler as profiler -import torchvision.models as models for with_cuda in [False, True]: model = models.resnet18() diff --git a/benchmarks/serialization/simple_measurement.py b/benchmarks/serialization/simple_measurement.py index 9c7705f82fe8..9cc12ca13292 100644 --- a/benchmarks/serialization/simple_measurement.py +++ b/benchmarks/serialization/simple_measurement.py @@ -1,6 +1,7 @@ -import torch from pyarkbench import Benchmark, default_args, Timer +import torch + use_new = True diff --git a/benchmarks/sparse/benchmark_semi_structured_sparsity.py b/benchmarks/sparse/benchmark_semi_structured_sparsity.py index 59aa63915883..66311c40428f 100644 --- a/benchmarks/sparse/benchmark_semi_structured_sparsity.py +++ b/benchmarks/sparse/benchmark_semi_structured_sparsity.py @@ -2,11 +2,12 @@ import argparse import random import pandas as pd +from tqdm import tqdm + import torch import torch.utils.benchmark as benchmark from torch import nn from torch.sparse import SparseSemiStructuredTensor, to_sparse_semi_structured -from tqdm import tqdm torch.set_printoptions( diff --git a/benchmarks/sparse/dlmc/matmul_bench.py b/benchmarks/sparse/dlmc/matmul_bench.py index 889125a8c44a..07a712c9baae 100644 --- a/benchmarks/sparse/dlmc/matmul_bench.py +++ b/benchmarks/sparse/dlmc/matmul_bench.py @@ -9,9 +9,10 @@ import argparse import os import sys +from scipy.sparse import isspmatrix + import torch import torch.utils.benchmark as benchmark_utils -from scipy.sparse import isspmatrix from .utils import load_dlmc_dataset diff --git a/benchmarks/sparse/dlmc/utils.py b/benchmarks/sparse/dlmc/utils.py index d07a79b15e17..196b74cd4c11 100644 --- a/benchmarks/sparse/dlmc/utils.py +++ b/benchmarks/sparse/dlmc/utils.py @@ -1,9 +1,10 @@ import math from pathlib import Path -import torch from scipy import sparse +import torch + def to_coo_scipy(x): indices_1 = x._indices().numpy() diff --git a/benchmarks/sparse/spmm.py b/benchmarks/sparse/spmm.py index 166ced09c9c9..b707556dd7a1 100644 --- a/benchmarks/sparse/spmm.py +++ b/benchmarks/sparse/spmm.py @@ -1,9 +1,10 @@ import argparse import sys -import torch from utils import Event, gen_sparse_coo, gen_sparse_coo_and_csr, gen_sparse_csr +import torch + def test_sparse_csr(m, n, k, nnz, test_count): start_timer = Event(enable_timing=True) diff --git a/benchmarks/sparse/triton_ops.py b/benchmarks/sparse/triton_ops.py index d1f856b7df41..66522694d0ad 100644 --- a/benchmarks/sparse/triton_ops.py +++ b/benchmarks/sparse/triton_ops.py @@ -125,6 +125,7 @@ if __name__ == "__main__": import sys import triton + from torch.testing import make_tensor torch.manual_seed(0) diff --git a/benchmarks/sparse/utils.py b/benchmarks/sparse/utils.py index 97e2ee48f065..a1f695d7065c 100644 --- a/benchmarks/sparse/utils.py +++ b/benchmarks/sparse/utils.py @@ -4,6 +4,7 @@ import random import time import numpy as np + import torch diff --git a/benchmarks/tensorexpr/benchmark.py b/benchmarks/tensorexpr/benchmark.py index d6fa1485436e..38951ac5091f 100644 --- a/benchmarks/tensorexpr/benchmark.py +++ b/benchmarks/tensorexpr/benchmark.py @@ -4,6 +4,7 @@ import os import time import numpy as np + import torch from . import tensor_engine diff --git a/benchmarks/tensorexpr/broadcast.py b/benchmarks/tensorexpr/broadcast.py index 2401416c5cdb..7350460476ec 100644 --- a/benchmarks/tensorexpr/broadcast.py +++ b/benchmarks/tensorexpr/broadcast.py @@ -2,6 +2,7 @@ import itertools import operator import numpy as np + import torch from . import benchmark diff --git a/benchmarks/tensorexpr/concat.py b/benchmarks/tensorexpr/concat.py index 795045221a66..568764afad2e 100644 --- a/benchmarks/tensorexpr/concat.py +++ b/benchmarks/tensorexpr/concat.py @@ -1,4 +1,5 @@ import numpy as np + import torch from . import benchmark diff --git a/benchmarks/tensorexpr/elementwise.py b/benchmarks/tensorexpr/elementwise.py index eee6ef621fd6..5ea4d503e4fd 100644 --- a/benchmarks/tensorexpr/elementwise.py +++ b/benchmarks/tensorexpr/elementwise.py @@ -3,6 +3,7 @@ import operator import numpy as np import scipy.special + import torch from . import benchmark diff --git a/benchmarks/tensorexpr/microbenchmarks.py b/benchmarks/tensorexpr/microbenchmarks.py index 6177502f7f4c..7716aeb6bf12 100644 --- a/benchmarks/tensorexpr/microbenchmarks.py +++ b/benchmarks/tensorexpr/microbenchmarks.py @@ -6,6 +6,7 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns + import torch import torch._C._te as te diff --git a/benchmarks/transformer/attention_bias_benchmarks.py b/benchmarks/transformer/attention_bias_benchmarks.py index fbe57b540dc2..fbcf06955527 100644 --- a/benchmarks/transformer/attention_bias_benchmarks.py +++ b/benchmarks/transformer/attention_bias_benchmarks.py @@ -4,14 +4,15 @@ from functools import partial from typing import Callable, List, Union import numpy as np +from tabulate import tabulate +from tqdm import tqdm + import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.benchmark as benchmark -from tabulate import tabulate from torch.nn.attention.bias import CausalBias, CausalVariant from torch.nn.parameter import Parameter -from tqdm import tqdm def benchmark_torch_function_in_microseconds(func: Callable, *args, **kwargs) -> float: diff --git a/benchmarks/transformer/better_transformer_vs_mha_functional.py b/benchmarks/transformer/better_transformer_vs_mha_functional.py index 71be7db4562a..44e8105ef1e9 100644 --- a/benchmarks/transformer/better_transformer_vs_mha_functional.py +++ b/benchmarks/transformer/better_transformer_vs_mha_functional.py @@ -20,11 +20,12 @@ from pprint import pprint from typing import Optional import numpy as np -import torch from prettytable import PrettyTable from tqdm import tqdm +import torch + warnings.filterwarnings("ignore") error_dict = defaultdict(int) diff --git a/benchmarks/transformer/score_mod.py b/benchmarks/transformer/score_mod.py index 57088c45f8a0..29d951bc1dee 100644 --- a/benchmarks/transformer/score_mod.py +++ b/benchmarks/transformer/score_mod.py @@ -6,11 +6,12 @@ from functools import partial from typing import Callable, List, Optional, Tuple import numpy as np +from tabulate import tabulate +from tqdm import tqdm + import torch import torch.nn.functional as F -from tabulate import tabulate from torch.nn.attention._flex_attention import _flex_attention -from tqdm import tqdm torch._dynamo.config.automatic_dynamic_shapes = False # Needed since changing args to function causes recompiles diff --git a/benchmarks/transformer/sdp.py b/benchmarks/transformer/sdp.py index c79ab8358bdc..eacf6cf0f00d 100644 --- a/benchmarks/transformer/sdp.py +++ b/benchmarks/transformer/sdp.py @@ -9,11 +9,12 @@ from pprint import pprint from typing import List, Optional import numpy as np +from prettytable import PrettyTable +from tqdm import tqdm + import torch import torch.utils.benchmark as benchmark -from prettytable import PrettyTable from torch.backends.cuda import sdp_kernel -from tqdm import tqdm warnings.filterwarnings("ignore") diff --git a/benchmarks/transformer/sdpa.py b/benchmarks/transformer/sdpa.py index 6492561b6a91..d45970213e01 100644 --- a/benchmarks/transformer/sdpa.py +++ b/benchmarks/transformer/sdpa.py @@ -4,12 +4,13 @@ from contextlib import nullcontext from dataclasses import asdict, dataclass from typing import Callable, List, Tuple +from tabulate import tabulate +from tqdm import tqdm + import torch import torch.utils.benchmark as benchmark -from tabulate import tabulate from torch.nn.attention import sdpa_kernel, SDPBackend from torch.nn.functional import scaled_dot_product_attention -from tqdm import tqdm def benchmark_torch_function_in_microseconds(func: Callable, *args, **kwargs) -> float: diff --git a/docs/source/scripts/build_activation_images.py b/docs/source/scripts/build_activation_images.py index 2a91d929899a..21e27a0ca1a4 100644 --- a/docs/source/scripts/build_activation_images.py +++ b/docs/source/scripts/build_activation_images.py @@ -7,9 +7,9 @@ online tutorials. from pathlib import Path import matplotlib +from matplotlib import pyplot as plt import torch -from matplotlib import pyplot as plt matplotlib.use("Agg") diff --git a/functorch/benchmarks/cse.py b/functorch/benchmarks/cse.py index af21a3432cde..3bf5ab11514c 100644 --- a/functorch/benchmarks/cse.py +++ b/functorch/benchmarks/cse.py @@ -1,11 +1,11 @@ import torch import torch.fx as fx +from functorch import make_fx + from torch._functorch.compile_utils import fx_graph_cse from torch.profiler import profile, ProfilerActivity -from functorch import make_fx - def profile_it(f, inp): for _ in range(5): diff --git a/functorch/benchmarks/operator_authoring.py b/functorch/benchmarks/operator_authoring.py index f5f77071b930..975311a67c56 100644 --- a/functorch/benchmarks/operator_authoring.py +++ b/functorch/benchmarks/operator_authoring.py @@ -3,6 +3,7 @@ from functools import partial import numpy as np import pandas as pd + import torch from functorch.compile import pointwise_operator diff --git a/functorch/benchmarks/per_sample_grads.py b/functorch/benchmarks/per_sample_grads.py index 73c1e3e2ef8a..7eb99096ec72 100644 --- a/functorch/benchmarks/per_sample_grads.py +++ b/functorch/benchmarks/per_sample_grads.py @@ -1,11 +1,12 @@ import time -import torch -import torch.nn as nn import torchvision.models as models from opacus import PrivacyEngine from opacus.utils.module_modification import convert_batchnorm_modules +import torch +import torch.nn as nn + from functorch import grad, make_functional, vmap device = "cuda" diff --git a/functorch/dim/__init__.py b/functorch/dim/__init__.py index 519a7cb271cd..2413ed331fb2 100644 --- a/functorch/dim/__init__.py +++ b/functorch/dim/__init__.py @@ -2,9 +2,9 @@ import dis import inspect from typing import Sequence, Union -import torch - import functorch._C + +import torch from functorch._C import dim as _C from .tree_map import tree_flatten, tree_map from .wrap_type import wrap_type diff --git a/functorch/examples/dp_cifar10/cifar10_opacus.py b/functorch/examples/dp_cifar10/cifar10_opacus.py index bd8239b187e6..236763ac3171 100644 --- a/functorch/examples/dp_cifar10/cifar10_opacus.py +++ b/functorch/examples/dp_cifar10/cifar10_opacus.py @@ -12,16 +12,17 @@ import sys from datetime import datetime, timedelta import numpy as np -import torch -import torch.nn as nn -import torch.optim as optim -import torch.utils.data import torchvision.transforms as transforms from opacus import PrivacyEngine from torchvision import models from torchvision.datasets import CIFAR10 from tqdm import tqdm +import torch +import torch.nn as nn +import torch.optim as optim +import torch.utils.data + logging.basicConfig( format="%(asctime)s:%(levelname)s:%(message)s", diff --git a/functorch/examples/dp_cifar10/cifar10_transforms.py b/functorch/examples/dp_cifar10/cifar10_transforms.py index bbab7f46b5e2..786031bce9b8 100644 --- a/functorch/examples/dp_cifar10/cifar10_transforms.py +++ b/functorch/examples/dp_cifar10/cifar10_transforms.py @@ -12,16 +12,17 @@ import sys from datetime import datetime, timedelta import numpy as np +import torchvision.transforms as transforms +from torchvision import models +from torchvision.datasets import CIFAR10 +from tqdm import tqdm + import torch import torch.nn as nn import torch.optim as optim import torch.utils.data -import torchvision.transforms as transforms from torch.func import functional_call, grad_and_value, vmap -from torchvision import models -from torchvision.datasets import CIFAR10 -from tqdm import tqdm logging.basicConfig( format="%(asctime)s:%(levelname)s:%(message)s", diff --git a/functorch/examples/maml_omniglot/maml-omniglot-higher.py b/functorch/examples/maml_omniglot/maml-omniglot-higher.py index fa38fd616ee3..db058e1f6211 100755 --- a/functorch/examples/maml_omniglot/maml-omniglot-higher.py +++ b/functorch/examples/maml_omniglot/maml-omniglot-higher.py @@ -36,10 +36,11 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd +from support.omniglot_loaders import OmniglotNShot + import torch import torch.nn.functional as F import torch.optim as optim -from support.omniglot_loaders import OmniglotNShot from torch import nn mpl.use("Agg") diff --git a/functorch/examples/maml_omniglot/maml-omniglot-ptonly.py b/functorch/examples/maml_omniglot/maml-omniglot-ptonly.py index 4145cf86240d..436d11d15912 100755 --- a/functorch/examples/maml_omniglot/maml-omniglot-ptonly.py +++ b/functorch/examples/maml_omniglot/maml-omniglot-ptonly.py @@ -35,13 +35,14 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd +from support.omniglot_loaders import OmniglotNShot + import torch import torch.nn.functional as F import torch.optim as optim -from support.omniglot_loaders import OmniglotNShot -from torch import nn from functorch import make_functional_with_buffers +from torch import nn mpl.use("Agg") plt.style.use("bmh") diff --git a/functorch/examples/maml_omniglot/maml-omniglot-transforms.py b/functorch/examples/maml_omniglot/maml-omniglot-transforms.py index ba55e5804788..2a7c1b95fb0c 100755 --- a/functorch/examples/maml_omniglot/maml-omniglot-transforms.py +++ b/functorch/examples/maml_omniglot/maml-omniglot-transforms.py @@ -36,10 +36,11 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd +from support.omniglot_loaders import OmniglotNShot + import torch import torch.nn.functional as F import torch.optim as optim -from support.omniglot_loaders import OmniglotNShot from torch import nn from torch.func import functional_call, grad, vmap diff --git a/functorch/examples/maml_omniglot/support/omniglot_loaders.py b/functorch/examples/maml_omniglot/support/omniglot_loaders.py index 5d7f6421bbb4..7e54d3584a87 100644 --- a/functorch/examples/maml_omniglot/support/omniglot_loaders.py +++ b/functorch/examples/maml_omniglot/support/omniglot_loaders.py @@ -22,11 +22,11 @@ import os import os.path import numpy as np +import torchvision.transforms as transforms +from PIL import Image import torch import torch.utils.data as data -import torchvision.transforms as transforms -from PIL import Image class Omniglot(data.Dataset): diff --git a/functorch/examples/maml_regression/evjang.py b/functorch/examples/maml_regression/evjang.py index cd0ee575c495..423aaab1e169 100644 --- a/functorch/examples/maml_regression/evjang.py +++ b/functorch/examples/maml_regression/evjang.py @@ -7,6 +7,7 @@ import math import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np + import torch from torch.nn import functional as F diff --git a/functorch/examples/maml_regression/evjang_transforms.py b/functorch/examples/maml_regression/evjang_transforms.py index c70fe5e1cde9..92a8fbcdbf55 100644 --- a/functorch/examples/maml_regression/evjang_transforms.py +++ b/functorch/examples/maml_regression/evjang_transforms.py @@ -7,6 +7,7 @@ import math import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np + import torch from torch.func import grad, vmap from torch.nn import functional as F diff --git a/functorch/examples/maml_regression/evjang_transforms_module.py b/functorch/examples/maml_regression/evjang_transforms_module.py index b4c71ed19d8e..e2b8c548282e 100644 --- a/functorch/examples/maml_regression/evjang_transforms_module.py +++ b/functorch/examples/maml_regression/evjang_transforms_module.py @@ -7,11 +7,12 @@ import math import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np + import torch -from torch import nn -from torch.nn import functional as F from functorch import grad, make_functional, vmap +from torch import nn +from torch.nn import functional as F mpl.use("Agg") diff --git a/functorch/experimental/__init__.py b/functorch/experimental/__init__.py index 23fc8381cc23..3941f6d96e1f 100644 --- a/functorch/experimental/__init__.py +++ b/functorch/experimental/__init__.py @@ -1,6 +1,5 @@ # PyTorch forward-mode is not mature yet +from functorch import functionalize from torch._functorch.apis import chunk_vmap from torch._functorch.batch_norm_replacement import replace_all_batch_norm_modules_ from torch._functorch.eager_transforms import hessian, jacfwd, jvp - -from functorch import functionalize diff --git a/functorch/op_analysis/gen_data.py b/functorch/op_analysis/gen_data.py index 23672071cd97..4fda25f9a4e2 100644 --- a/functorch/op_analysis/gen_data.py +++ b/functorch/op_analysis/gen_data.py @@ -1,9 +1,10 @@ import csv from collections import defaultdict -import torch import yaml +import torch + def get_ops_for_key(key): # Needs modified PyTorch C++ code to work diff --git a/ios/TestApp/benchmark/coreml_backend.py b/ios/TestApp/benchmark/coreml_backend.py index 3bfee6bad0eb..7b2473637ccf 100644 --- a/ios/TestApp/benchmark/coreml_backend.py +++ b/ios/TestApp/benchmark/coreml_backend.py @@ -1,7 +1,8 @@ +from torchvision import models + import torch from torch.backends._coreml.preprocess import CompileSpec, CoreMLComputeUnit, TensorSpec -from torchvision import models def mobilenetv2_spec(): diff --git a/ios/TestApp/benchmark/trace_model.py b/ios/TestApp/benchmark/trace_model.py index 24af8d383348..8614f396c764 100644 --- a/ios/TestApp/benchmark/trace_model.py +++ b/ios/TestApp/benchmark/trace_model.py @@ -1,6 +1,7 @@ +from torchvision import models + import torch from torch.utils.mobile_optimizer import optimize_for_mobile -from torchvision import models model = models.mobilenet_v2(weights=models.MobileNet_V2_Weights.IMAGENET1K_V1) model.eval() diff --git a/ios/TestApp/custom_build/custom_build.py b/ios/TestApp/custom_build/custom_build.py index de4335d58cb6..c07a66aeda3f 100644 --- a/ios/TestApp/custom_build/custom_build.py +++ b/ios/TestApp/custom_build/custom_build.py @@ -1,7 +1,8 @@ -import torch import yaml from torchvision import models +import torch + model = models.mobilenet_v2(weights=models.MobileNet_V2_Weights.IMAGENET1K_V1) model.eval() example = torch.rand(1, 3, 224, 224) diff --git a/pyproject.toml b/pyproject.toml index f11314c7268f..8091c2650a83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,12 +34,9 @@ include_trailing_comma = true [tool.usort.known] -first_party = ["caffe2", "torchgen", "functorch", "test"] +first_party = ["caffe2", "torch", "torchgen", "functorch", "test"] standard_library = ["typing_extensions"] -[tool.usort.kown] -first_party = ["torch"] - [tool.ruff] target-version = "py38" diff --git a/scripts/export/update_schema.py b/scripts/export/update_schema.py index dff24c83bd8f..674e409a7347 100644 --- a/scripts/export/update_schema.py +++ b/scripts/export/update_schema.py @@ -1,9 +1,10 @@ import argparse import os -from torch._export.serde import schema_check from yaml import dump, Dumper +from torch._export.serde import schema_check + if __name__ == "__main__": parser = argparse.ArgumentParser(prog="update_schema") parser.add_argument( diff --git a/scripts/release_notes/categorize.py b/scripts/release_notes/categorize.py index 0187637e7b84..6ef0e0c199f7 100644 --- a/scripts/release_notes/categorize.py +++ b/scripts/release_notes/categorize.py @@ -4,7 +4,6 @@ import textwrap from pathlib import Path import common -import torch # Imports for working with classi from classifier import ( @@ -18,6 +17,8 @@ from classifier import ( from commitlist import CommitList from common import get_commit_data_cache, topics +import torch + class Categorizer: def __init__(self, path, category="Uncategorized", use_classifier: bool = False): diff --git a/scripts/release_notes/classifier.py b/scripts/release_notes/classifier.py index 6c0a9a02f8bc..c64bad818e4e 100644 --- a/scripts/release_notes/classifier.py +++ b/scripts/release_notes/classifier.py @@ -9,12 +9,13 @@ from typing import Dict, List import common import pandas as pd -import torch -import torch.nn as nn import torchtext from torchtext.functional import to_tensor from tqdm import tqdm +import torch +import torch.nn as nn + XLMR_BASE = torchtext.models.XLMR_BASE_ENCODER # This should not be here but it works for now diff --git a/test/cpp_extensions/no_python_abi_suffix_test/setup.py b/test/cpp_extensions/no_python_abi_suffix_test/setup.py index 9b39cd5723c1..69a49f0e56dc 100644 --- a/test/cpp_extensions/no_python_abi_suffix_test/setup.py +++ b/test/cpp_extensions/no_python_abi_suffix_test/setup.py @@ -1,4 +1,5 @@ from setuptools import setup + from torch.utils.cpp_extension import BuildExtension, CppExtension setup( diff --git a/test/cpp_extensions/setup.py b/test/cpp_extensions/setup.py index 4d4288a3076f..e0f1f858e884 100644 --- a/test/cpp_extensions/setup.py +++ b/test/cpp_extensions/setup.py @@ -1,8 +1,9 @@ import os import sys -import torch.cuda from setuptools import setup + +import torch.cuda from torch.testing._internal.common_utils import IS_WINDOWS from torch.utils.cpp_extension import ( BuildExtension, diff --git a/test/custom_backend/test_custom_backend.py b/test/custom_backend/test_custom_backend.py index 7b3d300d0342..5faf5fa94d5a 100644 --- a/test/custom_backend/test_custom_backend.py +++ b/test/custom_backend/test_custom_backend.py @@ -3,9 +3,9 @@ import os import tempfile -import torch - from backend import get_custom_backend_library_path, Model, to_custom_backend + +import torch from torch.testing._internal.common_utils import run_tests, TestCase diff --git a/test/custom_operator/my_custom_ops.py b/test/custom_operator/my_custom_ops.py index 6fff63e5fcf6..e9928f93ceb8 100644 --- a/test/custom_operator/my_custom_ops.py +++ b/test/custom_operator/my_custom_ops.py @@ -1,6 +1,7 @@ -import torch from model import get_custom_op_library_path +import torch + torch.ops.load_library(get_custom_op_library_path()) diff --git a/test/custom_operator/my_custom_ops2.py b/test/custom_operator/my_custom_ops2.py index 8a9db6e59b75..f92ab415134c 100644 --- a/test/custom_operator/my_custom_ops2.py +++ b/test/custom_operator/my_custom_ops2.py @@ -1,6 +1,7 @@ -import torch from model import get_custom_op_library_path +import torch + torch.ops.load_library(get_custom_op_library_path()) diff --git a/test/custom_operator/pointwise.py b/test/custom_operator/pointwise.py index 534aa0733a90..1a26bc7385ff 100644 --- a/test/custom_operator/pointwise.py +++ b/test/custom_operator/pointwise.py @@ -1,6 +1,7 @@ -import torch from model import get_custom_op_library_path +import torch + torch.ops.load_library(get_custom_op_library_path()) diff --git a/test/custom_operator/test_custom_ops.py b/test/custom_operator/test_custom_ops.py index 1b490c49e9ca..26f4bfc62f1d 100644 --- a/test/custom_operator/test_custom_ops.py +++ b/test/custom_operator/test_custom_ops.py @@ -5,10 +5,10 @@ import sys import tempfile import unittest +from model import get_custom_op_library_path, Model + import torch import torch._library.utils as utils - -from model import get_custom_op_library_path, Model from torch import ops from torch.testing._internal.common_utils import IS_WINDOWS, run_tests, TestCase diff --git a/test/distributed/_tensor/test_dtensor.py b/test/distributed/_tensor/test_dtensor.py index e2a9d33241e7..70a67b8e0b93 100644 --- a/test/distributed/_tensor/test_dtensor.py +++ b/test/distributed/_tensor/test_dtensor.py @@ -1,9 +1,10 @@ # Copyright (c) Meta Platforms, Inc. and affiliates # Owner(s): ["oncall: distributed"] +from numpy.testing import assert_array_equal + import torch import torch.nn.functional as F -from numpy.testing import assert_array_equal from torch.distributed._functional_collectives import AsyncCollectiveTensor from torch.distributed._tensor import ( diff --git a/test/distributed/_tensor/test_dtensor_compile.py b/test/distributed/_tensor/test_dtensor_compile.py index fb89b9908b86..f40cb4999858 100644 --- a/test/distributed/_tensor/test_dtensor_compile.py +++ b/test/distributed/_tensor/test_dtensor_compile.py @@ -70,9 +70,8 @@ bw_graph_cell = [None] fw_compiler = functools.partial(extract_graph, graph_cell=fw_graph_cell) bw_compiler = functools.partial(extract_graph, graph_cell=bw_graph_cell) -from torch._dynamo.backends.common import aot_autograd - from functorch.compile import min_cut_rematerialization_partition +from torch._dynamo.backends.common import aot_autograd aot_eager_graph = aot_autograd( fw_compiler=fw_compiler, diff --git a/test/distributed/_tensor/test_xla_integration.py b/test/distributed/_tensor/test_xla_integration.py index 682d10250f4c..f2fa0c6dd961 100644 --- a/test/distributed/_tensor/test_xla_integration.py +++ b/test/distributed/_tensor/test_xla_integration.py @@ -7,6 +7,7 @@ from functools import wraps from typing import Any, Callable, Dict, Tuple import numpy as np + import torch from torch import nn from torch.distributed._tensor import ( diff --git a/test/distributed/elastic/rendezvous/etcd_server_test.py b/test/distributed/elastic/rendezvous/etcd_server_test.py index 6e21948a38a6..05db3045d097 100644 --- a/test/distributed/elastic/rendezvous/etcd_server_test.py +++ b/test/distributed/elastic/rendezvous/etcd_server_test.py @@ -10,6 +10,7 @@ import sys import unittest import etcd + from torch.distributed.elastic.rendezvous.etcd_rendezvous import ( EtcdRendezvous, EtcdRendezvousHandler, diff --git a/test/distributed/pipeline/sync/skip/test_gpipe.py b/test/distributed/pipeline/sync/skip/test_gpipe.py index e002d65db7ff..4f433ab38941 100644 --- a/test/distributed/pipeline/sync/skip/test_gpipe.py +++ b/test/distributed/pipeline/sync/skip/test_gpipe.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch from torch import nn diff --git a/test/distributed/pipeline/sync/skip/test_leak.py b/test/distributed/pipeline/sync/skip/test_leak.py index 2bf797dae559..f4d1043e0549 100644 --- a/test/distributed/pipeline/sync/skip/test_leak.py +++ b/test/distributed/pipeline/sync/skip/test_leak.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch from torch import nn diff --git a/test/distributed/pipeline/sync/skip/test_portal.py b/test/distributed/pipeline/sync/skip/test_portal.py index e50b5e1059b8..5ad180b6f9c8 100644 --- a/test/distributed/pipeline/sync/skip/test_portal.py +++ b/test/distributed/pipeline/sync/skip/test_portal.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch from torch.distributed.pipeline.sync.dependency import fork, join diff --git a/test/distributed/pipeline/sync/skip/test_stash_pop.py b/test/distributed/pipeline/sync/skip/test_stash_pop.py index e67cfd47bd92..5d273860f6a6 100644 --- a/test/distributed/pipeline/sync/skip/test_stash_pop.py +++ b/test/distributed/pipeline/sync/skip/test_stash_pop.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch from torch import nn diff --git a/test/distributed/pipeline/sync/skip/test_tracker.py b/test/distributed/pipeline/sync/skip/test_tracker.py index 007a5a963a7c..9c3a970f7574 100644 --- a/test/distributed/pipeline/sync/skip/test_tracker.py +++ b/test/distributed/pipeline/sync/skip/test_tracker.py @@ -10,6 +10,7 @@ import threading from queue import Queue import pytest + import torch from torch import nn diff --git a/test/distributed/pipeline/sync/skip/test_verify_skippables.py b/test/distributed/pipeline/sync/skip/test_verify_skippables.py index 265c3fee85f9..1d5941487da8 100644 --- a/test/distributed/pipeline/sync/skip/test_verify_skippables.py +++ b/test/distributed/pipeline/sync/skip/test_verify_skippables.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + from torch import nn from torch.distributed.pipeline.sync.skip import Namespace, skippable, verify_skippables diff --git a/test/distributed/pipeline/sync/test_balance.py b/test/distributed/pipeline/sync/test_balance.py index 82af7545bb0f..faf09f4581ae 100644 --- a/test/distributed/pipeline/sync/test_balance.py +++ b/test/distributed/pipeline/sync/test_balance.py @@ -9,6 +9,7 @@ import time import pytest + import torch from torch import nn diff --git a/test/distributed/pipeline/sync/test_bugs.py b/test/distributed/pipeline/sync/test_bugs.py index 1cb981c6a468..928a78db6e32 100644 --- a/test/distributed/pipeline/sync/test_bugs.py +++ b/test/distributed/pipeline/sync/test_bugs.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch import torch.nn.functional as F from torch import nn diff --git a/test/distributed/pipeline/sync/test_checkpoint.py b/test/distributed/pipeline/sync/test_checkpoint.py index e1ae6f6754ec..7be8ddefafe9 100644 --- a/test/distributed/pipeline/sync/test_checkpoint.py +++ b/test/distributed/pipeline/sync/test_checkpoint.py @@ -9,6 +9,7 @@ from functools import partial import pytest + import torch import torch.cuda from torch import nn diff --git a/test/distributed/pipeline/sync/test_copy.py b/test/distributed/pipeline/sync/test_copy.py index 22a3a37805f2..302c3d25d53f 100644 --- a/test/distributed/pipeline/sync/test_copy.py +++ b/test/distributed/pipeline/sync/test_copy.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch from torch.distributed.pipeline.sync.copy import Copy, Wait diff --git a/test/distributed/pipeline/sync/test_deferred_batch_norm.py b/test/distributed/pipeline/sync/test_deferred_batch_norm.py index 2fea96e7ddb6..c3807c57d612 100644 --- a/test/distributed/pipeline/sync/test_deferred_batch_norm.py +++ b/test/distributed/pipeline/sync/test_deferred_batch_norm.py @@ -10,6 +10,7 @@ from copy import deepcopy from itertools import chain import pytest + import torch from torch import nn, optim diff --git a/test/distributed/pipeline/sync/test_dependency.py b/test/distributed/pipeline/sync/test_dependency.py index 73283b88abb2..e966d6541bf5 100644 --- a/test/distributed/pipeline/sync/test_dependency.py +++ b/test/distributed/pipeline/sync/test_dependency.py @@ -9,6 +9,7 @@ import weakref import pytest + import torch from torch.distributed.pipeline.sync.dependency import Fork, fork, Join, join diff --git a/test/distributed/pipeline/sync/test_inplace.py b/test/distributed/pipeline/sync/test_inplace.py index eade0f43e1bd..33f31b2a52bb 100644 --- a/test/distributed/pipeline/sync/test_inplace.py +++ b/test/distributed/pipeline/sync/test_inplace.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch from torch import nn diff --git a/test/distributed/pipeline/sync/test_microbatch.py b/test/distributed/pipeline/sync/test_microbatch.py index 89d7a8b995b7..b5e44aa73a8d 100644 --- a/test/distributed/pipeline/sync/test_microbatch.py +++ b/test/distributed/pipeline/sync/test_microbatch.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch import torch.cuda diff --git a/test/distributed/pipeline/sync/test_pipe.py b/test/distributed/pipeline/sync/test_pipe.py index 848a3ed7eb90..e493b1d5a03e 100644 --- a/test/distributed/pipeline/sync/test_pipe.py +++ b/test/distributed/pipeline/sync/test_pipe.py @@ -12,6 +12,7 @@ from collections import OrderedDict from copy import deepcopy import pytest + import torch from torch import nn, Tensor diff --git a/test/distributed/pipeline/sync/test_stream.py b/test/distributed/pipeline/sync/test_stream.py index 29281ca606d8..f9702c8e4152 100644 --- a/test/distributed/pipeline/sync/test_stream.py +++ b/test/distributed/pipeline/sync/test_stream.py @@ -7,6 +7,7 @@ # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import pytest + import torch from torch.distributed.pipeline.sync.stream import ( diff --git a/test/distributed/pipeline/sync/test_worker.py b/test/distributed/pipeline/sync/test_worker.py index ca5d99c57638..f82af2ea0067 100644 --- a/test/distributed/pipeline/sync/test_worker.py +++ b/test/distributed/pipeline/sync/test_worker.py @@ -9,6 +9,7 @@ import threading import pytest + import torch from torch.distributed.pipeline.sync.microbatch import Batch diff --git a/test/distributed/pipelining/test_backward.py b/test/distributed/pipelining/test_backward.py index 5791f40c6102..083fd12d5820 100644 --- a/test/distributed/pipelining/test_backward.py +++ b/test/distributed/pipelining/test_backward.py @@ -2,9 +2,9 @@ # Owner(s): ["oncall: distributed"] import copy -import torch - from model_registry import MLPModule + +import torch from torch.distributed.pipelining._backward import stage_backward from torch.testing._internal.common_utils import run_tests, TestCase diff --git a/test/distributed/pipelining/test_composability.py b/test/distributed/pipelining/test_composability.py index 941d86e576e1..bbf3f1929fbc 100644 --- a/test/distributed/pipelining/test_composability.py +++ b/test/distributed/pipelining/test_composability.py @@ -5,10 +5,11 @@ import os import sys import tempfile +from model_registry import MLPModule + import torch import torch.distributed as dist import torch.nn as nn -from model_registry import MLPModule from torch.distributed._composable.fsdp.fully_shard import ( fully_shard, MixedPrecisionPolicy, diff --git a/test/distributed/pipelining/test_pipe.py b/test/distributed/pipelining/test_pipe.py index 74d13111bec7..b7ef10ebad5b 100644 --- a/test/distributed/pipelining/test_pipe.py +++ b/test/distributed/pipelining/test_pipe.py @@ -1,8 +1,8 @@ # Copyright (c) Meta Platforms, Inc. and affiliates # Owner(s): ["oncall: distributed"] -import torch - from model_registry import MLPModule + +import torch from torch.distributed.pipelining import pipe_split, pipeline from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, diff --git a/test/distributed/pipelining/test_schedule.py b/test/distributed/pipelining/test_schedule.py index 42bb7eaf9fdc..232f69d8bcef 100644 --- a/test/distributed/pipelining/test_schedule.py +++ b/test/distributed/pipelining/test_schedule.py @@ -5,10 +5,10 @@ import os import sys import tempfile +from model_registry import ModelWithKwargs, MultiMLP + import torch import torch.distributed as dist - -from model_registry import ModelWithKwargs, MultiMLP from torch.distributed.pipelining import ( ManualPipelineStage, pipeline, diff --git a/test/distributed/pipelining/test_stage.py b/test/distributed/pipelining/test_stage.py index a7c1f51b3da9..97a147cb357a 100644 --- a/test/distributed/pipelining/test_stage.py +++ b/test/distributed/pipelining/test_stage.py @@ -4,10 +4,10 @@ import os import sys import tempfile +from model_registry import ExampleCode, ModelWithKwargs, MultiMLP + import torch import torch.distributed as dist - -from model_registry import ExampleCode, ModelWithKwargs, MultiMLP from torch.distributed.pipelining import ( ManualPipelineStage, pipeline, diff --git a/test/distributed/test_c10d_gloo.py b/test/distributed/test_c10d_gloo.py index 34f8849ddbf3..6db53fea64a1 100644 --- a/test/distributed/test_c10d_gloo.py +++ b/test/distributed/test_c10d_gloo.py @@ -20,9 +20,6 @@ if not c10d.is_available() or not c10d.is_gloo_available(): sys.exit(0) import test_c10d_common -import torch.distributed as dist -import torch.nn.functional as F -import torch.testing._internal.common_utils as common from test_c10d_common import ( gpus_for_rank, LOOPBACK, @@ -30,6 +27,10 @@ from test_c10d_common import ( SparseGradientModule, Task, ) + +import torch.distributed as dist +import torch.nn.functional as F +import torch.testing._internal.common_utils as common from torch import nn from torch.distributed._shard.sharded_tensor import ( init_from_local_shards, diff --git a/test/distributed/test_c10d_nccl.py b/test/distributed/test_c10d_nccl.py index 4b0ea6b4dd17..4fea855a85b9 100644 --- a/test/distributed/test_c10d_nccl.py +++ b/test/distributed/test_c10d_nccl.py @@ -28,12 +28,13 @@ if not c10d.is_available() or not c10d.is_nccl_available(): from typing import Dict, List import test_c10d_common +from test_c10d_common import ConvNet, DoubleGpuNet, gpus_for_rank, ModuleForDdpCommHook + import torch.distributed as dist import torch.distributed.algorithms.ddp_comm_hooks.default_hooks as default import torch.distributed.algorithms.ddp_comm_hooks.powerSGD_hook as powerSGD import torch.nn.functional as F import torch.testing._internal.common_utils as common -from test_c10d_common import ConvNet, DoubleGpuNet, gpus_for_rank, ModuleForDdpCommHook from torch import nn from torch._C._distributed_c10d import OpType from torch.nn.parallel import DistributedDataParallel diff --git a/test/distributed/test_c10d_spawn_gloo.py b/test/distributed/test_c10d_spawn_gloo.py index 95897a2938b1..a5c5a0a05512 100644 --- a/test/distributed/test_c10d_spawn_gloo.py +++ b/test/distributed/test_c10d_spawn_gloo.py @@ -6,10 +6,11 @@ import sys import tempfile import test_c10d_spawn +from test_c10d_spawn import _torch_dist_nn_available, TestDistributedNNFunctions + import torch import torch.distributed as c10d import torch.nn as nn -from test_c10d_spawn import _torch_dist_nn_available, TestDistributedNNFunctions from torch.testing._internal.common_cuda import TEST_CUDA, TEST_MULTIGPU from torch.testing._internal.common_distributed import ( create_device, diff --git a/test/distributed/test_c10d_spawn_nccl.py b/test/distributed/test_c10d_spawn_nccl.py index 67d6fae24266..184ecd988ec2 100644 --- a/test/distributed/test_c10d_spawn_nccl.py +++ b/test/distributed/test_c10d_spawn_nccl.py @@ -3,9 +3,10 @@ import sys import test_c10d_spawn +from test_c10d_spawn import _torch_dist_nn_available, TestDistributedNNFunctions + import torch import torch.distributed as c10d -from test_c10d_spawn import _torch_dist_nn_available, TestDistributedNNFunctions from torch.testing._internal.common_cuda import TEST_MULTIGPU from torch.testing._internal.common_distributed import requires_nccl, skip_if_lt_x_gpu from torch.testing._internal.common_utils import ( diff --git a/test/distributed/test_c10d_spawn_ucc.py b/test/distributed/test_c10d_spawn_ucc.py index 81f7ec621018..db41e9b6274d 100644 --- a/test/distributed/test_c10d_spawn_ucc.py +++ b/test/distributed/test_c10d_spawn_ucc.py @@ -3,9 +3,10 @@ import sys import test_c10d_spawn +from test_c10d_spawn import _torch_dist_nn_available, TestDistributedNNFunctions + import torch import torch.distributed as c10d -from test_c10d_spawn import _torch_dist_nn_available, TestDistributedNNFunctions from torch.testing._internal.common_cuda import TEST_MULTIGPU from torch.testing._internal.common_distributed import requires_ucc, skip_if_lt_x_gpu from torch.testing._internal.common_utils import ( diff --git a/test/distributed/test_c10d_ucc.py b/test/distributed/test_c10d_ucc.py index 75294c90b5df..e4a1c9004d72 100644 --- a/test/distributed/test_c10d_ucc.py +++ b/test/distributed/test_c10d_ucc.py @@ -18,15 +18,16 @@ if not c10d.is_available() or not c10d.is_ucc_available(): sys.exit(0) import test_c10d_common -import torch.distributed as dist -import torch.nn.functional as F -import torch.testing._internal.common_utils as common from test_c10d_common import ( gpus_for_rank, ModuleForDdpCommHook, SparseGradientModule, Task, ) + +import torch.distributed as dist +import torch.nn.functional as F +import torch.testing._internal.common_utils as common from torch import nn from torch.nn.parallel import DistributedDataParallel from torch.testing._internal.common_distributed import ( diff --git a/test/distributed/test_dynamo_distributed.py b/test/distributed/test_dynamo_distributed.py index 058118d6fa4c..b31a2f717537 100644 --- a/test/distributed/test_dynamo_distributed.py +++ b/test/distributed/test_dynamo_distributed.py @@ -10,6 +10,7 @@ from typing import List from unittest.mock import patch import numpy as np + import torch import torch._dynamo import torch._dynamo.logging diff --git a/test/distributed/test_functional_api.py b/test/distributed/test_functional_api.py index ecbbb4e5b3ae..f2255637a691 100644 --- a/test/distributed/test_functional_api.py +++ b/test/distributed/test_functional_api.py @@ -10,13 +10,13 @@ import torch.distributed as dist import torch.distributed._functional_collectives as ft_c import torch.distributed._tensor as dt import torch.distributed.distributed_c10d as c10d + +from functorch import make_fx from torch._inductor.utils import run_and_get_code from torch.testing import FileCheck from torch.testing._internal.distributed.fake_pg import FakeStore from torch.utils._triton import has_triton -from functorch import make_fx - if not dist.is_available(): print("Distributed not available, skipping tests", file=sys.stderr) sys.exit(0) diff --git a/test/distributions/test_distributions.py b/test/distributions/test_distributions.py index 9e271a750999..79be804d287f 100644 --- a/test/distributions/test_distributions.py +++ b/test/distributions/test_distributions.py @@ -35,9 +35,10 @@ from collections import namedtuple from itertools import product from random import shuffle +from packaging import version + import torch import torch.autograd.forward_ad as fwAD -from packaging import version from torch import inf, nan from torch.autograd import grad diff --git a/test/dynamo/test_activation_checkpointing.py b/test/dynamo/test_activation_checkpointing.py index 5382b3fcf3ba..ee6d56a84ddb 100644 --- a/test/dynamo/test_activation_checkpointing.py +++ b/test/dynamo/test_activation_checkpointing.py @@ -11,6 +11,8 @@ import torch._dynamo.test_case import torch._functorch.config import torch.distributed as dist import torch.utils.checkpoint + +from functorch.compile import min_cut_rematerialization_partition from torch._dynamo.backends.common import aot_autograd from torch._dynamo.testing import CompileCounterWithBackend from torch._higher_order_ops.wrap import tag_activation_checkpoint @@ -19,8 +21,6 @@ from torch.testing._internal.inductor_utils import HAS_CUDA from torch.testing._internal.two_tensor import TwoTensor from torch.utils.checkpoint import _pt2_selective_checkpoint_context_fn_gen, checkpoint -from functorch.compile import min_cut_rematerialization_partition - requires_cuda = unittest.skipUnless(HAS_CUDA, "requires cuda") requires_distributed = functools.partial( unittest.skipIf, not dist.is_available(), "requires distributed" diff --git a/test/dynamo/test_aot_autograd.py b/test/dynamo/test_aot_autograd.py index f21c84a55709..84b1e0a28c0e 100644 --- a/test/dynamo/test_aot_autograd.py +++ b/test/dynamo/test_aot_autograd.py @@ -722,9 +722,8 @@ class AotAutogradFallbackTests(torch._dynamo.test_case.TestCase): return (out,) def compile_submod(input_mod, args): - from torch._functorch.aot_autograd import aot_module_simplified - from functorch.compile import nop + from torch._functorch.aot_autograd import aot_module_simplified class WrapperModule(torch.nn.Module): def __init__(self): diff --git a/test/dynamo/test_autograd_function.py b/test/dynamo/test_autograd_function.py index 5e70bd7cdb9a..eef1d7237780 100644 --- a/test/dynamo/test_autograd_function.py +++ b/test/dynamo/test_autograd_function.py @@ -15,6 +15,7 @@ from torch.testing._internal.triton_utils import HAS_CUDA, requires_cuda if HAS_CUDA: import triton + from torch.testing._internal.triton_utils import add_kernel diff --git a/test/dynamo/test_backends.py b/test/dynamo/test_backends.py index 68e4b745147f..209b075c7612 100644 --- a/test/dynamo/test_backends.py +++ b/test/dynamo/test_backends.py @@ -240,9 +240,8 @@ class TestCustomBackendAPI(torch._dynamo.test_case.TestCase): self.assertTrue(backend_run) def test_aot_autograd_api(self): - from torch._dynamo.backends.common import aot_autograd - from functorch.compile import make_boxed_func + from torch._dynamo.backends.common import aot_autograd backend_run = False diff --git a/test/dynamo/test_debug_utils.py b/test/dynamo/test_debug_utils.py index ff5c5e5b43ed..0c305f800e58 100644 --- a/test/dynamo/test_debug_utils.py +++ b/test/dynamo/test_debug_utils.py @@ -3,13 +3,13 @@ import unittest import torch + +from functorch import make_fx from torch._dynamo import debug_utils from torch._dynamo.debug_utils import aot_graph_input_parser from torch._dynamo.test_case import TestCase from torch.testing._internal.inductor_utils import HAS_CUDA -from functorch import make_fx - requires_cuda = unittest.skipUnless(HAS_CUDA, "requires cuda") f32 = torch.float32 diff --git a/test/dynamo/test_export.py b/test/dynamo/test_export.py index cf4310d5f74c..9f1417e23247 100644 --- a/test/dynamo/test_export.py +++ b/test/dynamo/test_export.py @@ -17,6 +17,8 @@ import torch import torch._dynamo import torch._dynamo.test_case import torch._dynamo.testing + +from functorch.experimental.control_flow import cond from torch._dynamo import config from torch._dynamo.exc import UserError from torch._dynamo.testing import normalize_gm @@ -33,8 +35,6 @@ from torch.fx.experimental.symbolic_shapes import ( from torch.testing._internal import common_utils from torch.testing._internal.common_cuda import TEST_CUDA -from functorch.experimental.control_flow import cond - class ExportTests(torch._dynamo.test_case.TestCase): # TODO(voz): Refactor to a shared test function. diff --git a/test/dynamo/test_higher_order_ops.py b/test/dynamo/test_higher_order_ops.py index bab0abc5f4ec..9b86a90b02f3 100644 --- a/test/dynamo/test_higher_order_ops.py +++ b/test/dynamo/test_higher_order_ops.py @@ -7,6 +7,8 @@ import sys import unittest import warnings +import functorch.experimental.control_flow as control_flow + import torch import torch._dynamo.config as config @@ -32,8 +34,6 @@ from torch.testing._internal.common_utils import ( from torch.testing._internal.inductor_utils import HAS_CUDA from torch.testing._internal.logging_utils import LoggingTestCase, make_logging_test -import functorch.experimental.control_flow as control_flow - requires_cuda = unittest.skipUnless(HAS_CUDA, "requires cuda") diff --git a/test/dynamo/test_hooks.py b/test/dynamo/test_hooks.py index f122803f9a79..a8fe7524db91 100644 --- a/test/dynamo/test_hooks.py +++ b/test/dynamo/test_hooks.py @@ -8,12 +8,12 @@ import torch import torch._dynamo import torch._dynamo.test_case import torch._dynamo.testing + +from functorch.compile import nop from torch._dynamo import compiled_autograd from torch._functorch.aot_autograd import aot_module_simplified from torch.utils.hooks import RemovableHandle -from functorch.compile import nop - def compiler_fn(gm): return torch._dynamo.optimize("inductor", nopython=True, dynamic=True)(gm) diff --git a/test/dynamo/test_misc.py b/test/dynamo/test_misc.py index e1de4ca3e814..ff496406140e 100644 --- a/test/dynamo/test_misc.py +++ b/test/dynamo/test_misc.py @@ -25,6 +25,7 @@ import weakref from unittest.mock import patch import numpy as np + import torch import torch._dynamo.testing diff --git a/test/dynamo/test_repros.py b/test/dynamo/test_repros.py index 1812b7fe0e48..ecb5476ebd0b 100644 --- a/test/dynamo/test_repros.py +++ b/test/dynamo/test_repros.py @@ -22,6 +22,7 @@ from typing import Any, Dict, Iterator, List, Tuple from unittest import mock import numpy as np + import torch import torch._dynamo.test_case @@ -166,9 +167,8 @@ bw_graph = [None] def aot_graph_capture_backend(gm, args): - from torch._functorch.aot_autograd import aot_module_simplified - from functorch.compile import min_cut_rematerialization_partition + from torch._functorch.aot_autograd import aot_module_simplified def fw_compiler(gm, _): fw_graph[0] = gm diff --git a/test/dynamo/test_unspec.py b/test/dynamo/test_unspec.py index cb47a0b728a3..317fd15195ba 100644 --- a/test/dynamo/test_unspec.py +++ b/test/dynamo/test_unspec.py @@ -4,6 +4,7 @@ import random import unittest import numpy as np + import torch import torch._dynamo.test_case import torch._dynamo.testing diff --git a/test/export/test_export.py b/test/export/test_export.py index 4a21e38fffa4..ded6a59b9700 100644 --- a/test/export/test_export.py +++ b/test/export/test_export.py @@ -15,6 +15,8 @@ from typing import Dict, List import torch import torch._dynamo as torchdynamo import torch.nn.functional as F + +from functorch.experimental.control_flow import cond, map from torch import Tensor from torch._dynamo.test_case import TestCase from torch._export.pass_base import _ExportPassBaseDeprecatedDoNotUse @@ -58,8 +60,6 @@ from torch.utils._pytree import ( treespec_loads, ) -from functorch.experimental.control_flow import cond, map - try: from torchrec.sparse.jagged_tensor import KeyedJaggedTensor diff --git a/test/export/test_pass_infra.py b/test/export/test_pass_infra.py index 052da499ed14..70e94c9827ef 100644 --- a/test/export/test_pass_infra.py +++ b/test/export/test_pass_infra.py @@ -3,14 +3,14 @@ import copy import unittest import torch + +from functorch.experimental import control_flow from torch._dynamo.eval_frame import is_dynamo_supported from torch._export.pass_base import _ExportPassBaseDeprecatedDoNotUse from torch.export import export from torch.fx.passes.infra.pass_base import PassResult from torch.testing._internal.common_utils import IS_WINDOWS, run_tests, TestCase -from functorch.experimental import control_flow - @unittest.skipIf(not is_dynamo_supported(), "Dynamo not supported") class TestPassInfra(TestCase): diff --git a/test/export/test_passes.py b/test/export/test_passes.py index c7b4404e6ec6..2807a2ded907 100644 --- a/test/export/test_passes.py +++ b/test/export/test_passes.py @@ -11,6 +11,8 @@ from re import escape from typing import List, Set import torch + +from functorch.experimental.control_flow import cond from torch._dynamo.eval_frame import is_dynamo_supported from torch._export.non_strict_utils import ( _fakify_script_objects, @@ -53,8 +55,6 @@ from torch.testing._internal.common_utils import ( from torch.testing._internal.torchbind_impls import init_torchbind_implementations from torch.utils import _pytree as pytree -from functorch.experimental.control_flow import cond - def count_call_function(graph: torch.fx.Graph, target: torch.ops.OpOverload) -> int: count = 0 diff --git a/test/export/test_unflatten.py b/test/export/test_unflatten.py index e46c948ebfa4..3ca58e8fff79 100644 --- a/test/export/test_unflatten.py +++ b/test/export/test_unflatten.py @@ -10,6 +10,8 @@ from typing import Any, List import torch import torch._dynamo as torchdynamo + +from functorch.experimental.control_flow import cond, map from torch import Tensor from torch._export.utils import ( get_buffer, @@ -51,8 +53,6 @@ from torch.utils._pytree import ( treespec_loads, ) -from functorch.experimental.control_flow import cond, map - @unittest.skipIf(not torchdynamo.is_dynamo_supported(), "dynamo isn't support") class TestUnflatten(TestCase): diff --git a/test/export/test_verifier.py b/test/export/test_verifier.py index e15d3f4f0bc4..c2755d22d709 100644 --- a/test/export/test_verifier.py +++ b/test/export/test_verifier.py @@ -2,6 +2,8 @@ import unittest import torch + +from functorch.experimental import control_flow from torch import Tensor from torch._dynamo.eval_frame import is_dynamo_supported @@ -10,8 +12,6 @@ from torch.export import export from torch.export.exported_program import InputKind, InputSpec, TensorArgument from torch.testing._internal.common_utils import IS_WINDOWS, run_tests, TestCase -from functorch.experimental import control_flow - @unittest.skipIf(not is_dynamo_supported(), "dynamo isn't supported") class TestVerifier(TestCase): diff --git a/test/functorch/attn_ft.py b/test/functorch/attn_ft.py index 7329c4ed4539..3a7bd7afe67b 100644 --- a/test/functorch/attn_ft.py +++ b/test/functorch/attn_ft.py @@ -6,9 +6,9 @@ import math import torch -from torch import nn from functorch.dim import cat, dimlists, dims, softmax +from torch import nn class Linear(nn.Linear): diff --git a/test/functorch/common_utils.py b/test/functorch/common_utils.py index 8b8c8a8efc75..d59802121c93 100644 --- a/test/functorch/common_utils.py +++ b/test/functorch/common_utils.py @@ -9,16 +9,17 @@ import os import unittest from collections import namedtuple +from functorch_additional_op_db import additional_op_db + import torch import torch.utils._pytree as pytree -from functorch_additional_op_db import additional_op_db + +from functorch import vmap from torch.testing._internal.autograd_function_db import autograd_function_db from torch.testing._internal.common_device_type import toleranceOverride from torch.testing._internal.common_methods_invocations import DecorateInfo, op_db from torch.testing._internal.common_modules import module_db -from functorch import vmap - IS_FBCODE = os.getenv("FUNCTORCH_TEST_FBCODE") == "1" diff --git a/test/functorch/discover_coverage.py b/test/functorch/discover_coverage.py index dd7e8b6c9aeb..781b601b321b 100644 --- a/test/functorch/discover_coverage.py +++ b/test/functorch/discover_coverage.py @@ -7,9 +7,10 @@ from enum import Enum # Importing these files make modifications to the op_db that we need import test_ops # noqa: F401 import test_vmap # noqa: F401 +from functorch_additional_op_db import additional_op_db + import torch import torch._functorch.top_operators_github_usage as top_ops -from functorch_additional_op_db import additional_op_db from torch.testing._internal.common_device_type import toleranceOverride from torch.testing._internal.common_methods_invocations import op_db diff --git a/test/functorch/test_aotdispatch.py b/test/functorch/test_aotdispatch.py index 25152ac9af87..348af610372a 100644 --- a/test/functorch/test_aotdispatch.py +++ b/test/functorch/test_aotdispatch.py @@ -15,11 +15,29 @@ from functools import partial from typing import Any, Callable, Dict, List, Optional, Union from unittest.mock import patch +from common_utils import decorate, decorateForModules, skip, skipOps, xfail + import torch import torch._dynamo as torchdynamo import torch.nn as nn import torch.utils._pytree as pytree -from common_utils import decorate, decorateForModules, skip, skipOps, xfail + +from functorch import grad, jacrev, make_fx, vjp, vmap +from functorch.compile import ( + aot_function, + aot_module, + compiled_function, + compiled_module, + default_decompositions, + default_partition, + get_aot_compilation_context, + make_boxed_compiler, + memory_efficient_fusion, + min_cut_rematerialization_partition, + nnc_jit, + nop, +) +from functorch.experimental import control_flow from torch._decomp import decomposition_table from torch._functorch.aot_autograd import ( aot_export_joint_simple, @@ -61,23 +79,6 @@ from torch.testing._internal.optests import ( ) from torch.testing._internal.two_tensor import TwoTensor, TwoTensorMode -from functorch import grad, jacrev, make_fx, vjp, vmap -from functorch.compile import ( - aot_function, - aot_module, - compiled_function, - compiled_module, - default_decompositions, - default_partition, - get_aot_compilation_context, - make_boxed_compiler, - memory_efficient_fusion, - min_cut_rematerialization_partition, - nnc_jit, - nop, -) -from functorch.experimental import control_flow - USE_TORCHVISION = False try: import torchvision diff --git a/test/functorch/test_control_flow.py b/test/functorch/test_control_flow.py index 2065327f3148..cfad762c54be 100644 --- a/test/functorch/test_control_flow.py +++ b/test/functorch/test_control_flow.py @@ -5,6 +5,9 @@ import unittest import torch import torch.utils._pytree as pytree + +from functorch.experimental import control_flow +from functorch.experimental.control_flow import cond, UnsupportedAliasMutationException from torch._higher_order_ops.while_loop import while_loop from torch._subclasses.functional_tensor import ( CppFunctionalizeAPI, @@ -25,9 +28,6 @@ from torch.testing._internal.common_utils import ( TestCase, ) -from functorch.experimental import control_flow -from functorch.experimental.control_flow import cond, UnsupportedAliasMutationException - # TODO: pull these helpers from AOTAutograd later def to_fun(t): diff --git a/test/functorch/test_dims.py b/test/functorch/test_dims.py index 83ed1615f12b..928fba5039e9 100644 --- a/test/functorch/test_dims.py +++ b/test/functorch/test_dims.py @@ -9,17 +9,10 @@ import gc from unittest import skip, skipIf -import torch - from attn_ft import BertSelfAttention as BertSelfAttentionA, Linear from attn_positional import BertSelfAttention as BertSelfAttentionB -from torch.testing._internal.common_utils import ( - run_tests, - skipIfTorchDynamo, - TEST_CUDA, - TestCase, -) +import torch from functorch._C import dim as _C from functorch.dim import ( @@ -32,6 +25,13 @@ from functorch.dim import ( Tensor, ) +from torch.testing._internal.common_utils import ( + run_tests, + skipIfTorchDynamo, + TEST_CUDA, + TestCase, +) + try: from torchvision.models import resnet18 except ImportError: diff --git a/test/functorch/test_eager_transforms.py b/test/functorch/test_eager_transforms.py index 124b86627913..3084c1795560 100644 --- a/test/functorch/test_eager_transforms.py +++ b/test/functorch/test_eager_transforms.py @@ -17,11 +17,28 @@ from functools import partial, wraps # NB: numpy is a testing dependency! import numpy as np +from common_utils import expectedFailureIf + +import functorch import torch import torch.autograd.forward_ad as fwAD import torch.nn as nn import torch.nn.functional as F -from common_utils import expectedFailureIf +from functorch import ( + combine_state_for_ensemble, + grad, + grad_and_value, + hessian, + jacfwd, + jacrev, + jvp, + make_functional, + make_functional_with_buffers, + make_fx, + vjp, + vmap, +) +from functorch.experimental import functionalize, replace_all_batch_norm_modules_ from torch._C import _ExcludeDispatchKeyGuard, DispatchKey, DispatchKeySet from torch._dynamo import allow_in_graph from torch._functorch.eager_transforms import _slice_argnums @@ -64,23 +81,6 @@ from torch.testing._internal.common_utils import ( from torch.utils._pytree import tree_flatten, tree_map, tree_unflatten -import functorch -from functorch import ( - combine_state_for_ensemble, - grad, - grad_and_value, - hessian, - jacfwd, - jacrev, - jvp, - make_functional, - make_functional_with_buffers, - make_fx, - vjp, - vmap, -) -from functorch.experimental import functionalize, replace_all_batch_norm_modules_ - USE_TORCHVISION = False try: import torchvision # noqa: F401 diff --git a/test/functorch/test_memory_efficient_fusion.py b/test/functorch/test_memory_efficient_fusion.py index d31748fe0c50..297e9fb3255b 100644 --- a/test/functorch/test_memory_efficient_fusion.py +++ b/test/functorch/test_memory_efficient_fusion.py @@ -8,12 +8,12 @@ from typing import Callable import torch import torch.fx as fx import torch.nn as nn -from torch._functorch.compile_utils import fx_graph_cse -from torch.nn import functional as F -from torch.testing._internal.common_utils import run_tests, TestCase from functorch import make_fx from functorch.compile import memory_efficient_fusion +from torch._functorch.compile_utils import fx_graph_cse +from torch.nn import functional as F +from torch.testing._internal.common_utils import run_tests, TestCase HAS_CUDA = torch.cuda.is_available() diff --git a/test/functorch/test_minifier.py b/test/functorch/test_minifier.py index b90f754a90b0..61862b2ffe21 100644 --- a/test/functorch/test_minifier.py +++ b/test/functorch/test_minifier.py @@ -1,11 +1,11 @@ # Owner(s): ["module: functorch"] import torch -from torch._functorch.compile_utils import get_outputs, get_placeholders -from torch.testing._internal.common_utils import run_tests, TestCase from functorch import make_fx from functorch.compile import minifier +from torch._functorch.compile_utils import get_outputs, get_placeholders +from torch.testing._internal.common_utils import run_tests, TestCase class TestMinifier(TestCase): diff --git a/test/functorch/test_ops.py b/test/functorch/test_ops.py index e9b7330acfe2..c8df820c7c9c 100644 --- a/test/functorch/test_ops.py +++ b/test/functorch/test_ops.py @@ -10,8 +10,6 @@ import functools import itertools import unittest -import torch -import torch.autograd.forward_ad as fwAD from common_utils import ( check_vmap_fallback, decorate, @@ -30,6 +28,11 @@ from common_utils import ( xfail, ) from functorch_additional_op_db import additional_op_db + +import torch +import torch.autograd.forward_ad as fwAD + +from functorch import grad, jacfwd, jacrev, vjp, vmap from torch import Tensor from torch._functorch.eager_transforms import _as_tuple, jvp from torch.testing._internal.autograd_function_db import autograd_function_db @@ -61,8 +64,6 @@ from torch.testing._internal.opinfo.core import SampleInput from torch.utils import _pytree as pytree from torch.utils._pytree import tree_flatten, tree_map, tree_unflatten -from functorch import grad, jacfwd, jacrev, vjp, vmap - aten = torch.ops.aten diff --git a/test/functorch/test_parsing.py b/test/functorch/test_parsing.py index 11812f355140..d98b4aa00fd2 100644 --- a/test/functorch/test_parsing.py +++ b/test/functorch/test_parsing.py @@ -27,8 +27,6 @@ SOFTWARE. from typing import Any, Callable, Dict from unittest import mock -from torch.testing._internal.common_utils import run_tests, TestCase - from functorch.einops._parsing import ( _ellipsis, AnonymousAxis, @@ -37,6 +35,8 @@ from functorch.einops._parsing import ( validate_rearrange_expressions, ) +from torch.testing._internal.common_utils import run_tests, TestCase + mock_anonymous_axis_eq: Callable[[AnonymousAxis, object], bool] = ( lambda self, other: isinstance(other, AnonymousAxis) and self.value == other.value ) diff --git a/test/functorch/test_rearrange.py b/test/functorch/test_rearrange.py index 90c9a20d8515..47414ca6d331 100644 --- a/test/functorch/test_rearrange.py +++ b/test/functorch/test_rearrange.py @@ -28,10 +28,11 @@ SOFTWARE. from typing import List, Tuple import numpy as np + import torch -from torch.testing._internal.common_utils import run_tests, TestCase from functorch.einops import rearrange +from torch.testing._internal.common_utils import run_tests, TestCase identity_patterns: List[str] = [ "...->...", diff --git a/test/functorch/test_vmap.py b/test/functorch/test_vmap.py index b45b0ddbc1c1..e5b72b5d7eb5 100644 --- a/test/functorch/test_vmap.py +++ b/test/functorch/test_vmap.py @@ -18,8 +18,6 @@ from collections import namedtuple from typing import OrderedDict from unittest.case import skipIf -import torch -import torch.nn.functional as F from common_utils import ( check_vmap_fallback, compute_quantities_for_vmap_test, @@ -36,6 +34,13 @@ from common_utils import ( xfail, ) from functorch_additional_op_db import additional_op_db + +import functorch + +import torch +import torch.nn.functional as F +from functorch import grad, grad_and_value, jacfwd, jvp, vjp, vmap +from functorch.experimental import chunk_vmap from torch import Tensor from torch._C._functorch import reshape_dim_into, reshape_dim_outof from torch._functorch.make_functional import functional_init_with_buffers @@ -65,10 +70,6 @@ from torch.testing._internal.common_utils import ( ) from torch.utils import _pytree as pytree -import functorch -from functorch import grad, grad_and_value, jacfwd, jvp, vjp, vmap -from functorch.experimental import chunk_vmap - FALLBACK_REGEX = "There is a performance drop" diff --git a/test/fx/test_gradual_type.py b/test/fx/test_gradual_type.py index 1a0f5d9bde47..31f28dc45ee1 100644 --- a/test/fx/test_gradual_type.py +++ b/test/fx/test_gradual_type.py @@ -3,6 +3,7 @@ import unittest import sympy + import torch from torch.fx import GraphModule, symbolic_trace from torch.fx.annotate import annotate diff --git a/test/inductor/test_aot_inductor.py b/test/inductor/test_aot_inductor.py index 27636ff26a5f..f500687596f9 100644 --- a/test/inductor/test_aot_inductor.py +++ b/test/inductor/test_aot_inductor.py @@ -42,6 +42,7 @@ from torch.utils import _pytree as pytree if HAS_CUDA: import triton + from torch.testing._internal.triton_utils import ( add_kernel, add_kernel_2d_autotuned, diff --git a/test/inductor/test_codecache.py b/test/inductor/test_codecache.py index 5b5dd5cde3c2..994786740a65 100644 --- a/test/inductor/test_codecache.py +++ b/test/inductor/test_codecache.py @@ -44,6 +44,7 @@ HAS_TRITON = has_triton() if HAS_TRITON: import triton + from torch.testing._internal.triton_utils import add_kernel requires_gpu = functools.partial(unittest.skipIf, not HAS_GPU, "requires gpu") diff --git a/test/inductor/test_cpu_repro.py b/test/inductor/test_cpu_repro.py index 1110fde150fc..4a9a75764080 100644 --- a/test/inductor/test_cpu_repro.py +++ b/test/inductor/test_cpu_repro.py @@ -12,6 +12,7 @@ from unittest.mock import patch import numpy as np import sympy + import torch from torch import nn from torch._C import FileCheck diff --git a/test/inductor/test_efficient_conv_bn_eval.py b/test/inductor/test_efficient_conv_bn_eval.py index 34235a9285b7..c65b7585f9f3 100644 --- a/test/inductor/test_efficient_conv_bn_eval.py +++ b/test/inductor/test_efficient_conv_bn_eval.py @@ -106,9 +106,8 @@ class EfficientConvBNEvalTemplate(TestCase): def test_conv_bn_eval( test_class, use_bias, module, sync_bn, decompose_nn_module ): - from torch._dispatch.python import enable_python_dispatcher - from functorch import make_fx + from torch._dispatch.python import enable_python_dispatcher kwargs = {"kernel_size": 3, "stride": 2} if module[0] != nn.Linear else {} mod_eager = test_class( diff --git a/test/inductor/test_perf.py b/test/inductor/test_perf.py index c2d4f935f459..5e1af26f4bfa 100644 --- a/test/inductor/test_perf.py +++ b/test/inductor/test_perf.py @@ -2,6 +2,8 @@ import contextlib from unittest.mock import patch +import functorch + import torch import torch._inductor.config as config import torch.autograd @@ -28,8 +30,6 @@ from torch.testing._internal.common_utils import skipIfRocm # Defines all the kernels for tests from torch.testing._internal.triton_utils import HAS_CUDA, requires_cuda -import functorch - if HAS_CUDA: from torch.testing._internal.triton_utils import add_kernel diff --git a/test/inductor/test_triton_kernels.py b/test/inductor/test_triton_kernels.py index 9958d1fee5e6..accab8beae6b 100644 --- a/test/inductor/test_triton_kernels.py +++ b/test/inductor/test_triton_kernels.py @@ -107,6 +107,7 @@ class KernelTests(torch._inductor.test_case.TestCase): @requires_cuda @skipIfRocm def test_triton_kernel_functionalize(self): + from functorch import make_fx from torch._higher_order_ops.triton_kernel_wrap import kernel_side_table from torch._subclasses.functional_tensor import ( CppFunctionalizeAPI, @@ -114,8 +115,6 @@ class KernelTests(torch._inductor.test_case.TestCase): PythonFunctionalizeAPI, ) - from functorch import make_fx - kernel_side_table.reset_table() def f(x, output): diff --git a/test/inductor/test_utils.py b/test/inductor/test_utils.py index 667e1513d332..66150f92bbef 100644 --- a/test/inductor/test_utils.py +++ b/test/inductor/test_utils.py @@ -1,6 +1,7 @@ # Owner(s): ["module: inductor"] from sympy import Symbol + from torch._inductor.test_case import run_tests, TestCase from torch._inductor.utils import sympy_subs diff --git a/test/jit/fixtures_srcs/test_upgrader_models_generation.py b/test/jit/fixtures_srcs/test_upgrader_models_generation.py index df0368d5d865..74516785fb4b 100644 --- a/test/jit/fixtures_srcs/test_upgrader_models_generation.py +++ b/test/jit/fixtures_srcs/test_upgrader_models_generation.py @@ -1,9 +1,9 @@ # Owner(s): ["oncall: mobile"] import torch -from torch.testing._internal.common_utils import run_tests, TestCase from test.jit.fixtures_srcs.generate_models import ALL_MODULES +from torch.testing._internal.common_utils import run_tests, TestCase class TestUpgraderModelGeneration(TestCase): diff --git a/test/jit/test_dataclasses.py b/test/jit/test_dataclasses.py index 274818336aec..4cebc2706568 100644 --- a/test/jit/test_dataclasses.py +++ b/test/jit/test_dataclasses.py @@ -7,8 +7,9 @@ from dataclasses import dataclass, field, InitVar from enum import Enum from typing import List, Optional -import torch from hypothesis import given, settings, strategies as st + +import torch from torch.testing._internal.jit_utils import JitTestCase diff --git a/test/jit/test_decorator.py b/test/jit/test_decorator.py index 132935c37a7e..b7d4ef0f30e8 100644 --- a/test/jit/test_decorator.py +++ b/test/jit/test_decorator.py @@ -7,9 +7,9 @@ from enum import Enum from typing import List, Optional import torch -from torch.testing._internal.jit_utils import JitTestCase from jit.myfunction_a import my_function_a +from torch.testing._internal.jit_utils import JitTestCase class TestDecorator(JitTestCase): diff --git a/test/jit/test_misc.py b/test/jit/test_misc.py index 8d58ab860d5b..956096173f9b 100644 --- a/test/jit/test_misc.py +++ b/test/jit/test_misc.py @@ -8,14 +8,14 @@ from typing import Any, Dict, List, Optional, Tuple import torch import torch.nn as nn import torch.testing._internal.jit_utils + +from jit.test_module_interface import TestModuleInterface # noqa: F401 from torch import jit from torch.testing import FileCheck from torch.testing._internal.common_utils import freeze_rng_state from torch.testing._internal.jit_utils import JitTestCase, make_global, RUN_CUDA_HALF -from jit.test_module_interface import TestModuleInterface # noqa: F401 - # Make the helper files in test/ importable pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) sys.path.append(pytorch_test_dir) diff --git a/test/jit/test_python_ir.py b/test/jit/test_python_ir.py index ff00823f11c8..60d85dd8d76a 100644 --- a/test/jit/test_python_ir.py +++ b/test/jit/test_python_ir.py @@ -3,6 +3,7 @@ import unittest import numpy as np + import torch from torch.testing import FileCheck from torch.testing._internal.common_utils import IS_MACOS diff --git a/test/jit/test_save_load_for_op_version.py b/test/jit/test_save_load_for_op_version.py index d9eb62bc4217..63e17a7a1867 100644 --- a/test/jit/test_save_load_for_op_version.py +++ b/test/jit/test_save_load_for_op_version.py @@ -7,9 +7,9 @@ from itertools import product as product from typing import Union import hypothesis.strategies as st +from hypothesis import example, given, settings import torch -from hypothesis import example, given, settings # Make the helper files in test/ importable pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) diff --git a/test/jit/test_types.py b/test/jit/test_types.py index e331aad12e44..baa1e2311bad 100644 --- a/test/jit/test_types.py +++ b/test/jit/test_types.py @@ -9,12 +9,12 @@ from typing import Dict, Iterator, List, Optional, Tuple import torch import torch.testing._internal.jit_utils + +from jit.test_module_interface import TestModuleInterface # noqa: F401 from torch.testing import FileCheck from torch.testing._internal.jit_utils import JitTestCase -from jit.test_module_interface import TestModuleInterface # noqa: F401 - # Make the helper files in test/ importable pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) sys.path.append(pytorch_test_dir) diff --git a/test/lazy/test_ts_opinfo.py b/test/lazy/test_ts_opinfo.py index c880c90a8108..102dee3664be 100644 --- a/test/lazy/test_ts_opinfo.py +++ b/test/lazy/test_ts_opinfo.py @@ -7,13 +7,14 @@ import pathlib from typing import Sequence from unittest import skip +import yaml + import torch import torch._lazy import torch._lazy.config import torch._lazy.ir_cache import torch._lazy.metrics import torch._lazy.ts_backend -import yaml from torch.testing._internal.common_device_type import ( instantiate_device_type_tests, ops, diff --git a/test/mobile/custom_build/prepare_model.py b/test/mobile/custom_build/prepare_model.py index 6cbf1ecef2fd..1adea1795f5e 100644 --- a/test/mobile/custom_build/prepare_model.py +++ b/test/mobile/custom_build/prepare_model.py @@ -4,10 +4,11 @@ MobileNetV2 TorchScript model, and dumps root ops used by the model for custom build script to create a tailored build which only contains these used ops. """ -import torch import yaml from torchvision import models +import torch + # Download and trace the model. model = models.mobilenet_v2(weights=models.MobileNet_V2_Weights.IMAGENET1K_V1) model.eval() diff --git a/test/mobile/model_test/gen_test_model.py b/test/mobile/model_test/gen_test_model.py index 15e3c2e807cd..e93945528b60 100644 --- a/test/mobile/model_test/gen_test_model.py +++ b/test/mobile/model_test/gen_test_model.py @@ -1,7 +1,6 @@ import io import sys -import torch import yaml from android_api_module import AndroidAPIModule from builtin_ops import TSBuiltinOpsModule, TSCollectionOpsModule @@ -44,13 +43,15 @@ from tensor_ops import ( TensorTypingOpsModule, TensorViewOpsModule, ) -from torch.jit.mobile import _load_for_lite_interpreter from torchvision_models import ( MobileNetV2Module, MobileNetV2VulkanModule, Resnet18Module, ) +import torch +from torch.jit.mobile import _load_for_lite_interpreter + test_path_ios = "ios/TestApp/models/" test_path_android = "android/pytorch_android/src/androidTest/assets/" diff --git a/test/mobile/model_test/torchvision_models.py b/test/mobile/model_test/torchvision_models.py index cdd27a408910..8f51a6d1e4ad 100644 --- a/test/mobile/model_test/torchvision_models.py +++ b/test/mobile/model_test/torchvision_models.py @@ -1,7 +1,8 @@ +from torchvision import models + import torch from torch.utils.bundled_inputs import augment_model_with_bundled_inputs from torch.utils.mobile_optimizer import optimize_for_mobile -from torchvision import models class MobileNetV2Module: diff --git a/test/onnx/debug_embed_params.py b/test/onnx/debug_embed_params.py index ea6db1de1e87..8f32a838a998 100644 --- a/test/onnx/debug_embed_params.py +++ b/test/onnx/debug_embed_params.py @@ -2,12 +2,12 @@ import sys import onnx import pytorch_test_common + +import caffe2.python.onnx.backend as c2 import torch import torch.jit from torch.autograd import Variable -import caffe2.python.onnx.backend as c2 - torch.set_default_tensor_type("torch.FloatTensor") try: import torch diff --git a/test/onnx/dynamo/test_dynamo_with_onnxruntime_backend.py b/test/onnx/dynamo/test_dynamo_with_onnxruntime_backend.py index e11cebc26b8d..1d5127b18603 100644 --- a/test/onnx/dynamo/test_dynamo_with_onnxruntime_backend.py +++ b/test/onnx/dynamo/test_dynamo_with_onnxruntime_backend.py @@ -10,10 +10,10 @@ import unittest from typing import Tuple import onnxruntime +from parameterized import parameterized import torch import torch._dynamo.backends.registry -from parameterized import parameterized from torch import nn from torch.onnx import ( _OrtBackend as OrtBackend, diff --git a/test/onnx/dynamo/test_exporter_api.py b/test/onnx/dynamo/test_exporter_api.py index 8d32101e0c1b..cc60b975a5eb 100644 --- a/test/onnx/dynamo/test_exporter_api.py +++ b/test/onnx/dynamo/test_exporter_api.py @@ -3,8 +3,9 @@ import io import os import onnx -import torch from beartype import roar + +import torch from torch.onnx import dynamo_export, ExportOptions, ONNXProgram from torch.onnx._internal import exporter, io_adapter from torch.onnx._internal.exporter import ( diff --git a/test/onnx/dynamo/test_registry_dispatcher.py b/test/onnx/dynamo/test_registry_dispatcher.py index 43fec1616463..087251131e64 100644 --- a/test/onnx/dynamo/test_registry_dispatcher.py +++ b/test/onnx/dynamo/test_registry_dispatcher.py @@ -6,12 +6,12 @@ import operator from typing import TypeVar, Union import onnxscript # type: ignore[import] - -import torch -import torch.fx from onnxscript import BFLOAT16, DOUBLE, FLOAT, FLOAT16 # type: ignore[import] from onnxscript.function_libs.torch_lib import ops # type: ignore[import] from onnxscript.onnx_opset import opset15 as op # type: ignore[import] + +import torch +import torch.fx from torch.onnx._internal.diagnostics import infra from torch.onnx._internal.fx import ( analysis, diff --git a/test/onnx/error_reproduction.py b/test/onnx/error_reproduction.py index 470bdd7c38e4..d2af1ec86bdf 100644 --- a/test/onnx/error_reproduction.py +++ b/test/onnx/error_reproduction.py @@ -14,6 +14,7 @@ import numpy as np import onnx import onnxruntime as ort import onnxscript + import torch _MISMATCH_MARKDOWN_TEMPLATE = """\ diff --git a/test/onnx/onnx_test_common.py b/test/onnx/onnx_test_common.py index 23a98dc0df4e..0cb97f47ddb3 100644 --- a/test/onnx/onnx_test_common.py +++ b/test/onnx/onnx_test_common.py @@ -30,6 +30,7 @@ import numpy as np import onnxruntime import pytest import pytorch_test_common + import torch from torch import export as torch_export from torch.onnx import _constants, verification diff --git a/test/onnx/test_autograd_funs.py b/test/onnx/test_autograd_funs.py index a5498f39d2da..755f811f032a 100644 --- a/test/onnx/test_autograd_funs.py +++ b/test/onnx/test_autograd_funs.py @@ -1,9 +1,9 @@ # Owner(s): ["module: onnx"] import pytorch_test_common +from onnx_test_common import run_model_test import torch -from onnx_test_common import run_model_test from torch.onnx import OperatorExportTypes from torch.onnx._globals import GLOBALS from torch.onnx.utils import _model_to_graph diff --git a/test/onnx/test_custom_ops.py b/test/onnx/test_custom_ops.py index 9ce2c9341580..dd8b0a539766 100644 --- a/test/onnx/test_custom_ops.py +++ b/test/onnx/test_custom_ops.py @@ -2,6 +2,7 @@ import onnx_test_common import pytorch_test_common + import torch import torch.utils.cpp_extension from torch.onnx import symbolic_helper diff --git a/test/onnx/test_fx_op_consistency.py b/test/onnx/test_fx_op_consistency.py index 0a1cabf19d41..4c71aafa473e 100644 --- a/test/onnx/test_fx_op_consistency.py +++ b/test/onnx/test_fx_op_consistency.py @@ -56,9 +56,9 @@ import onnx_test_common import parameterized import pytest import pytorch_test_common +from onnx_test_common import skip, skip_slow, xfail import torch -from onnx_test_common import skip, skip_slow, xfail from torch.onnx._internal.diagnostics import _rules from torch.testing._internal import ( common_device_type, diff --git a/test/onnx/test_fx_to_onnx.py b/test/onnx/test_fx_to_onnx.py index f5de6aca086a..b660b0525dba 100644 --- a/test/onnx/test_fx_to_onnx.py +++ b/test/onnx/test_fx_to_onnx.py @@ -10,8 +10,9 @@ from typing import Mapping, Tuple import onnx import onnx.inliner import pytorch_test_common -import torch import transformers # type: ignore[import] + +import torch from torch import nn from torch._subclasses import fake_tensor from torch.nn import functional as F diff --git a/test/onnx/test_fx_to_onnx_with_onnxruntime.py b/test/onnx/test_fx_to_onnx_with_onnxruntime.py index 3f8ba1de2bc3..149b9dc987bb 100644 --- a/test/onnx/test_fx_to_onnx_with_onnxruntime.py +++ b/test/onnx/test_fx_to_onnx_with_onnxruntime.py @@ -14,10 +14,11 @@ import onnx_test_common import onnxruntime # type: ignore[import] import parameterized # type: ignore[import] import pytorch_test_common -import torch -import torch.onnx import transformers # type: ignore[import] + +import torch +import torch.onnx from torch import nn from torch._subclasses import fake_tensor diff --git a/test/onnx/test_fx_type_promotion.py b/test/onnx/test_fx_type_promotion.py index ce6e9a09cac6..1e3860ad2a8e 100644 --- a/test/onnx/test_fx_type_promotion.py +++ b/test/onnx/test_fx_type_promotion.py @@ -1,6 +1,7 @@ # Owner(s): ["module: onnx"] import pytorch_test_common + from torch.onnx._internal.fx.passes import type_promotion from torch.testing._internal import common_utils diff --git a/test/onnx/test_models.py b/test/onnx/test_models.py index f56d9cd9f23c..132c812f3b08 100644 --- a/test/onnx/test_models.py +++ b/test/onnx/test_models.py @@ -3,8 +3,6 @@ import unittest import pytorch_test_common - -import torch from model_defs.dcgan import _netD, _netG, bsz, imgsz, nz, weights_init from model_defs.emb_seq import EmbeddingNetwork1, EmbeddingNetwork2 from model_defs.mnist import MNIST @@ -13,11 +11,6 @@ from model_defs.squeezenet import SqueezeNet from model_defs.srresnet import SRResNet from model_defs.super_resolution import SuperResolutionNet from pytorch_test_common import skipIfUnsupportedMinOpsetVersion, skipScriptTest -from torch.ao import quantization -from torch.autograd import Variable -from torch.onnx import OperatorExportTypes -from torch.testing._internal import common_utils -from torch.testing._internal.common_utils import skipIfNoLapack from torchvision.models import shufflenet_v2_x1_0 from torchvision.models.alexnet import alexnet from torchvision.models.densenet import densenet121 @@ -31,6 +24,13 @@ from torchvision.models.vgg import vgg16, vgg16_bn, vgg19, vgg19_bn from torchvision.models.video import mc3_18, r2plus1d_18, r3d_18 from verify import verify +import torch +from torch.ao import quantization +from torch.autograd import Variable +from torch.onnx import OperatorExportTypes +from torch.testing._internal import common_utils +from torch.testing._internal.common_utils import skipIfNoLapack + if torch.cuda.is_available(): def toC(x): diff --git a/test/onnx/test_models_onnxruntime.py b/test/onnx/test_models_onnxruntime.py index f9afca487f52..7c51f45b19e4 100644 --- a/test/onnx/test_models_onnxruntime.py +++ b/test/onnx/test_models_onnxruntime.py @@ -10,12 +10,8 @@ import parameterized import PIL import pytorch_test_common import test_models - -import torch import torchvision from pytorch_test_common import skipIfUnsupportedMinOpsetVersion, skipScriptTest -from torch import nn -from torch.testing._internal import common_utils from torchvision import ops from torchvision.models.detection import ( faster_rcnn, @@ -27,6 +23,10 @@ from torchvision.models.detection import ( transform, ) +import torch +from torch import nn +from torch.testing._internal import common_utils + def exportTest( self, diff --git a/test/onnx/test_models_quantized_onnxruntime.py b/test/onnx/test_models_quantized_onnxruntime.py index 2c582e7d447e..81a180ea01fd 100644 --- a/test/onnx/test_models_quantized_onnxruntime.py +++ b/test/onnx/test_models_quantized_onnxruntime.py @@ -6,9 +6,9 @@ import unittest import onnx_test_common import parameterized import PIL +import torchvision import torch -import torchvision from torch import nn diff --git a/test/onnx/test_onnxscript_no_runtime.py b/test/onnx/test_onnxscript_no_runtime.py index 4389dc53aef0..fb59e1dc8889 100644 --- a/test/onnx/test_onnxscript_no_runtime.py +++ b/test/onnx/test_onnxscript_no_runtime.py @@ -6,8 +6,9 @@ from typing import List import onnx import onnxscript -import torch from onnxscript.onnx_types import FLOAT + +import torch from torch.onnx._internal import jit_utils from torch.testing._internal import common_utils diff --git a/test/onnx/test_onnxscript_runtime.py b/test/onnx/test_onnxscript_runtime.py index 4266de85b107..1f02726d989c 100644 --- a/test/onnx/test_onnxscript_runtime.py +++ b/test/onnx/test_onnxscript_runtime.py @@ -5,8 +5,9 @@ from typing import List import onnx_test_common import onnxscript -import torch from onnxscript.onnx_types import FLOAT + +import torch from torch.onnx._internal import jit_utils from torch.testing._internal import common_utils diff --git a/test/onnx/test_op_consistency.py b/test/onnx/test_op_consistency.py index b6f2db246884..95e67b3221e7 100644 --- a/test/onnx/test_op_consistency.py +++ b/test/onnx/test_op_consistency.py @@ -30,10 +30,10 @@ from typing import Optional, Tuple import onnx_test_common import parameterized -import torch - # For readability, these two are allowed to be imported as function from onnx_test_common import skip, xfail + +import torch from torch.testing._internal import ( common_device_type, common_methods_invocations, diff --git a/test/onnx/test_operators.py b/test/onnx/test_operators.py index 2ed17771e3ce..99f0d533a61c 100644 --- a/test/onnx/test_operators.py +++ b/test/onnx/test_operators.py @@ -18,11 +18,6 @@ import tempfile # Full diff for expect files import unittest -import torch -import torch.nn as nn -import torch.nn.functional as F -import torch.onnx - from pytorch_test_common import ( BATCH_SIZE, flatten, @@ -30,6 +25,11 @@ from pytorch_test_common import ( RNN_INPUT_SIZE, RNN_SEQUENCE_LENGTH, ) + +import torch +import torch.nn as nn +import torch.nn.functional as F +import torch.onnx from torch.autograd import Function, Variable from torch.nn import functional, Module from torch.onnx._internal import diagnostics diff --git a/test/onnx/test_pytorch_jit_onnx.py b/test/onnx/test_pytorch_jit_onnx.py index 2c02df78aabb..68f26aea8b89 100644 --- a/test/onnx/test_pytorch_jit_onnx.py +++ b/test/onnx/test_pytorch_jit_onnx.py @@ -1,9 +1,9 @@ # Owner(s): ["module: onnx"] import onnxruntime import pytorch_test_common +from pytorch_test_common import skipIfNoCuda import torch -from pytorch_test_common import skipIfNoCuda from torch.onnx import verification from torch.onnx._globals import GLOBALS from torch.testing._internal import common_utils diff --git a/test/onnx/test_pytorch_onnx_onnxruntime.py b/test/onnx/test_pytorch_onnx_onnxruntime.py index 966e34aedd86..816bcfc3b8df 100644 --- a/test/onnx/test_pytorch_onnx_onnxruntime.py +++ b/test/onnx/test_pytorch_onnx_onnxruntime.py @@ -15,7 +15,6 @@ import numpy as np import onnx import onnx_test_common import parameterized -import torch import torchvision from model_defs import ( lstm_flattening_result, @@ -38,6 +37,8 @@ from pytorch_test_common import ( skipTraceTest, ) +import torch + from torch import Tensor from torch.nn.utils import rnn as rnn_utils from torch.onnx import errors, verification diff --git a/test/onnx/test_pytorch_onnx_onnxruntime_cuda.py b/test/onnx/test_pytorch_onnx_onnxruntime_cuda.py index 82aab068f501..399fe8a64dc1 100644 --- a/test/onnx/test_pytorch_onnx_onnxruntime_cuda.py +++ b/test/onnx/test_pytorch_onnx_onnxruntime_cuda.py @@ -6,8 +6,6 @@ import onnx_test_common import onnxruntime # noqa: F401 import parameterized - -import torch from onnx_test_common import MAX_ONNX_OPSET_VERSION, MIN_ONNX_OPSET_VERSION from pytorch_test_common import ( skipIfNoBFloat16Cuda, @@ -16,6 +14,8 @@ from pytorch_test_common import ( skipScriptTest, ) from test_pytorch_onnx_onnxruntime import _parameterized_class_attrs_and_values + +import torch from torch.cuda.amp import autocast from torch.testing._internal import common_utils diff --git a/test/onnx/test_pytorch_onnx_shape_inference.py b/test/onnx/test_pytorch_onnx_shape_inference.py index 41f23f3c0a59..f01b7b5af406 100644 --- a/test/onnx/test_pytorch_onnx_shape_inference.py +++ b/test/onnx/test_pytorch_onnx_shape_inference.py @@ -5,8 +5,9 @@ import io import numpy as np import onnx import pytorch_test_common -import torch from pytorch_test_common import skipIfUnsupportedMinOpsetVersion + +import torch from torch.onnx import _constants, utils from torch.onnx._globals import GLOBALS from torch.onnx._internal import jit_utils diff --git a/test/onnx/test_utility_funs.py b/test/onnx/test_utility_funs.py index f133b5cf149e..9ee412987965 100644 --- a/test/onnx/test_utility_funs.py +++ b/test/onnx/test_utility_funs.py @@ -10,10 +10,6 @@ from typing import Callable import onnx import parameterized import pytorch_test_common - -import torch -import torch.onnx -import torch.utils.cpp_extension import torchvision from autograd_helper import CustomFunction as CustomFunction2 from pytorch_test_common import ( @@ -21,12 +17,16 @@ from pytorch_test_common import ( skipIfUnsupportedMaxOpsetVersion, skipIfUnsupportedMinOpsetVersion, ) +from verify import verify + +import torch +import torch.onnx +import torch.utils.cpp_extension from torch.onnx import _constants, OperatorExportTypes, TrainingMode, utils from torch.onnx._globals import GLOBALS from torch.onnx.symbolic_helper import _unpack_list, parse_args from torch.testing._internal import common_utils from torch.testing._internal.common_utils import skipIfNoCaffe2, skipIfNoLapack -from verify import verify def _remove_test_environment_prefix_from_scope_name(scope_name: str) -> str: diff --git a/test/onnx/test_verification.py b/test/onnx/test_verification.py index 04d5678081b5..f416be34aedb 100644 --- a/test/onnx/test_verification.py +++ b/test/onnx/test_verification.py @@ -9,9 +9,9 @@ import numpy as np import onnx import parameterized import pytorch_test_common +from packaging import version import torch -from packaging import version from torch.onnx import _constants, _experimental, verification from torch.testing._internal import common_utils diff --git a/test/onnx_caffe2/export_onnx_tests_generator.py b/test/onnx_caffe2/export_onnx_tests_generator.py index e81f1277d8ee..43ea9a22a60b 100644 --- a/test/onnx_caffe2/export_onnx_tests_generator.py +++ b/test/onnx_caffe2/export_onnx_tests_generator.py @@ -5,10 +5,10 @@ import traceback import onnx import onnx_test_common - -import torch from onnx import numpy_helper from test_nn import new_module_tests + +import torch from torch.autograd import Variable from torch.testing._internal.common_nn import module_tests diff --git a/test/onnx_caffe2/test_custom_ops.py b/test/onnx_caffe2/test_custom_ops.py index 649db9f663e3..f25ae1b43a84 100644 --- a/test/onnx_caffe2/test_custom_ops.py +++ b/test/onnx_caffe2/test_custom_ops.py @@ -3,12 +3,12 @@ import numpy as np import onnx import pytorch_test_common -import torch -import torch.utils.cpp_extension from test_pytorch_onnx_caffe2 import do_export -from torch.testing._internal import common_utils import caffe2.python.onnx.backend as c2 +import torch +import torch.utils.cpp_extension +from torch.testing._internal import common_utils class TestCaffe2CustomOps(pytorch_test_common.ExportTestCase): diff --git a/test/onnx_caffe2/test_pytorch_helper.py b/test/onnx_caffe2/test_pytorch_helper.py index 778b8553b65c..56a4932a9996 100644 --- a/test/onnx_caffe2/test_pytorch_helper.py +++ b/test/onnx_caffe2/test_pytorch_helper.py @@ -5,16 +5,16 @@ import unittest import numpy as np import pytorch_test_common +from pytorch_helper import PyTorchModule import torch.nn.init as init import torch.onnx -from pytorch_helper import PyTorchModule -from torch import nn -from torch.testing._internal import common_utils -from torch.testing._internal.common_utils import skipIfNoLapack from caffe2.python.core import workspace from caffe2.python.model_helper import ModelHelper +from torch import nn +from torch.testing._internal import common_utils +from torch.testing._internal.common_utils import skipIfNoLapack class TestCaffe2Backend(pytorch_test_common.ExportTestCase): diff --git a/test/onnx_caffe2/test_pytorch_onnx_caffe2.py b/test/onnx_caffe2/test_pytorch_onnx_caffe2.py index dd425ee5b70f..18cba5b73f76 100644 --- a/test/onnx_caffe2/test_pytorch_onnx_caffe2.py +++ b/test/onnx_caffe2/test_pytorch_onnx_caffe2.py @@ -11,9 +11,6 @@ import model_defs.word_language_model as word_language_model import numpy as np import onnx import pytorch_test_common -import torch.onnx -import torch.onnx.operators -import torch.utils.model_zoo as model_zoo import verify from debug_embed_params import run_embed_params from model_defs.lstm_flattening_result import LstmFlatteningResult @@ -33,12 +30,6 @@ from pytorch_test_common import ( skipIfUnsupportedMinOpsetVersion, skipIfUnsupportedOpsetVersion, ) -from torch import nn -from torch.autograd import function, Variable -from torch.nn.utils import rnn as rnn_utils -from torch.onnx import ExportTypes -from torch.testing._internal import common_utils -from torch.testing._internal.common_utils import skipIfNoLapack # Import various models for testing from torchvision.models.alexnet import alexnet @@ -48,10 +39,19 @@ from torchvision.models.resnet import resnet50 from torchvision.models.vgg import vgg16, vgg16_bn, vgg19, vgg19_bn import caffe2.python.onnx.backend as c2 +import torch.onnx +import torch.onnx.operators +import torch.utils.model_zoo as model_zoo from caffe2.python.operator_test.torch_integration_test import ( create_bbox_transform_inputs, generate_rois_rotated, ) +from torch import nn +from torch.autograd import function, Variable +from torch.nn.utils import rnn as rnn_utils +from torch.onnx import ExportTypes +from torch.testing._internal import common_utils +from torch.testing._internal.common_utils import skipIfNoLapack skip = unittest.skip diff --git a/test/onnx_caffe2/test_pytorch_onnx_caffe2_quantized.py b/test/onnx_caffe2/test_pytorch_onnx_caffe2_quantized.py index deb46102c877..372961c000ed 100644 --- a/test/onnx_caffe2/test_pytorch_onnx_caffe2_quantized.py +++ b/test/onnx_caffe2/test_pytorch_onnx_caffe2_quantized.py @@ -5,13 +5,13 @@ import io import numpy as np import onnx import pytorch_test_common + +import caffe2.python.onnx.backend as c2 import torch.ao.nn.quantized as nnq import torch.nn as nn import torch.onnx from torch.testing._internal import common_utils -import caffe2.python.onnx.backend as c2 - class TestQuantizedOps(pytorch_test_common.ExportTestCase): def generic_test( diff --git a/test/onnx_caffe2/test_verify.py b/test/onnx_caffe2/test_verify.py index f5b3000eb9c8..05ca80840459 100644 --- a/test/onnx_caffe2/test_verify.py +++ b/test/onnx_caffe2/test_verify.py @@ -1,12 +1,12 @@ # Owner(s): ["module: onnx"] +from verify import verify + +import caffe2.python.onnx.backend as backend import torch from torch.autograd import Function from torch.nn import Module, Parameter from torch.testing._internal import common_utils -from verify import verify - -import caffe2.python.onnx.backend as backend class TestVerify(common_utils.TestCase): diff --git a/test/package/test_trace_dep/__init__.py b/test/package/test_trace_dep/__init__.py index d6fb2e821677..b3b446aeab98 100644 --- a/test/package/test_trace_dep/__init__.py +++ b/test/package/test_trace_dep/__init__.py @@ -1,6 +1,7 @@ -import torch import yaml +import torch + class SumMod(torch.nn.Module): def forward(self, inp): diff --git a/test/profiler/test_profiler.py b/test/profiler/test_profiler.py index c9591a747d77..38e83d448fdd 100644 --- a/test/profiler/test_profiler.py +++ b/test/profiler/test_profiler.py @@ -32,6 +32,7 @@ from typing import List, Optional from unittest.mock import patch import expecttest + import torch import torch.nn as nn import torch.optim diff --git a/test/scripts/run_cuda_memcheck.py b/test/scripts/run_cuda_memcheck.py index 924048030e33..790f286e58b6 100755 --- a/test/scripts/run_cuda_memcheck.py +++ b/test/scripts/run_cuda_memcheck.py @@ -20,9 +20,10 @@ import subprocess import sys import cuda_memcheck_common as cmc -import torch import tqdm +import torch + ALL_TESTS = [] GPUS = torch.cuda.device_count() diff --git a/test/test_ao_sparsity.py b/test/test_ao_sparsity.py index 37a13ede6d43..ac5f1c1a4e41 100644 --- a/test/test_ao_sparsity.py +++ b/test/test_ao_sparsity.py @@ -28,6 +28,7 @@ from ao.sparsity.test_structured_sparsifier import ( # noqa: F401 # noqa: F401 TestFPGMPruner, TestSaliencyPruner, ) + from torch.testing._internal.common_utils import IS_ARM64, run_tests # Composability diff --git a/test/test_autograd_fallback.py b/test/test_autograd_fallback.py index ec6f01c4c2df..b0361306443a 100644 --- a/test/test_autograd_fallback.py +++ b/test/test_autograd_fallback.py @@ -4,6 +4,7 @@ import contextlib import warnings import numpy as np + import torch from torch.library import _scoped_library, Library from torch.testing._internal.common_utils import ( diff --git a/test/test_binary_ufuncs.py b/test/test_binary_ufuncs.py index 3ed43e6b06c3..faec1b69524b 100644 --- a/test/test_binary_ufuncs.py +++ b/test/test_binary_ufuncs.py @@ -10,6 +10,7 @@ from itertools import chain, product from numbers import Number import numpy as np + import torch import torch.autograd.forward_ad as fwAD diff --git a/test/test_bundled_images.py b/test/test_bundled_images.py index 091bad66c15e..73f51d008bb1 100644 --- a/test/test_bundled_images.py +++ b/test/test_bundled_images.py @@ -4,6 +4,7 @@ import io import cv2 + import torch import torch.utils.bundled_inputs from torch.testing._internal.common_utils import TestCase diff --git a/test/test_compile_benchmark_util.py b/test/test_compile_benchmark_util.py index 7d43b5727b3b..7a3aebb4e444 100644 --- a/test/test_compile_benchmark_util.py +++ b/test/test_compile_benchmark_util.py @@ -8,6 +8,7 @@ from torch.testing._internal.common_utils import run_tests, TEST_CUDA, TestCase try: import tabulate # noqa: F401 # type: ignore[import] + from torch.utils.benchmark.utils.compile import bench_all HAS_TABULATE = True diff --git a/test/test_cpp_api_parity.py b/test/test_cpp_api_parity.py index 3b57b40d6224..6d2cc51fcce3 100644 --- a/test/test_cpp_api_parity.py +++ b/test/test_cpp_api_parity.py @@ -3,9 +3,6 @@ import os -import torch -import torch.testing._internal.common_nn as common_nn -import torch.testing._internal.common_utils as common from cpp_api_parity import ( functional_impl_check, module_impl_check, @@ -15,6 +12,10 @@ from cpp_api_parity import ( from cpp_api_parity.parity_table_parser import parse_parity_tracker_table from cpp_api_parity.utils import is_torch_nn_functional_test +import torch +import torch.testing._internal.common_nn as common_nn +import torch.testing._internal.common_utils as common + # NOTE: turn this on if you want to print source code of all C++ tests (e.g. for debugging purpose) PRINT_CPP_SOURCE = False diff --git a/test/test_custom_ops.py b/test/test_custom_ops.py index 98b3042e50ac..703de349ecbe 100644 --- a/test/test_custom_ops.py +++ b/test/test_custom_ops.py @@ -13,14 +13,14 @@ import torch._custom_ops as custom_ops import torch.testing._internal.optests as optests import torch.utils.cpp_extension + +from functorch import make_fx from torch import Tensor from torch._custom_op.impl import custom_op, CustomOp, infer_schema from torch._utils_internal import get_file_path_2 from torch.testing._internal import custom_op_db from torch.testing._internal.common_cuda import TEST_CUDA from torch.testing._internal.custom_op_db import numpy_nonzero - -from functorch import make_fx from typing import * # noqa: F403 import numpy as np diff --git a/test/test_determination.py b/test/test_determination.py index bf3a24a64e0c..50cc2fa9975d 100644 --- a/test/test_determination.py +++ b/test/test_determination.py @@ -3,6 +3,7 @@ import os import run_test + from torch.testing._internal.common_utils import run_tests, TestCase diff --git a/test/test_dynamic_shapes.py b/test/test_dynamic_shapes.py index 4a2ba0d9867e..d89c8e1a4f36 100644 --- a/test/test_dynamic_shapes.py +++ b/test/test_dynamic_shapes.py @@ -9,6 +9,7 @@ import operator import re import sympy + import torch import torch.fx import torch.nn.functional as F @@ -1490,6 +1491,7 @@ class TestDimConstraints(TestCase): from sympy import Symbol from sympy.solvers.inequalities import reduce_inequalities + from torch._dynamo.source import ( LocalSource, TensorProperty, @@ -1521,6 +1523,7 @@ class TestDimConstraints(TestCase): def test_dim_constraints_solve_full(self): from sympy import Eq, Integer, Ne, Symbol + from torch._dynamo.source import ( LocalSource, TensorProperty, diff --git a/test/test_indexing.py b/test/test_indexing.py index f34fa4c5669b..1ffac7834555 100644 --- a/test/test_indexing.py +++ b/test/test_indexing.py @@ -8,6 +8,7 @@ import warnings from functools import reduce import numpy as np + import torch from torch import tensor diff --git a/test/test_view_ops.py b/test/test_view_ops.py index cb019057ae9f..a88b29f62911 100644 --- a/test/test_view_ops.py +++ b/test/test_view_ops.py @@ -6,6 +6,7 @@ from functools import partial from itertools import combinations, permutations, product import numpy as np + import torch from torch.testing import make_tensor diff --git a/test/torch_np/numpy_tests/core/test_dtype.py b/test/torch_np/numpy_tests/core/test_dtype.py index 23cee32b525d..ccff28135a1f 100644 --- a/test/torch_np/numpy_tests/core/test_dtype.py +++ b/test/torch_np/numpy_tests/core/test_dtype.py @@ -13,6 +13,7 @@ from unittest import skipIf as skipif import pytest from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, diff --git a/test/torch_np/numpy_tests/core/test_einsum.py b/test/torch_np/numpy_tests/core/test_einsum.py index 1dd3b264fcb8..f2dc28e98c27 100644 --- a/test/torch_np/numpy_tests/core/test_einsum.py +++ b/test/torch_np/numpy_tests/core/test_einsum.py @@ -5,8 +5,9 @@ import itertools from unittest import expectedFailure as xfail, skipIf as skipif, SkipTest -import torch._numpy as np from pytest import raises as assert_raises + +import torch._numpy as np from torch._numpy.testing import ( assert_, assert_allclose, diff --git a/test/torch_np/numpy_tests/core/test_getlimits.py b/test/torch_np/numpy_tests/core/test_getlimits.py index 4574cb07c699..ab5b08319db6 100644 --- a/test/torch_np/numpy_tests/core/test_getlimits.py +++ b/test/torch_np/numpy_tests/core/test_getlimits.py @@ -13,6 +13,7 @@ from unittest import skipIf import numpy from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( run_tests, TEST_WITH_TORCHDYNAMO, diff --git a/test/torch_np/numpy_tests/core/test_indexing.py b/test/torch_np/numpy_tests/core/test_indexing.py index 77844e77a6e0..718bd7c8a498 100644 --- a/test/torch_np/numpy_tests/core/test_indexing.py +++ b/test/torch_np/numpy_tests/core/test_indexing.py @@ -13,6 +13,7 @@ from unittest import expectedFailure as xfail, skipIf as skipif, SkipTest import pytest from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, diff --git a/test/torch_np/numpy_tests/core/test_numeric.py b/test/torch_np/numpy_tests/core/test_numeric.py index 5b774d962db2..a6d351b9dc04 100644 --- a/test/torch_np/numpy_tests/core/test_numeric.py +++ b/test/torch_np/numpy_tests/core/test_numeric.py @@ -21,6 +21,7 @@ from unittest import expectedFailure as xfail, skipIf as skipif, SkipTest from hypothesis import given, strategies as st from hypothesis.extra import numpy as hynp from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, diff --git a/test/torch_np/numpy_tests/core/test_numerictypes.py b/test/torch_np/numpy_tests/core/test_numerictypes.py index 462c51873b66..784f4b887076 100644 --- a/test/torch_np/numpy_tests/core/test_numerictypes.py +++ b/test/torch_np/numpy_tests/core/test_numerictypes.py @@ -7,6 +7,7 @@ import sys from unittest import skipIf as skipif from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, diff --git a/test/torch_np/numpy_tests/core/test_scalar_methods.py b/test/torch_np/numpy_tests/core/test_scalar_methods.py index 2e763c6636a8..35bec88b382b 100644 --- a/test/torch_np/numpy_tests/core/test_scalar_methods.py +++ b/test/torch_np/numpy_tests/core/test_scalar_methods.py @@ -14,6 +14,7 @@ from unittest import skipIf as skipif, SkipTest import pytest from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, diff --git a/test/torch_np/numpy_tests/lib/test_type_check.py b/test/torch_np/numpy_tests/lib/test_type_check.py index 96c0ddbc9672..9df29f5a7172 100644 --- a/test/torch_np/numpy_tests/lib/test_type_check.py +++ b/test/torch_np/numpy_tests/lib/test_type_check.py @@ -6,6 +6,7 @@ import functools from unittest import expectedFailure as xfail, skipIf as skipif from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( run_tests, TEST_WITH_TORCHDYNAMO, diff --git a/test/torch_np/numpy_tests/linalg/test_linalg.py b/test/torch_np/numpy_tests/linalg/test_linalg.py index 3a5c21745e24..87f30f23ac86 100644 --- a/test/torch_np/numpy_tests/linalg/test_linalg.py +++ b/test/torch_np/numpy_tests/linalg/test_linalg.py @@ -19,6 +19,7 @@ import pytest from numpy.linalg.linalg import _multi_dot_matrix_chain_order from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, diff --git a/test/torch_np/test_basic.py b/test/torch_np/test_basic.py index 790b40349ce0..f0603e7feb48 100644 --- a/test/torch_np/test_basic.py +++ b/test/torch_np/test_basic.py @@ -5,12 +5,13 @@ import inspect from unittest import expectedFailure as xfail, skipIf as skip import numpy as _np +from pytest import raises as assert_raises + import torch import torch._numpy as w import torch._numpy._ufuncs as _ufuncs import torch._numpy._util as _util -from pytest import raises as assert_raises from torch._numpy.testing import assert_allclose, assert_equal from torch.testing._internal.common_cuda import TEST_CUDA diff --git a/test/torch_np/test_ufuncs_basic.py b/test/torch_np/test_ufuncs_basic.py index 274a3d75618e..6acacf6400b7 100644 --- a/test/torch_np/test_ufuncs_basic.py +++ b/test/torch_np/test_ufuncs_basic.py @@ -14,6 +14,7 @@ import operator from unittest import skipIf as skip, SkipTest from pytest import raises as assert_raises + from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, parametrize, diff --git a/torch/ao/quantization/experimental/adaround_loss.py b/torch/ao/quantization/experimental/adaround_loss.py index 8080d72cc6da..6033d38e507d 100644 --- a/torch/ao/quantization/experimental/adaround_loss.py +++ b/torch/ao/quantization/experimental/adaround_loss.py @@ -1,6 +1,7 @@ from typing import Tuple import numpy as np + import torch from torch.nn import functional as F diff --git a/torch/csrc/lazy/test_mnist.py b/torch/csrc/lazy/test_mnist.py index 20b94437239b..a3a03d9844d3 100644 --- a/torch/csrc/lazy/test_mnist.py +++ b/torch/csrc/lazy/test_mnist.py @@ -2,6 +2,8 @@ import os +from torchvision import datasets, transforms + import torch import torch._lazy import torch._lazy.metrics @@ -10,7 +12,6 @@ import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch.optim.lr_scheduler import StepLR -from torchvision import datasets, transforms torch._lazy.ts_backend.init() diff --git a/torch/fx/experimental/shape_inference/infer_symbol_values.py b/torch/fx/experimental/shape_inference/infer_symbol_values.py index 81c86fe38198..fcdbb0a4aab9 100644 --- a/torch/fx/experimental/shape_inference/infer_symbol_values.py +++ b/torch/fx/experimental/shape_inference/infer_symbol_values.py @@ -4,6 +4,7 @@ from typing import Any, DefaultDict, Dict, List, Tuple, Union import numpy as np import sympy as sp + import torch square_brackets_pattern = r"\[([^]]+)\]"