Skip to content

Commit

Permalink
[2/N][Easy] fix typo for usort config in pyproject.toml (kown -…
Browse files Browse the repository at this point in the history
…> `known`): sort caffe2 (#127123)

The `usort` config in `pyproject.toml` has no effect due to a typo. Fixing the typo make `usort` do more and generate the changes in the PR. Except `pyproject.toml`, all changes are generated by `lintrunner -a --take UFMT --all-files`.

Pull Request resolved: #127123
Approved by: https://github.com/Skylion007
ghstack dependencies: #127122
  • Loading branch information
XuehaiPan authored and pytorchmergebot committed May 25, 2024
1 parent da141b0 commit 0dae2ba
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 30 deletions.
3 changes: 2 additions & 1 deletion benchmarks/framework_overhead_benchmark/C2Module.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
from caffe2.python import core, workspace

from utils import NUM_LOOP_ITERS

from caffe2.python import core, workspace

workspace.GlobalInit(["caffe2"])


Expand Down
1 change: 1 addition & 0 deletions benchmarks/operator_benchmark/benchmark_caffe2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import benchmark_utils
from benchmark_test_generator import _register_test

from caffe2.proto import caffe2_pb2
from caffe2.python import core, workspace

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/operator_benchmark/c2/add_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core

import operator_benchmark as op_bench
from caffe2.python import core


"""Microbenchmarks for element-wise Add operator. Supports both Caffe2/PyTorch."""
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/operator_benchmark/c2/batch_box_cox_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core

import operator_benchmark as op_bench
from caffe2.python import core


"""Microbenchmarks for BatchBoxCox operator."""
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/operator_benchmark/c2/batch_gather_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import benchmark_caffe2 as op_bench_c2
import numpy
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core

import operator_benchmark as op_bench
from caffe2.python import core


"""Microbenchmarks for element-wise BatchGather operator."""
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/operator_benchmark/c2/clip_ranges_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core, dyndep

import operator_benchmark as op_bench
from caffe2.python import core, dyndep

dyndep.InitOpsLibrary("@/caffe2/caffe2/fb/operators:clip_ranges_op")

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/operator_benchmark/c2/concat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core

import operator_benchmark as op_bench
from caffe2.python import core


"""Microbenchmarks for Concat operator. Supports both Caffe2/PyTorch."""
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/operator_benchmark/c2/matmul_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core

import operator_benchmark as op_bench
from caffe2.python import core

"""Microbenchmarks for MatMul operator"""

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/operator_benchmark/c2/quantile_op_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core

import operator_benchmark as op_bench
from caffe2.python import core


"""Microbenchmarks for QuantileOp operator."""
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/operator_benchmark/c2/replace_nan_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core

import operator_benchmark as op_bench
from caffe2.python import core


"""Microbenchmarks for element-wise ReplaceNaN operator."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import operator_benchmark as op_bench

from caffe2.python import core


Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ include_trailing_comma = true


[tool.usort.known]
first_party = ["caffe2"]
standard_library = ["typing_extensions"]

[tool.usort.kown]
first_party = ["caffe2", "torch", "torchgen", "functorch", "tests"]
first_party = ["torch", "torchgen", "functorch", "tests"]


[tool.ruff]
Expand Down
9 changes: 5 additions & 4 deletions scripts/model_zoo/update-models-from-caffe2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
from urllib.request import urlretrieve

import boto3
import caffe2.python.onnx.backend
import caffe2.python.onnx.frontend
import caffe2.python.workspace as c2_workspace
import numpy as np
import onnx
import onnx.backend
from onnx import numpy_helper

import caffe2.python.onnx.backend
import caffe2.python.onnx.frontend
import caffe2.python.workspace as c2_workspace
from caffe2.proto import caffe2_pb2

from caffe2.python.models.download import (
deleteDirectory,
downloadFromURLToFile,
getURLFromName,
)
from onnx import numpy_helper


"""A script converting Caffe2 models to ONNX, and updating ONNX model zoos.
Expand Down
4 changes: 2 additions & 2 deletions test/onnx/debug_embed_params.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import sys

import caffe2.python.onnx.backend as c2

import onnx
import pytorch_test_common
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
Expand Down
1 change: 1 addition & 0 deletions test/onnx/pytorch_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import onnx

import torch.onnx

from caffe2.python.core import BlobReference, Net
from caffe2.python.onnx.backend import Caffe2Backend

Expand Down
4 changes: 2 additions & 2 deletions test/onnx_caffe2/test_caffe2_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import glob
import os

import caffe2.python.onnx.backend as c2

import numpy as np
import onnx.backend.test
from onnx import numpy_helper

import caffe2.python.onnx.backend as c2


def load_tensor_as_numpy_array(f):
tensor = onnx.TensorProto()
Expand Down
3 changes: 2 additions & 1 deletion test/onnx_caffe2/test_custom_ops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Owner(s): ["module: onnx"]

import caffe2.python.onnx.backend as c2
import numpy as np
import onnx
import pytorch_test_common
Expand All @@ -9,6 +8,8 @@
from test_pytorch_onnx_caffe2 import do_export
from torch.testing._internal import common_utils

import caffe2.python.onnx.backend as c2


class TestCaffe2CustomOps(pytorch_test_common.ExportTestCase):
def test_custom_add(self):
Expand Down
5 changes: 3 additions & 2 deletions test/onnx_caffe2/test_pytorch_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import torch.nn.init as init
import torch.onnx
from caffe2.python.core import workspace
from caffe2.python.model_helper import ModelHelper
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


class TestCaffe2Backend(pytorch_test_common.ExportTestCase):
@skipIfNoLapack
Expand Down
12 changes: 6 additions & 6 deletions test/onnx_caffe2/test_pytorch_onnx_caffe2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import unittest
from typing import Tuple

import caffe2.python.onnx.backend as c2

import model_defs.dcgan as dcgan
import model_defs.word_language_model as word_language_model
import numpy as np
Expand All @@ -17,10 +15,6 @@
import torch.onnx.operators
import torch.utils.model_zoo as model_zoo
import verify
from caffe2.python.operator_test.torch_integration_test import (
create_bbox_transform_inputs,
generate_rois_rotated,
)
from debug_embed_params import run_embed_params
from model_defs.lstm_flattening_result import LstmFlatteningResult
from model_defs.mnist import MNIST
Expand Down Expand Up @@ -53,6 +47,12 @@
from torchvision.models.resnet import resnet50
from torchvision.models.vgg import vgg16, vgg16_bn, vgg19, vgg19_bn

import caffe2.python.onnx.backend as c2
from caffe2.python.operator_test.torch_integration_test import (
create_bbox_transform_inputs,
generate_rois_rotated,
)

skip = unittest.skip


Expand Down
4 changes: 2 additions & 2 deletions test/onnx_caffe2/test_pytorch_onnx_caffe2_quantized.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import io

import caffe2.python.onnx.backend as c2

import numpy as np
import onnx
import pytorch_test_common
Expand All @@ -12,6 +10,8 @@
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(
Expand Down
3 changes: 2 additions & 1 deletion test/onnx_caffe2/test_verify.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Owner(s): ["module: onnx"]

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):
maxDiff = None
Expand Down

0 comments on commit 0dae2ba

Please sign in to comment.