Skip to content

Commit e61fd1a

Browse files
amyreeseWei Wei
authored andcommitted
[codemod][usort] apply import merging for fbcode (3 of 11)
Summary: Applies new import merging and sorting from µsort v1.0. When merging imports, µsort will make a best-effort to move associated comments to match merged elements, but there are known limitations due to the diynamic nature of Python and developer tooling. These changes should not produce any dangerous runtime changes, but may require touch-ups to satisfy linters and other tooling. Note that µsort uses case-insensitive, lexicographical sorting, which results in a different ordering compared to isort. This provides a more consistent sorting order, matching the case-insensitive order used when sorting import statements by module name, and ensures that "frog", "FROG", and "Frog" always sort next to each other. For details on µsort's sorting and merging semantics, see the user guide: https://usort.readthedocs.io/en/stable/guide.html#sorting Reviewed By: lisroach Differential Revision: D36402148 fbshipit-source-id: 8eab032f38c0af6c83b38e18cfb69506e32fa53e
1 parent b503d47 commit e61fd1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+89
-136
lines changed

fx/converter_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Dict, Any
1+
from typing import Any, Callable, Dict
22

33
from torch.fx.node import Target
44

fx/converters/acc_ops_converters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import math
33
import operator
44
import warnings
5-
from typing import Dict, Tuple, Sequence, cast, Optional, Union
5+
from typing import cast, Dict, Optional, Sequence, Tuple, Union
66

77
import fx2trt_oss.tracer.acc_tracer.acc_ops as acc_ops
88
import numpy as np
@@ -13,12 +13,12 @@
1313
from fx2trt_oss.fx.converter_registry import tensorrt_converter
1414
from fx2trt_oss.fx.types import * # noqa: F403
1515
from fx2trt_oss.fx.utils import (
16+
get_dynamic_dims,
1617
torch_dtype_from_trt,
1718
torch_dtype_to_trt,
18-
get_dynamic_dims,
1919
)
2020
from torch.fx.immutable_collections import immutable_list
21-
from torch.fx.node import Target, Argument
21+
from torch.fx.node import Argument, Target
2222

2323
from .converter_utils import * # noqa: F403
2424

fx/converters/adaptive_avgpool.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import torch
44
from fx2trt_oss.fx.converter_registry import tensorrt_converter
55

6-
from .converter_utils import (
7-
mark_as_int8_layer,
8-
extend_mod_attr_to_tuple,
9-
)
6+
from .converter_utils import extend_mod_attr_to_tuple, mark_as_int8_layer
107

118

129
@tensorrt_converter(torch.nn.modules.pooling.AdaptiveAvgPool2d)

fx/converters/batchnorm.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
import torch
66
from fx2trt_oss.fx.converter_registry import tensorrt_converter
77

8-
from .converter_utils import (
9-
mark_as_int8_layer,
10-
to_numpy,
11-
get_dyn_range,
12-
)
8+
from .converter_utils import get_dyn_range, mark_as_int8_layer, to_numpy
139

1410

1511
def common_batchnorm(network, mod, input_val, layer_name, is_quantized):

fx/converters/converter_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import operator
22
import warnings
3-
from typing import Any, Tuple, Sequence, Union, List, Optional, Dict, Callable
3+
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
44

55
import numpy as np
66

77
# @manual=//deeplearning/trt/python:py_tensorrt
88
import tensorrt as trt
99
import torch
1010
from fx2trt_oss.fx.types import (
11-
TRTNetwork,
12-
TRTTensor,
13-
TRTLayer,
14-
TRTPluginFieldCollection,
15-
TRTPlugin,
11+
Shape,
1612
TRTDataType,
1713
TRTElementWiseOp,
18-
Shape,
14+
TRTLayer,
15+
TRTNetwork,
16+
TRTPlugin,
17+
TRTPluginFieldCollection,
18+
TRTTensor,
1919
)
2020
from fx2trt_oss.fx.utils import torch_dtype_from_trt
21-
from torch.fx.node import Target, Argument
21+
from torch.fx.node import Argument, Target
2222

2323

2424
def get_trt_plugin(

fx/converters/convolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
from .converter_utils import (
88
extend_mod_attr_to_tuple,
9+
get_dyn_range,
910
mark_as_int8_layer,
1011
to_numpy,
11-
get_dyn_range,
1212
)
1313

1414

fx/converters/linear.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import torch
44
from fx2trt_oss.fx.converter_registry import tensorrt_converter
55

6-
from .converter_utils import (
7-
mark_as_int8_layer,
8-
to_numpy,
9-
get_dyn_range,
10-
)
6+
from .converter_utils import get_dyn_range, mark_as_int8_layer, to_numpy
117

128

139
def common_linear(network, mod, input_val, layer_name, is_quantized):

fx/converters/maxpool.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import torch
44
from fx2trt_oss.fx.converter_registry import tensorrt_converter
55

6-
from .converter_utils import (
7-
mark_as_int8_layer,
8-
extend_mod_attr_to_tuple,
9-
)
6+
from .converter_utils import extend_mod_attr_to_tuple, mark_as_int8_layer
107

118

129
def common_maxpool(network, mod, dimension, input_val, layer_name):

fx/converters/quantization.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import torch
44
from fx2trt_oss.fx.converter_registry import tensorrt_converter
55

6-
from .converter_utils import (
7-
get_dyn_range,
8-
get_inputs_from_args_and_kwargs,
9-
)
6+
from .converter_utils import get_dyn_range, get_inputs_from_args_and_kwargs
107

118

129
quantize_per_tensor_inputs = ["input", "scale", "zero_point", "dtype"]

fx/example/fx2trt_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import torch
55
import torch.fx
66
import torch.nn as nn
7-
from fx2trt_oss.fx import TRTInterpreter, InputTensorSpec, TRTModule
7+
from fx2trt_oss.fx import InputTensorSpec, TRTInterpreter, TRTModule
88
from fx2trt_oss.fx.tools.trt_splitter import TRTSplitter
99

1010

0 commit comments

Comments
 (0)