Skip to content

Commit 146b855

Browse files
committed
chore: linting for the remaining files
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent 336393b commit 146b855

File tree

13 files changed

+55
-41
lines changed

13 files changed

+55
-41
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ repos:
3838
rev: 'v1.4.1'
3939
hooks:
4040
- id: mypy
41-
exclude: "^py/torch_tensorrt/fx"
41+
exclude: "^py/torch_tensorrt/fx|^examples|^tests|^tools"
4242
- repo: local
4343
hooks:
4444
- id: dont-commit-upstream

core/conversion/evaluators/aten.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ DEFINE_ARITHMATIC_TWO_INPUT_EVALUATOR(
103103
"aten::pow.float_int(float a, int b) -> (float)",
104104
}));
105105

106-
DEFINE_TWO_INPUT_SIMPLE_EVALUATOR(
107-
and,
108-
"aten::__and__",
109-
a&& b,
110-
bool,
111-
std::set<std::string>({"aten::__and__(int a, int b) -> (bool)", "aten::__and__.bool(bool a, bool b) -> (bool)"}));
106+
DEFINE_TWO_INPUT_SIMPLE_EVALUATOR(and, "aten::__and__", a&& b, bool, std::set<std::string>({"aten::__and__(int a, int b) -> (bool)", "aten::__and__.bool(bool a, bool b) -> (bool)"}));
112107
DEFINE_TWO_INPUT_SIMPLE_EVALUATOR(or, "aten::__or__", a || b, bool, {"aten::__or__(int a, int b) -> (bool)"});
113108
DEFINE_TWO_INPUT_SIMPLE_EVALUATOR(
114109
xor,

docsrc/getting_started/getting_started_with_windows.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Building With Visual Studio Code
117117
e.g. /.vscode/settings.json
118118

119119
.. code-block:: json
120-
120+
121121
{
122122
"cmake.generator": "Ninja",
123123
"cmake.configureSettings": {

examples/fx/hugging_face_torchdynamo_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def check_correctness(args, mod, inputs, optimize_ctx, optimize_name):
218218

219219
synchronize = torch.cuda.synchronize
220220

221+
221222
# timing function to record the repeated run time
222223
def timed(model, model_iter_fn, train_inputs, timings=1, return_result=False):
223224
synchronize()

examples/int8/training/vgg16/finetune_qat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def calibrate_model(
184184

185185

186186
def main():
187-
188187
global state
189188
global classes
190189
global writer

examples/torchtrt_runtime_example/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import torch.nn as nn
33
import torch_tensorrt as torchtrt
44

5+
56
# create a simple norm layer.
67
# This norm layer uses NormalizePlugin from Torch-TensorRT
78
class Norm(torch.nn.Module):
@@ -27,7 +28,6 @@ def forward(self, x):
2728

2829

2930
def main():
30-
3131
model = ConvGelu().eval().cuda()
3232
scripted_model = torch.jit.script(model)
3333

tests/py/dynamo/backend/test_backend_compiler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def forward(self, x, y):
7474
torch.randint(1, 40, (16, 7, 5), dtype=torch.int).cuda(),
7575
]
7676

77-
(unexpected_ops_seen, _, partitioned_graphs,) = lower_graph_testing(
77+
(
78+
unexpected_ops_seen,
79+
_,
80+
partitioned_graphs,
81+
) = lower_graph_testing(
7882
fx_graph,
7983
inputs,
8084
unexpected_ops=unexpected_ops,

tests/py/dynamo/backend/test_partitioning.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ def forward(self, x, y):
9393
]
9494

9595
fx_graph = torch.fx.symbolic_trace(PartiallySupportedMultiOp())
96-
(unexpected_ops_seen, _, partitioned_graphs,) = lower_graph_testing(
96+
(
97+
unexpected_ops_seen,
98+
_,
99+
partitioned_graphs,
100+
) = lower_graph_testing(
97101
fx_graph,
98102
inputs,
99103
unexpected_ops=unexpected_ops,

tests/py/ts/api/test_classes.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def test_infer_from_example_tensor(self):
104104

105105
example_tensor = torch.randn(shape).half()
106106
i = torchtrt.Input.from_tensor(example_tensor)
107-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
107+
ts_i = torchtrt.ts.TorchScriptInput(
108+
shape=i.shape, dtype=i.dtype, format=i.format
109+
)
108110
self.assertTrue(self._verify_correctness(ts_i, target))
109111

110112
def test_static_shape(self):
@@ -120,27 +122,39 @@ def test_static_shape(self):
120122
}
121123

122124
i = torchtrt.Input(shape)
123-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
125+
ts_i = torchtrt.ts.TorchScriptInput(
126+
shape=i.shape, dtype=i.dtype, format=i.format
127+
)
124128
self.assertTrue(self._verify_correctness(ts_i, target))
125129

126130
i = torchtrt.Input(tuple(shape))
127-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
131+
ts_i = torchtrt.ts.TorchScriptInput(
132+
shape=i.shape, dtype=i.dtype, format=i.format
133+
)
128134
self.assertTrue(self._verify_correctness(ts_i, target))
129135

130136
i = torchtrt.Input(torch.randn(shape).shape)
131-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
137+
ts_i = torchtrt.ts.TorchScriptInput(
138+
shape=i.shape, dtype=i.dtype, format=i.format
139+
)
132140
self.assertTrue(self._verify_correctness(ts_i, target))
133141

134142
i = torchtrt.Input(shape=shape)
135-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
143+
ts_i = torchtrt.ts.TorchScriptInput(
144+
shape=i.shape, dtype=i.dtype, format=i.format
145+
)
136146
self.assertTrue(self._verify_correctness(ts_i, target))
137147

138148
i = torchtrt.Input(shape=tuple(shape))
139-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
149+
ts_i = torchtrt.ts.TorchScriptInput(
150+
shape=i.shape, dtype=i.dtype, format=i.format
151+
)
140152
self.assertTrue(self._verify_correctness(ts_i, target))
141153

142154
i = torchtrt.Input(shape=torch.randn(shape).shape)
143-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
155+
ts_i = torchtrt.ts.TorchScriptInput(
156+
shape=i.shape, dtype=i.dtype, format=i.format
157+
)
144158
self.assertTrue(self._verify_correctness(ts_i, target))
145159

146160
def test_data_type(self):
@@ -156,11 +170,15 @@ def test_data_type(self):
156170
}
157171

158172
i = torchtrt.Input(shape, dtype=torchtrt.dtype.half)
159-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
173+
ts_i = torchtrt.ts.TorchScriptInput(
174+
shape=i.shape, dtype=i.dtype, format=i.format
175+
)
160176
self.assertTrue(self._verify_correctness(ts_i, target))
161177

162178
i = torchtrt.Input(shape, dtype=torch.half)
163-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
179+
ts_i = torchtrt.ts.TorchScriptInput(
180+
shape=i.shape, dtype=i.dtype, format=i.format
181+
)
164182
self.assertTrue(self._verify_correctness(ts_i, target))
165183

166184
def test_tensor_format(self):
@@ -176,11 +194,15 @@ def test_tensor_format(self):
176194
}
177195

178196
i = torchtrt.Input(shape, format=torchtrt.TensorFormat.channels_last)
179-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
197+
ts_i = torchtrt.ts.TorchScriptInput(
198+
shape=i.shape, dtype=i.dtype, format=i.format
199+
)
180200
self.assertTrue(self._verify_correctness(ts_i, target))
181201

182202
i = torchtrt.Input(shape, format=torch.channels_last)
183-
ts_i = torchtrt.ts.TorchScriptInput(shape=i.shape, dtype=i.dtype, format=i.format)
203+
ts_i = torchtrt.ts.TorchScriptInput(
204+
shape=i.shape, dtype=i.dtype, format=i.format
205+
)
184206
self.assertTrue(self._verify_correctness(ts_i, target))
185207

186208
def test_dynamic_shape(self):

tests/py/ts/api/test_collections.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def find_repo_root(max_depth=10):
2323

2424
class TestStandardTensorInput(unittest.TestCase):
2525
def test_compile(self):
26-
2726
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
2827
self.model = (
2928
torch.jit.load(MODULE_DIR + "/standard_tensor_input_scripted.jit.pt")
@@ -52,7 +51,6 @@ def test_compile(self):
5251

5352
class TestStandardTensorInputLong(unittest.TestCase):
5453
def test_compile(self):
55-
5654
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
5755
self.model = (
5856
torch.jit.load(MODULE_DIR + "/standard_tensor_input_scripted.jit.pt")
@@ -82,7 +80,6 @@ def test_compile(self):
8280

8381
class TestStandardTensorInputDomain(unittest.TestCase):
8482
def test_compile(self):
85-
8683
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
8784
self.model = (
8885
torch.jit.load(MODULE_DIR + "/standard_tensor_input_scripted.jit.pt")
@@ -111,7 +108,6 @@ def test_compile(self):
111108

112109
class TestTupleInput(unittest.TestCase):
113110
def test_compile(self):
114-
115111
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
116112
self.model = (
117113
torch.jit.load(MODULE_DIR + "/tuple_input_scripted.jit.pt")
@@ -140,7 +136,6 @@ def test_compile(self):
140136

141137
class TestListInput(unittest.TestCase):
142138
def test_compile(self):
143-
144139
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
145140
self.model = (
146141
torch.jit.load(MODULE_DIR + "/list_input_scripted.jit.pt").eval().to("cuda")
@@ -167,7 +162,6 @@ def test_compile(self):
167162

168163
class TestTupleInputOutput(unittest.TestCase):
169164
def test_compile(self):
170-
171165
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
172166
self.model = (
173167
torch.jit.load(MODULE_DIR + "/tuple_input_output_scripted.jit.pt")
@@ -187,7 +181,7 @@ def test_compile(self):
187181
trt_mod = torchtrt.ts.compile(self.model, **compile_spec)
188182
trt_out = trt_mod((self.input, self.input))
189183
pyt_out = self.model((self.input, self.input))
190-
for (t, p) in zip(trt_out, pyt_out):
184+
for t, p in zip(trt_out, pyt_out):
191185
cos_sim = cosine_similarity(t, p)
192186
self.assertTrue(
193187
cos_sim > COSINE_THRESHOLD,
@@ -215,7 +209,7 @@ def test_compile_full_compilation(self):
215209
trt_mod = torchtrt.ts.compile(self.model, **compile_spec)
216210
trt_out = trt_mod((self.input, self.input))
217211
pyt_out = self.model((self.input, self.input))
218-
for (t, p) in zip(trt_out, pyt_out):
212+
for t, p in zip(trt_out, pyt_out):
219213
cos_sim = cosine_similarity(t, p)
220214
self.assertTrue(
221215
cos_sim > COSINE_THRESHOLD,
@@ -225,7 +219,6 @@ def test_compile_full_compilation(self):
225219

226220
class TestListInputOutput(unittest.TestCase):
227221
def test_compile(self):
228-
229222
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
230223
self.model = (
231224
torch.jit.load(MODULE_DIR + "/list_input_output_scripted.jit.pt")
@@ -246,15 +239,14 @@ def test_compile(self):
246239
trt_out = trt_mod((self.input, self.input))
247240
pyt_out = self.model((self.input, self.input))
248241

249-
for (t, p) in zip(trt_out, pyt_out):
242+
for t, p in zip(trt_out, pyt_out):
250243
cos_sim = cosine_similarity(t, p)
251244
self.assertTrue(
252245
cos_sim > COSINE_THRESHOLD,
253246
msg=f"list_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
254247
)
255248

256249
def test_compile_full_compilation(self):
257-
258250
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
259251
self.model = (
260252
torch.jit.load(MODULE_DIR + "/list_input_output_scripted.jit.pt")
@@ -276,7 +268,7 @@ def test_compile_full_compilation(self):
276268
trt_out = trt_mod((self.input, self.input))
277269
pyt_out = self.model((self.input, self.input))
278270

279-
for (t, p) in zip(trt_out, pyt_out):
271+
for t, p in zip(trt_out, pyt_out):
280272
cos_sim = cosine_similarity(t, p)
281273
self.assertTrue(
282274
cos_sim > COSINE_THRESHOLD,
@@ -286,7 +278,6 @@ def test_compile_full_compilation(self):
286278

287279
class TestListInputTupleOutput(unittest.TestCase):
288280
def test_compile(self):
289-
290281
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
291282
self.model = (
292283
torch.jit.load(MODULE_DIR + "/list_input_tuple_output_scripted.jit.pt")
@@ -306,15 +297,14 @@ def test_compile(self):
306297
trt_mod = torchtrt.ts.compile(self.model, **compile_spec)
307298
trt_out = trt_mod((self.input, self.input))
308299
pyt_out = self.model((self.input, self.input))
309-
for (t, p) in zip(trt_out, pyt_out):
300+
for t, p in zip(trt_out, pyt_out):
310301
cos_sim = cosine_similarity(t, p)
311302
self.assertTrue(
312303
cos_sim > COSINE_THRESHOLD,
313304
msg=f"list_input_tuple_output_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
314305
)
315306

316307
def test_compile_full_compilation(self):
317-
318308
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
319309
self.model = (
320310
torch.jit.load(MODULE_DIR + "/list_input_tuple_output_scripted.jit.pt")
@@ -335,7 +325,7 @@ def test_compile_full_compilation(self):
335325
trt_mod = torchtrt.ts.compile(self.model, **compile_spec)
336326
trt_out = trt_mod((self.input, self.input))
337327
pyt_out = self.model((self.input, self.input))
338-
for (t, p) in zip(trt_out, pyt_out):
328+
for t, p in zip(trt_out, pyt_out):
339329
cos_sim = cosine_similarity(t, p)
340330
self.assertTrue(
341331
cos_sim > COSINE_THRESHOLD,

tests/py/ts/ptq/test_ptq_dataloader_calibrator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def compute_accuracy(testing_dataloader, model):
5151

5252
class TestAccuracy(unittest.TestCase):
5353
def test_compile_script(self):
54-
5554
self.model = (
5655
torch.jit.load(MODULE_DIR + "/trained_vgg16.jit.pt").eval().to("cuda")
5756
)

tools/perf/hub.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def main():
145145
# Creating an empty manifest file for overwriting post setup
146146
os.system("touch {}".format(MANIFEST_FILE))
147147
else:
148-
149148
# Load manifest if already exists
150149
with open(MANIFEST_FILE, "r") as f:
151150
manifest = json.load(f)

tools/perf/perf_run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
WARMUP_ITER = 10
3434
results = []
3535

36+
3637
# YAML Parser class for parsing the run configurations
3738
class ConfigParser:
3839
def __init__(self, config_file):

0 commit comments

Comments
 (0)