Skip to content

Commit

Permalink
Apply TorchFix codemods to torchbenchmarks (#2287)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #2287

Reviewed By: zou3519, xuzhao9

Differential Revision: D58301337

fbshipit-source-id: 2bdff7d9652060b5a2cba720cb54689aad66f18a
  • Loading branch information
kit1980 authored and facebook-github-bot committed Jun 10, 2024
1 parent aae0125 commit 37256de
Show file tree
Hide file tree
Showing 24 changed files with 26 additions and 25 deletions.
5 changes: 3 additions & 2 deletions torchbenchmark/e2e_models/vision_resnet50/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tqdm import tqdm

from pathlib import Path
from torchvision import models

# setup environment variable
CURRENT_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
Expand Down Expand Up @@ -56,7 +57,7 @@ def __init__(self, test, batch_size=None, extra_args=[]):
# by default, run 200 epochs
self.num_epochs = 200
# use random init model for train
self.model = torchvision.models.resnet50().to(self.device)
self.model = models.resnet50().to(self.device)
from .resnet import ResNet50
self.model = ResNet50().to(self.device)
self.model.train()
Expand All @@ -66,7 +67,7 @@ def __init__(self, test, batch_size=None, extra_args=[]):
self.scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(self.optimizer, T_max=self.T_max)
else:
# use pretrained model for eval
self.model = torchvision.models.resnet50(pretrained=True).to(self.device)
self.model = models.resnet50(weights=models.ResNet50_Weights.IMAGENET1K_V1).to(self.device)
self.model.eval()

def get_optimizer(self):
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/alexnet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/densenet121/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/functorch_dp_cifar10/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
import torch.optim as optim
import torch.nn as nn
import torchvision.models as models
from torchvision import models
from functorch import make_functional_with_buffers, vmap, grad
from typing import Tuple

Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/lennard_jones/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from functorch import vmap, jacrev
from torch.func import vmap, jacrev
from typing import Tuple

from ...util.model import BenchmarkModel
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/mnasnet1_0/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/mobilenet_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by gen_torchvision_benchmark.py
import torch
import torch.optim as optim
import torchvision.models as models
from torchvision import models
from torch.quantization import quantize_fx
from torchbenchmark.tasks import COMPUTER_VISION
from ...util.model import BenchmarkModel
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/mobilenet_v3_large/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/moco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
import torchvision.models as models
from torchvision import models
from typing import Tuple

from .moco.builder import MoCo
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/moco/main_lincls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import torch.utils.data.distributed
import torchvision.transforms as transforms
import torchvision.datasets as datasets
import torchvision.models as models
from torchvision import models

model_names = sorted(name for name in models.__dict__
if name.islower() and not name.startswith("__")
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/moco/main_moco.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import torch.utils.data.distributed
import torchvision.transforms as transforms
import torchvision.datasets as datasets
import torchvision.models as models
from torchvision import models

from .moco.builder import MoCo

Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/opacus_cifar10/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import torch.optim as optim
import torch.nn as nn
import torch.utils.data as data
import torchvision.models as models
from torchvision import models
from opacus import PrivacyEngine
from opacus.validators.module_validator import ModuleValidator
from typing import Tuple
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/resnet152/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/resnet18/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/resnet50/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/resnet50_quantized_qat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Generated by gen_torchvision_benchmark.py
import torch
import torch.optim as optim
import torchvision.models as models
from torchvision import models
from torch.quantization import quantize_fx
from ...util.model import BenchmarkModel
from torchbenchmark.tasks import COMPUTER_VISION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/resnext50_32x4d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/shufflenet_v2_x1_0/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/squeezenet1_1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from torchbenchmark.tasks import COMPUTER_VISION
import torch.optim as optim
import torch
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/tacotron2/waveglow/glow.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, c):
)

# Sample a random orthonormal matrix to initialize weights
W = torch.qr(torch.FloatTensor(c, c).normal_())[0]
W = torch.linalg.qr(torch.FloatTensor(c, c).normal_())[0]

# Ensure determinant is 1.0 not -1.0
if torch.det(W) < 0:
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/models/vgg16/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from torchbenchmark.util.framework.vision.model_factory import TorchVisionModel
from torchbenchmark.tasks import COMPUTER_VISION
import torchvision.models as models
from torchvision import models

class Model(TorchVisionModel):
task = COMPUTER_VISION.CLASSIFICATION
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/util/framework/vision/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import torch
import torch.optim as optim
import torchvision.models as models
from torchvision import models
from torchbenchmark.util.model import BenchmarkModel


Expand Down
2 changes: 1 addition & 1 deletion userbenchmark/functorch/vmap_hessian_fc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
import torch.nn as nn
from functorch import vmap, jacfwd, jacrev
from torch.func import vmap, jacfwd, jacrev
from .util import BenchmarkCase

# batched hessians of fully connected layers is a popular quantity
Expand Down

0 comments on commit 37256de

Please sign in to comment.