Skip to content

Commit ed75e9d

Browse files
committed
chore: Linter fixes
Signed-off-by: Dheeraj Peri <[email protected]>
1 parent 7e6b36c commit ed75e9d

24 files changed

+227
-68
lines changed

.github/workflows/docgen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Set up Python 3.9.4
3232
uses: actions/setup-python@v2
3333
with:
34-
python-version: 3.9.4
34+
python-version: 3.9.4
3535
- uses: actions/checkout@v2
3636
with:
3737
ref: ${{github.head_ref}}

.github/workflows/linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
pip3 install -r $GITHUB_WORKSPACE/.github/scripts/requirements.txt
4040
pip3 install -r $GITHUB_WORKSPACE/requirements-dev.txt
4141
- name: Lint C++
42-
run: |
42+
run: |
4343
cd $GITHUB_WORKSPACE
4444
python3 $GITHUB_WORKSPACE/.github/scripts/run_cpp_linter.py
4545
env:

noxfile.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
print("Using dependencies from host python")
3232

3333
# Set epochs to train VGG model for accuracy tests
34-
EPOCHS=25
34+
EPOCHS = 25
3535

3636
SUPPORTED_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
3737

3838
nox.options.sessions = [
3939
"l0_api_tests-" + "{}.{}".format(sys.version_info.major, sys.version_info.minor)
4040
]
4141

42+
4243
def install_deps(session):
4344
print("Installing deps")
4445
session.install("-r", os.path.join(TOP_DIR, "py", "requirements.txt"))
@@ -110,7 +111,9 @@ def train_model(session):
110111
str(EPOCHS),
111112
)
112113

113-
session.run_always("python", "export_ckpt.py", "vgg16_ckpts/ckpt_epoch" + str(EPOCHS) + ".pth")
114+
session.run_always(
115+
"python", "export_ckpt.py", "vgg16_ckpts/ckpt_epoch" + str(EPOCHS) + ".pth"
116+
)
114117

115118

116119
def finetune_model(session):
@@ -135,15 +138,15 @@ def finetune_model(session):
135138
"--start-from",
136139
str(EPOCHS),
137140
"--epochs",
138-
str(EPOCHS+1),
141+
str(EPOCHS + 1),
139142
env={"PYTHONPATH": PYT_PATH},
140143
)
141144

142145
# Export model
143146
session.run_always(
144147
"python",
145148
"export_qat.py",
146-
"vgg16_ckpts/ckpt_epoch" + str(EPOCHS+1) + ".pth",
149+
"vgg16_ckpts/ckpt_epoch" + str(EPOCHS + 1) + ".pth",
147150
env={"PYTHONPATH": PYT_PATH},
148151
)
149152
else:
@@ -161,11 +164,15 @@ def finetune_model(session):
161164
"--start-from",
162165
str(EPOCHS),
163166
"--epochs",
164-
str(EPOCHS+1),
167+
str(EPOCHS + 1),
165168
)
166169

167170
# Export model
168-
session.run_always("python", "export_qat.py", "vgg16_ckpts/ckpt_epoch" + str(EPOCHS+1) + ".pth")
171+
session.run_always(
172+
"python",
173+
"export_qat.py",
174+
"vgg16_ckpts/ckpt_epoch" + str(EPOCHS + 1) + ".pth",
175+
)
169176

170177

171178
def cleanup(session):
@@ -195,6 +202,7 @@ def run_base_tests(session):
195202
else:
196203
session.run_always("pytest", test)
197204

205+
198206
def run_model_tests(session):
199207
print("Running model tests")
200208
session.chdir(os.path.join(TOP_DIR, "tests/py"))
@@ -258,7 +266,7 @@ def run_trt_compatibility_tests(session):
258266
session.chdir(os.path.join(TOP_DIR, "tests/py"))
259267
tests = [
260268
"integrations/test_trt_intercompatibility.py",
261-
#"ptq/test_ptq_trt_calibrator.py",
269+
# "ptq/test_ptq_trt_calibrator.py",
262270
]
263271
for test in tests:
264272
if USE_HOST_DEPS:
@@ -310,6 +318,7 @@ def run_l0_dla_tests(session):
310318
run_base_tests(session)
311319
cleanup(session)
312320

321+
313322
def run_l1_model_tests(session):
314323
if not USE_HOST_DEPS:
315324
install_deps(session)
@@ -318,6 +327,7 @@ def run_l1_model_tests(session):
318327
run_model_tests(session)
319328
cleanup(session)
320329

330+
321331
def run_l1_int8_accuracy_tests(session):
322332
if not USE_HOST_DEPS:
323333
install_deps(session)
@@ -352,16 +362,19 @@ def l0_api_tests(session):
352362
"""When a developer needs to check correctness for a PR or something"""
353363
run_l0_api_tests(session)
354364

365+
355366
@nox.session(python=SUPPORTED_PYTHON_VERSIONS, reuse_venv=True)
356367
def l0_dla_tests(session):
357368
"""When a developer needs to check basic api functionality using host dependencies"""
358369
run_l0_dla_tests(session)
359370

371+
360372
@nox.session(python=SUPPORTED_PYTHON_VERSIONS, reuse_venv=True)
361373
def l1_model_tests(session):
362374
"""When a developer needs to check correctness for a PR or something"""
363375
run_l1_model_tests(session)
364376

377+
365378
@nox.session(python=SUPPORTED_PYTHON_VERSIONS, reuse_venv=True)
366379
def l1_int8_accuracy_tests(session):
367380
"""Checking accuracy performance on various usecases"""

tests/cpp/test_collections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ TEST(CppAPITests, TestCollectionTupleInputOutput) {
192192
auto trt_out = trt_mod.forward(complex_inputs);
193193

194194
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
195-
out.toTuple()->elements()[0].toTensor(), trt_out.toTuple()->elements()[0].toTensor(), 1e-5));
195+
out.toTuple()->elements()[0].toTensor(), trt_out.toTuple()->elements()[0].toTensor(), 1e-5));
196196
ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(
197197
out.toTuple()->elements()[1].toTensor(), trt_out.toTuple()->elements()[1].toTensor(), 1e-5));
198198
}

tests/cpp/test_modules_as_engines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ TEST_P(CppAPITests, ModuleAsEngineIsClose) {
1414
jit_results.push_back(jit_results_ivalues.toTensor());
1515
auto trt_results = torch_tensorrt::tests::util::RunModuleForwardAsEngine(mod, inputs);
1616

17-
ASSERT_TRUE(
18-
torch_tensorrt::tests::util::cosineSimEqual(jit_results[0], trt_results[0].reshape_as(jit_results[0]), threshold));
17+
ASSERT_TRUE(torch_tensorrt::tests::util::cosineSimEqual(
18+
jit_results[0], trt_results[0].reshape_as(jit_results[0]), threshold));
1919
}
2020

2121
#ifndef DISABLE_TEST_IN_CI

tests/py/api/test_collections.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ def test_compile(self):
4141
}
4242

4343
trt_mod = torchtrt.ts.compile(self.model, **compile_spec)
44-
cos_sim = cosine_similarity(self.model(self.input, self.input), trt_mod(self.input, self.input))
45-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"standard_tensor_input_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
44+
cos_sim = cosine_similarity(
45+
self.model(self.input, self.input), trt_mod(self.input, self.input)
46+
)
47+
self.assertTrue(
48+
cos_sim > COSINE_THRESHOLD,
49+
msg=f"standard_tensor_input_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
50+
)
4651

4752

4853
class TestTupleInput(unittest.TestCase):
@@ -65,8 +70,13 @@ def test_compile(self):
6570
}
6671

6772
trt_mod = torchtrt.ts.compile(self.model, **compile_spec)
68-
cos_sim = cosine_similarity(self.model((self.input, self.input)), trt_mod((self.input, self.input)))
69-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"tuple_input_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
73+
cos_sim = cosine_similarity(
74+
self.model((self.input, self.input)), trt_mod((self.input, self.input))
75+
)
76+
self.assertTrue(
77+
cos_sim > COSINE_THRESHOLD,
78+
msg=f"tuple_input_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
79+
)
7080

7181

7282
class TestListInput(unittest.TestCase):
@@ -87,8 +97,13 @@ def test_compile(self):
8797
}
8898

8999
trt_mod = torchtrt.ts.compile(self.model, **compile_spec)
90-
cos_sim = cosine_similarity(self.model([self.input, self.input]), trt_mod([self.input, self.input]))
91-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"list_input_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
100+
cos_sim = cosine_similarity(
101+
self.model([self.input, self.input]), trt_mod([self.input, self.input])
102+
)
103+
self.assertTrue(
104+
cos_sim > COSINE_THRESHOLD,
105+
msg=f"list_input_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
106+
)
92107

93108

94109
class TestTupleInputOutput(unittest.TestCase):
@@ -115,7 +130,10 @@ def test_compile(self):
115130
pyt_out = self.model((self.input, self.input))
116131
for (t, p) in zip(trt_out, pyt_out):
117132
cos_sim = cosine_similarity(t, p)
118-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"tuple_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
133+
self.assertTrue(
134+
cos_sim > COSINE_THRESHOLD,
135+
msg=f"tuple_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
136+
)
119137

120138

121139
class TestListInputOutput(unittest.TestCase):
@@ -143,7 +161,10 @@ def test_compile(self):
143161

144162
for (t, p) in zip(trt_out, pyt_out):
145163
cos_sim = cosine_similarity(t, p)
146-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"list_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
164+
self.assertTrue(
165+
cos_sim > COSINE_THRESHOLD,
166+
msg=f"list_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
167+
)
147168

148169

149170
class TestListInputTupleOutput(unittest.TestCase):
@@ -170,7 +191,10 @@ def test_compile(self):
170191
pyt_out = self.model((self.input, self.input))
171192
for (t, p) in zip(trt_out, pyt_out):
172193
cos_sim = cosine_similarity(t, p)
173-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"list_input_tuple_output_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
194+
self.assertTrue(
195+
cos_sim > COSINE_THRESHOLD,
196+
msg=f"list_input_tuple_output_scripted TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
197+
)
174198

175199

176200
if __name__ == "__main__":

tests/py/api/test_e2e_behavior.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import copy
66
from typing import Dict
77

8+
89
class TestInputTypeDefaultsFP32Model(unittest.TestCase):
910
def test_input_use_default_fp32(self):
1011
self.model = models.resnet18(pretrained=True).eval().to("cuda")

tests/py/api/test_embed_engines.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Dict
88
from utils import cosine_similarity, COSINE_THRESHOLD
99

10+
1011
class TestModelToEngineToModel(unittest.TestCase):
1112
def test_resnet50(self):
1213
self.model = models.resnet50(pretrained=True).eval().to("cuda")
@@ -26,13 +27,20 @@ def test_resnet50(self):
2627
}
2728

2829
self.scripted_model = torch.jit.script(self.model)
29-
trt_engine = torchtrt.ts.convert_method_to_trt_engine(self.scripted_model, "forward", **compile_spec)
30+
trt_engine = torchtrt.ts.convert_method_to_trt_engine(
31+
self.scripted_model, "forward", **compile_spec
32+
)
3033
trt_mod = torchtrt.ts.embed_engine_in_new_module(trt_engine)
3134
cos_sim = cosine_similarity(self.model(self.input), trt_mod(self.input))
32-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"Resnet50 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
35+
self.assertTrue(
36+
cos_sim > COSINE_THRESHOLD,
37+
msg=f"Resnet50 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
38+
)
3339

3440
def test_efficientnet_b0(self):
35-
self.model = timm.create_model("efficientnet_b0", pretrained=True).eval().to("cuda")
41+
self.model = (
42+
timm.create_model("efficientnet_b0", pretrained=True).eval().to("cuda")
43+
)
3644
self.input = torch.randn((1, 3, 224, 224)).to("cuda")
3745

3846
compile_spec = {
@@ -49,11 +57,17 @@ def test_efficientnet_b0(self):
4957
}
5058

5159
self.scripted_model = torch.jit.script(self.model)
52-
trt_engine = torchtrt.ts.convert_method_to_trt_engine(self.scripted_model, "forward", **compile_spec)
60+
trt_engine = torchtrt.ts.convert_method_to_trt_engine(
61+
self.scripted_model, "forward", **compile_spec
62+
)
5363
trt_mod = torchtrt.ts.embed_engine_in_new_module(trt_engine)
5464

5565
cos_sim = cosine_similarity(self.model(self.input), trt_mod(self.input))
56-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"EfficientNet-B0 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
66+
self.assertTrue(
67+
cos_sim > COSINE_THRESHOLD,
68+
msg=f"EfficientNet-B0 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
69+
)
70+
5771

5872
if __name__ == "__main__":
5973
unittest.main()

tests/py/api/test_module_fallback.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Dict
77
from utils import cosine_similarity, COSINE_THRESHOLD
88

9+
910
class TestModuleFallback(unittest.TestCase):
1011
def test_fallback_resnet18(self):
1112
self.model = models.resnet18(pretrained=True).eval().to("cuda")
@@ -25,7 +26,10 @@ def test_fallback_resnet18(self):
2526
}
2627
trt_mod = torchtrt.compile(self.model, **compile_spec)
2728
cos_sim = cosine_similarity(self.model(self.input), trt_mod(self.input))
28-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"Resnet18 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
29+
self.assertTrue(
30+
cos_sim > COSINE_THRESHOLD,
31+
msg=f"Resnet18 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
32+
)
2933

3034
def test_fallback_mobilenet_v2(self):
3135
self.model = models.mobilenet_v2(pretrained=True).eval().to("cuda")
@@ -41,12 +45,17 @@ def test_fallback_mobilenet_v2(self):
4145
"gpu_id": 0,
4246
},
4347
"enabled_precisions": {torch.float},
44-
"torch_executed_modules": ["torchvision.models.mobilenetv2.ConvBNActivation"],
48+
"torch_executed_modules": [
49+
"torchvision.models.mobilenetv2.ConvBNActivation"
50+
],
4551
"min_block_size": 5,
4652
}
4753
trt_mod = torchtrt.compile(self.model, **compile_spec)
4854
cos_sim = cosine_similarity(self.model(self.input), trt_mod(self.input))
49-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"Mobilenet V2 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
55+
self.assertTrue(
56+
cos_sim > COSINE_THRESHOLD,
57+
msg=f"Mobilenet V2 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
58+
)
5059

5160

5261
if __name__ == "__main__":

tests/py/api/test_operator_fallback.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Dict
77
from utils import cosine_similarity, COSINE_THRESHOLD
88

9+
910
class TestFallbackModels(unittest.TestCase):
1011
def test_fallback_resnet18(self):
1112
self.model = models.resnet18(pretrained=True).eval().to("cuda")
@@ -25,7 +26,10 @@ def test_fallback_resnet18(self):
2526
}
2627
trt_mod = torchtrt.compile(self.model, **compile_spec)
2728
cos_sim = cosine_similarity(self.model(self.input), trt_mod(self.input))
28-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"Resnet18 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
29+
self.assertTrue(
30+
cos_sim > COSINE_THRESHOLD,
31+
msg=f"Resnet18 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
32+
)
2933

3034
def test_fallback_mobilenet_v2(self):
3135
self.model = models.mobilenet_v2(pretrained=True).eval().to("cuda")
@@ -45,7 +49,10 @@ def test_fallback_mobilenet_v2(self):
4549
}
4650
trt_mod = torchtrt.compile(self.model, **compile_spec)
4751
cos_sim = cosine_similarity(self.model(self.input), trt_mod(self.input))
48-
self.assertTrue(cos_sim > COSINE_THRESHOLD, msg=f"Mobilenet V2 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}")
52+
self.assertTrue(
53+
cos_sim > COSINE_THRESHOLD,
54+
msg=f"Mobilenet V2 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
55+
)
4956

5057

5158
if __name__ == "__main__":

0 commit comments

Comments
 (0)