Skip to content

Commit 2c327c4

Browse files
committed
infra: Adding standard python tooling to verify code quality
We are adding: - mypy: Type checking - ruff: Linting and common bug detection - isort: import order cleanup These tools will run as part of the precommit system and are required for all code in //py and //examples. They are suggested for the rest Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt/ts): Make torch_tensorrt.ts.TorchScriptInput mypy compliant Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt/ts): Making compile mypy compliant Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt): Make Device conform to mypy Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt): Making Input mypy compilaint Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt/ts): Make compile_spec conform to mypy Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt): more _Input.py mypy stuff Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt): conforming logging to mypy Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt): _compile.py conforms to mypy Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt/dynamo/backend): Backend is mypy conforming Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt): subsitutions mypy compliant Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt/dynamo/lowering): mypy compilance Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt/dynamo): Tracer mypy compliance Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt): ptq mypy compliance Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt): __init__.py mypy conforming Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore(//py/torch_tensorrt/dynamo/conversion): mypy conforming Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore: mypy compliance with 3.11 syntax Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore: Buildifier on build files Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore: linting for the remaining files Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore: All code is now flake8 compliant Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore: adding isort to pre-commit Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]> chore: ready to start review Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent 8c62fca commit 2c327c4

File tree

149 files changed

+1659
-1309
lines changed

Some content is hidden

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

149 files changed

+1659
-1309
lines changed

.pre-commit-config.yaml

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
exclude: ^.github/actions/assigner/dist
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v2.3.0
4+
rev: v4.4.0
55
hooks:
66
- id: check-yaml
77
- id: trailing-whitespace
8+
exclude: ^docs
89
- id: check-added-large-files
910
args:
1011
- --maxkb=1000
@@ -13,18 +14,14 @@ repos:
1314
- id: mixed-line-ending
1415
args:
1516
- --fix=lf
16-
- repo: https://github.com/psf/black
17-
rev: 22.6.0
18-
hooks:
19-
- id: black
20-
exclude: ^examples/custom_converters/elu_converter/setup.py
17+
exclude: ^docs
2118
- repo: https://github.com/pre-commit/mirrors-clang-format
22-
rev: v14.0.6
19+
rev: v16.0.6
2320
hooks:
2421
- id: clang-format
2522
types_or: [c++, c, cuda]
2623
- repo: https://github.com/keith/pre-commit-buildifier
27-
rev: 5.1.0
24+
rev: 6.1.0.2
2825
hooks:
2926
- id: buildifier
3027
args:
@@ -34,6 +31,26 @@ repos:
3431
rev: v0.13
3532
hooks:
3633
- id: validate-pyproject
34+
- repo: https://github.com/pycqa/isort
35+
rev: 5.12.0
36+
hooks:
37+
- id: isort
38+
name: isort (python)
39+
- repo: https://github.com/pre-commit/mirrors-mypy
40+
rev: 'v1.4.1'
41+
hooks:
42+
- id: mypy
43+
exclude: "^py/torch_tensorrt/fx|^examples|^tests|^tools|^docs|noxfile.py|setup.py|versions.py"
44+
- repo: https://github.com/astral-sh/ruff-pre-commit
45+
# Ruff version.
46+
rev: v0.0.278
47+
hooks:
48+
- id: ruff
49+
- repo: https://github.com/psf/black
50+
rev: 23.7.0
51+
hooks:
52+
- id: black
53+
exclude: ^examples/custom_converters/elu_converter/setup.py|^docs
3754
- repo: local
3855
hooks:
3956
- id: dont-commit-upstream
@@ -42,4 +59,3 @@ repos:
4259
exclude: "^.pre-commit-config.yaml"
4360
language: pygrep
4461
types: [text]
45-

BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ pkg_tar(
4747
":windows": ["//cpp/lib:torch_tensorrt.dll"],
4848
"//conditions:default": [
4949
"//cpp/lib:libtorchtrt.so",
50-
"//cpp/lib:libtorchtrt_runtime.so",
5150
"//cpp/lib:libtorchtrt_plugins.so",
51+
"//cpp/lib:libtorchtrt_runtime.so",
5252
],
5353
}),
5454
mode = "0755",
@@ -74,9 +74,9 @@ pkg_tar(
7474
extension = "tar.gz",
7575
package_dir = "torch_tensorrt",
7676
deps = [
77-
":lib",
7877
":include",
7978
":include_core",
79+
":lib",
8080
] + select({
8181
":windows": [],
8282
"//conditions:default": [":bin"],

core/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ cc_library(
2727
],
2828
deps = [
2929
"//core/conversion",
30-
"//core/runtime",
3130
"//core/lowering",
3231
"//core/partitioning",
32+
"//core/runtime",
3333
"//core/util/logging",
3434
"@tensorrt//:nvinfer",
3535
] + select({
3636
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
37-
"//conditions:default": ["@libtorch//:libtorch"],
37+
"//conditions:default": ["@libtorch"],
3838
}),
3939
alwayslink = True,
4040
)

core/conversion/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ cc_library(
2020
"conversion.h",
2121
],
2222
deps = [
23-
"@tensorrt//:nvinfer",
24-
"//core/conversion/var",
2523
"//core/conversion/conversionctx",
2624
"//core/conversion/converters",
2725
"//core/conversion/evaluators",
26+
"//core/conversion/var",
2827
"//core/ir",
2928
"//core/util:prelude",
29+
"@tensorrt//:nvinfer",
3030
] + select({
3131
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
32-
"//conditions:default": ["@libtorch//:libtorch"],
32+
"//conditions:default": ["@libtorch"],
3333
}),
3434
)
3535

core/conversion/conversionctx/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ cc_library(
1919
"ConversionCtx.h",
2020
],
2121
deps = [
22-
"@tensorrt//:nvinfer",
23-
"//core/util:prelude",
2422
"//core/ir",
23+
"//core/util:prelude",
24+
"@tensorrt//:nvinfer",
2525
] + select({
2626
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
27-
"//conditions:default": ["@libtorch//:libtorch"],
27+
"//conditions:default": ["@libtorch"],
2828
}),
2929
)
3030

core/conversion/converters/BUILD

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ cc_library(
1919
"Weights.h",
2020
],
2121
deps = [
22-
"@tensorrt//:nvinfer",
23-
"//core/util:prelude",
2422
"//core/conversion/conversionctx",
23+
"//core/util:prelude",
24+
"@tensorrt//:nvinfer",
2525
] + select({
2626
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
27-
"//conditions:default": ["@libtorch//:libtorch"],
27+
"//conditions:default": ["@libtorch"],
2828
}),
2929
alwayslink = True,
3030
)
@@ -39,12 +39,12 @@ cc_library(
3939
],
4040
deps = [
4141
":weights",
42-
"@tensorrt//:nvinfer",
43-
"//core/util:prelude",
4442
"//core/conversion/conversionctx",
43+
"//core/util:prelude",
44+
"@tensorrt//:nvinfer",
4545
] + select({
4646
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
47-
"//conditions:default": ["@libtorch//:libtorch"],
47+
"//conditions:default": ["@libtorch"],
4848
}),
4949
alwayslink = True,
5050
)
@@ -91,16 +91,16 @@ cc_library(
9191
"converters.h",
9292
],
9393
deps = [
94-
"@tensorrt//:nvinfer",
95-
"//core/util:prelude",
96-
"//core/conversion/var",
97-
"//core/conversion/tensorcontainer",
94+
":converter_util",
9895
"//core/conversion/conversionctx",
96+
"//core/conversion/tensorcontainer",
97+
"//core/conversion/var",
9998
"//core/plugins:torch_tensorrt_plugins",
100-
":converter_util",
99+
"//core/util:prelude",
100+
"@tensorrt//:nvinfer",
101101
] + select({
102102
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
103-
"//conditions:default": ["@libtorch//:libtorch"],
103+
"//conditions:default": ["@libtorch"],
104104
}),
105105
alwayslink = True,
106106
)

core/conversion/evaluators/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ cc_library(
2424
"evaluators.h",
2525
],
2626
deps = [
27-
"//core/util:prelude",
28-
"//core/conversion/var",
2927
"//core/conversion/tensorcontainer",
28+
"//core/conversion/var",
29+
"//core/util:prelude",
3030
] + select({
3131
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
32-
"//conditions:default": ["@libtorch//:libtorch"],
32+
"//conditions:default": ["@libtorch"],
3333
}),
3434
alwayslink = True,
3535
)

core/conversion/tensorcontainer/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ cc_library(
1919
"TensorContainer.h",
2020
],
2121
deps = [
22-
"@tensorrt//:nvinfer",
2322
"//core/util:prelude",
23+
"@tensorrt//:nvinfer",
2424
] + select({
2525
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
26-
"//conditions:default": ["@libtorch//:libtorch"],
26+
"//conditions:default": ["@libtorch"],
2727
}),
2828
alwayslink = True,
2929
)

core/conversion/var/BUILD

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ cc_library(
2020
"Var_inl.h",
2121
],
2222
deps = [
23-
"@tensorrt//:nvinfer",
24-
"//core/util:prelude",
2523
"//core/conversion/converters:converter_util",
26-
"//core/conversion/tensorcontainer:tensorcontainer",
24+
"//core/conversion/tensorcontainer",
25+
"//core/util:prelude",
26+
"@tensorrt//:nvinfer",
2727
] + select({
2828
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
29-
"//conditions:default": ["@libtorch//:libtorch"],
29+
"//conditions:default": ["@libtorch"],
3030
}),
3131
alwayslink = True,
3232
)

core/ir/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ cc_library(
2222
"ir.h",
2323
],
2424
deps = [
25-
"@tensorrt//:nvinfer",
2625
"//core/util:prelude",
26+
"@tensorrt//:nvinfer",
2727
] + select({
2828
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
29-
"//conditions:default": ["@libtorch//:libtorch"],
29+
"//conditions:default": ["@libtorch"],
3030
}),
3131
)
3232

core/lowering/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ cc_library(
2222
"lowering.h",
2323
],
2424
deps = [
25+
"//core/ir",
2526
"//core/lowering/passes",
2627
"//core/util:prelude",
27-
"//core/ir",
2828
] + select({
2929
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
30-
"//conditions:default": ["@libtorch//:libtorch"],
30+
"//conditions:default": ["@libtorch"],
3131
}),
3232
alwayslink = True,
3333
)

core/lowering/passes/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cc_library(
4949
"//core/util:prelude",
5050
] + select({
5151
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
52-
"//conditions:default": ["@libtorch//:libtorch"],
52+
"//conditions:default": ["@libtorch"],
5353
}),
5454
)
5555

core/partitioning/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ cc_library(
2121
"partitioning.h",
2222
],
2323
deps = [
24-
"//core/util:prelude",
25-
"//core/ir",
2624
"//core/conversion",
25+
"//core/ir",
2726
"//core/lowering",
2827
"//core/partitioning/partitioningctx",
2928
"//core/partitioning/partitioninginfo",
3029
"//core/partitioning/segmentedblock",
30+
"//core/util:prelude",
3131
] + select({
3232
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
33-
"//conditions:default": ["@libtorch//:libtorch"],
33+
"//conditions:default": ["@libtorch"],
3434
}),
3535
alwayslink = True,
3636
)

core/partitioning/partitioningctx/BUILD

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ cc_library(
1919
"PartitioningCtx.h",
2020
],
2121
deps = [
22-
"//core/util:prelude",
23-
"//core/ir",
2422
"//core/conversion",
25-
"//core/partitioning/segmentedblock",
23+
"//core/ir",
2624
"//core/partitioning/partitioninginfo",
25+
"//core/partitioning/segmentedblock",
26+
"//core/util:prelude",
2727
] + select({
2828
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
29-
"//conditions:default": ["@libtorch//:libtorch"],
29+
"//conditions:default": ["@libtorch"],
3030
}),
3131
alwayslink = True,
3232
)

core/partitioning/partitioninginfo/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ cc_library(
1919
"PartitioningInfo.h",
2020
],
2121
deps = [
22-
"//core/util:prelude",
23-
"//core/ir",
2422
"//core/conversion",
23+
"//core/ir",
2524
"//core/lowering",
25+
"//core/util:prelude",
2626
] + select({
2727
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
28-
"//conditions:default": ["@libtorch//:libtorch"],
28+
"//conditions:default": ["@libtorch"],
2929
}),
3030
alwayslink = True,
3131
)

core/partitioning/segmentedblock/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ cc_library(
1919
"SegmentedBlock.h",
2020
],
2121
deps = [
22-
"//core/util:prelude",
23-
"//core/ir",
2422
"//core/conversion",
23+
"//core/ir",
2524
"//core/lowering",
25+
"//core/util:prelude",
2626
] + select({
2727
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
28-
"//conditions:default": ["@libtorch//:libtorch"],
28+
"//conditions:default": ["@libtorch"],
2929
}),
3030
alwayslink = True,
3131
)

core/plugins/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ cc_library(
2929
"-lpthread",
3030
],
3131
deps = [
32+
"//core/util:prelude",
3233
"@tensorrt//:nvinfer",
3334
"@tensorrt//:nvinferplugin",
34-
"//core/util:prelude",
3535
] + select({
3636
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
37-
"//conditions:default": ["@libtorch//:libtorch"],
37+
"//conditions:default": ["@libtorch"],
3838
}),
3939
alwayslink = True,
4040
)

core/runtime/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ cc_library(
3131
"-lstdc++fs",
3232
],
3333
deps = [
34-
"@tensorrt//:nvinfer",
35-
"//core/util:prelude",
3634
"//core/plugins:torch_tensorrt_plugins",
35+
"//core/util:prelude",
36+
"@tensorrt//:nvinfer",
3737
] + select({
3838
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
39-
"//conditions:default": ["@libtorch//:libtorch"],
39+
"//conditions:default": ["@libtorch"],
4040
}),
4141
alwayslink = True,
4242
)

0 commit comments

Comments
 (0)