From 727ee853b463772a0751fb4341f05ad395fa4ab2 Mon Sep 17 00:00:00 2001 From: Sergii Dymchenko Date: Mon, 23 Dec 2024 18:21:03 +0000 Subject: [PATCH] Apply TorchFix TOR203 fixes (#143691) Codemodded via `torchfix . --select=TOR203 --fix`. This is a step to unblock https://github.com/pytorch/pytorch/pull/141076 Pull Request resolved: https://github.com/pytorch/pytorch/pull/143691 Approved by: https://github.com/malfet --- benchmarks/profiler_benchmark/resnet_memory_profiler.py | 2 +- functorch/benchmarks/per_sample_grads.py | 2 +- functorch/examples/dp_cifar10/cifar10_opacus.py | 3 +-- functorch/examples/dp_cifar10/cifar10_transforms.py | 3 +-- functorch/examples/maml_omniglot/support/omniglot_loaders.py | 2 +- test/functorch/test_eager_transforms.py | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/benchmarks/profiler_benchmark/resnet_memory_profiler.py b/benchmarks/profiler_benchmark/resnet_memory_profiler.py index c18d456c83ce..22c2fb5f282c 100644 --- a/benchmarks/profiler_benchmark/resnet_memory_profiler.py +++ b/benchmarks/profiler_benchmark/resnet_memory_profiler.py @@ -1,4 +1,4 @@ -import torchvision.models as models +from torchvision import models import torch import torch.autograd.profiler as profiler diff --git a/functorch/benchmarks/per_sample_grads.py b/functorch/benchmarks/per_sample_grads.py index 95b76252244b..cff92e634269 100644 --- a/functorch/benchmarks/per_sample_grads.py +++ b/functorch/benchmarks/per_sample_grads.py @@ -1,8 +1,8 @@ import time -import torchvision.models as models from opacus import PrivacyEngine from opacus.utils.module_modification import convert_batchnorm_modules +from torchvision import models import torch import torch.nn as nn diff --git a/functorch/examples/dp_cifar10/cifar10_opacus.py b/functorch/examples/dp_cifar10/cifar10_opacus.py index 236763ac3171..6025783e1482 100644 --- a/functorch/examples/dp_cifar10/cifar10_opacus.py +++ b/functorch/examples/dp_cifar10/cifar10_opacus.py @@ -12,9 +12,8 @@ import sys from datetime import datetime, timedelta import numpy as np -import torchvision.transforms as transforms from opacus import PrivacyEngine -from torchvision import models +from torchvision import models, transforms from torchvision.datasets import CIFAR10 from tqdm import tqdm diff --git a/functorch/examples/dp_cifar10/cifar10_transforms.py b/functorch/examples/dp_cifar10/cifar10_transforms.py index 662472b55fcc..fdf14c86efb4 100644 --- a/functorch/examples/dp_cifar10/cifar10_transforms.py +++ b/functorch/examples/dp_cifar10/cifar10_transforms.py @@ -12,8 +12,7 @@ import sys from datetime import datetime, timedelta import numpy as np -import torchvision.transforms as transforms -from torchvision import models +from torchvision import models, transforms from torchvision.datasets import CIFAR10 from tqdm import tqdm diff --git a/functorch/examples/maml_omniglot/support/omniglot_loaders.py b/functorch/examples/maml_omniglot/support/omniglot_loaders.py index 4390caa717b5..ccba01ce181e 100644 --- a/functorch/examples/maml_omniglot/support/omniglot_loaders.py +++ b/functorch/examples/maml_omniglot/support/omniglot_loaders.py @@ -22,8 +22,8 @@ import os import os.path import numpy as np -import torchvision.transforms as transforms from PIL import Image +from torchvision import transforms import torch import torch.utils.data as data diff --git a/test/functorch/test_eager_transforms.py b/test/functorch/test_eager_transforms.py index ce0c43cdbc62..34ad36cbb417 100644 --- a/test/functorch/test_eager_transforms.py +++ b/test/functorch/test_eager_transforms.py @@ -4541,7 +4541,7 @@ class TestExamplesCorrectness(TestCase): @unittest.skipIf(not USE_TORCHVISION, "test requires torchvision") @parametrize("mechanism", ["make_functional", "functional_call"]) def test_resnet18_per_sample_grads(self, device, mechanism): - import torchvision.models as models + from torchvision import models model = models.__dict__["resnet18"]( pretrained=False, norm_layer=(lambda c: nn.GroupNorm(min(32, c), c))