Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trt compiler fixes #8064

Merged
merged 96 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
054a2b8
Added TRTWrapper
borisfom Aug 5, 2024
3ab9c83
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 5, 2024
4ec1d3b
Merge branch 'dev' into trt-wrappers
KumoLiu Aug 5, 2024
fe71030
Addressing code review comments, adding docustrings, cleanup
borisfom Aug 5, 2024
6a9727f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 5, 2024
29d9725
Added TRT 10.3RC to Dockerfile
borisfom Aug 6, 2024
5b8b4f2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 6, 2024
f31d6dd
Workaround for format check
borisfom Aug 6, 2024
9303c32
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 6, 2024
c1d0b19
More format check workarounds
borisfom Aug 6, 2024
63c4b70
More format check workarounds
borisfom Aug 6, 2024
9a3d6a6
More format check workarounds
borisfom Aug 6, 2024
8bf0300
Using optional exports for trt_utils
borisfom Aug 6, 2024
c03e49b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 6, 2024
39c94c2
Fixing lint errors
borisfom Aug 6, 2024
35dffcc
Merge branch 'trt-wrappers' of github.com:borisfom/MONAI into trt-wra…
borisfom Aug 6, 2024
9d867a7
Format fixed
borisfom Aug 6, 2024
6e2733a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 6, 2024
848a42d
Fixing flake errors
borisfom Aug 6, 2024
9ade6af
Merge branch 'trt-wrappers' of github.com:borisfom/MONAI into trt-wra…
borisfom Aug 6, 2024
cf2c3b1
Fixing CI
borisfom Aug 6, 2024
e8b51f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 6, 2024
ddb5bc8
Fixed mypy, Engine refactor
borisfom Aug 7, 2024
79014d7
Merge branch 'dev' into trt-wrappers
yiheng-wang-nv Aug 7, 2024
511081f
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 7, 2024
b188237
Merged cast_utils, copyrights fixed.
borisfom Aug 8, 2024
60cdd74
Added unit test
borisfom Aug 8, 2024
778a44a
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 9, 2024
0ab5d26
TRTWrapper moved to networks
borisfom Aug 9, 2024
a948bfb
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 9, 2024
3a72c76
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 9, 2024
7d449f5
Refactored TRTWrapper args
borisfom Aug 10, 2024
6846fd4
Added docstring for precision
borisfom Aug 10, 2024
d598590
Fixed comments, reordered args
borisfom Aug 11, 2024
9109d3f
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 12, 2024
517c111
Reduced test assert accuracy
borisfom Aug 12, 2024
4739756
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 14, 2024
ed0d93d
Addressing code review comments
borisfom Aug 14, 2024
2ec8e53
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 15, 2024
fdcf118
Added Torch-TRT option, cleaned up engine save method
borisfom Aug 15, 2024
1009dc5
Added trt_wrap adapter
borisfom Aug 16, 2024
763f769
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 16, 2024
fd679c0
Refined trt_wrap
borisfom Aug 16, 2024
dc13b52
Used tempdir for ONNX
borisfom Aug 17, 2024
779de92
Refactored trt wrapper, added trt handler
borisfom Aug 18, 2024
6504dc9
Adjusted refactor for use in config
borisfom Aug 18, 2024
c1be72c
Added fold constant threshold param
borisfom Aug 20, 2024
0f16b8b
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 20, 2024
5c495b6
Logger refactoring
borisfom Aug 20, 2024
5d1ebc2
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 20, 2024
48b85ce
Addressing code review comments
borisfom Aug 22, 2024
1244c49
Added multiple submodules option to trt_wrap
borisfom Aug 22, 2024
a603f13
Added polygraphy to more places, torch-tensorrt option debugging
borisfom Aug 23, 2024
f5be0cc
Renamed trt_wrap -> trt_compile
borisfom Aug 23, 2024
b96ebb4
Reformatted for CI
borisfom Aug 23, 2024
73be701
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 23, 2024
85140e2
Fixed alias issue
borisfom Aug 23, 2024
fa4c182
Fixed base in Dockerfile
borisfom Aug 23, 2024
78a3ef3
Fixed CI test failures
borisfom Aug 23, 2024
267c125
Addressed code review comments
borisfom Aug 23, 2024
9adc035
Added dictionary return option
borisfom Aug 26, 2024
a017fcd
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 26, 2024
7f1c0c1
Fixed return_dict issue
borisfom Aug 26, 2024
a242a64
Implemented https://github.com/Project-MONAI/MONAI/issues/8044
borisfom Aug 26, 2024
5afc912
Generalizing merge logic, adding test case and doc
borisfom Aug 27, 2024
ceff018
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
e294968
Addressing code review comments
borisfom Aug 27, 2024
55cf7fa
Merge branch 'trt-wrappers' of github.com:borisfom/MONAI into trt-wra…
borisfom Aug 27, 2024
b6d9179
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
652448a
doc build fixed
borisfom Aug 28, 2024
b793eb2
Merge branch 'trt-wrappers' of github.com:borisfom/MONAI into trt-wra…
borisfom Aug 28, 2024
5c4f63a
Fixed formatting
borisfom Aug 28, 2024
dd91183
Fixed formatting
borisfom Aug 28, 2024
c41cb5a
Updated base container to 24.08
borisfom Aug 28, 2024
7e440fc
Renaming trt_wrapper -> trt_compiler, adding TRT handler test
borisfom Aug 28, 2024
329d024
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
84de860
fixing CI error
borisfom Aug 28, 2024
875d1a8
Merge branch 'trt-wrappers' of github.com:borisfom/MONAI into trt-wra…
borisfom Aug 28, 2024
b84cec4
Fixing min test error, addressing comments
borisfom Aug 28, 2024
9481d9f
optional propagation of dynamo arg fixed, onnx_graphsurgeon package a…
borisfom Aug 28, 2024
6a11581
add vista test cases
yiheng-wang-nv Aug 28, 2024
6e8bd6b
Merge branch 'dev' into trt-wrappers
yiheng-wang-nv Aug 28, 2024
3d221cb
Merge branch 'dev' into trt-wrappers
KumoLiu Aug 28, 2024
792a721
Code review input addressed
borisfom Aug 29, 2024
73ac717
Fixed torch-tensorrt path of trt_compile, added test
borisfom Aug 29, 2024
ea879f2
Merge branch 'trt-wrappers' of github.com:borisfom/MONAI into trt-wra…
borisfom Aug 29, 2024
1e7e76d
Fixing tests
borisfom Aug 29, 2024
47e676e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2024
1cb49c3
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Aug 29, 2024
dd4d2d6
Merge branch 'dev' into trt-wrappers
binliunls Aug 29, 2024
6b47a8b
Merge branch 'dev' into trt-wrappers
KumoLiu Aug 31, 2024
80d3928
Merge branch 'trt-wrappers' of github.com:borisfom/MONAI into trt-wra…
borisfom Sep 3, 2024
47823d1
Merge remote-tracking branch 'origin/dev' into trt-wrappers
borisfom Sep 3, 2024
c126e67
Fixing TRT 8.x compatibility
borisfom Sep 3, 2024
5645157
Improved diagnostic, skip trt test if < 10.3
borisfom Sep 3, 2024
9e98f66
Merge branch 'dev' into trt_compiler_fixes
KumoLiu Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions monai/networks/trt_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def forward(self, model, argv, kwargs):
self._build_and_save(model, build_args)
# This will reassign input_names from the engine
self._load_engine()
assert self.engine is not None
except Exception as e:
if self.fallback:
self.logger.info(f"Failed to build engine: {e}")
Expand Down Expand Up @@ -403,8 +404,10 @@ def _onnx_to_trt(self, onnx_path):

build_args = self.build_args.copy()
build_args["tf32"] = self.precision != "fp32"
build_args["fp16"] = self.precision == "fp16"
build_args["bf16"] = self.precision == "bf16"
if self.precision == "fp16":
build_args["fp16"] = True
elif self.precision == "bf16":
build_args["bf16"] = True

self.logger.info(f"Building TensorRT engine for {onnx_path}: {self.plan_path}")
network = network_from_onnx_path(onnx_path, flags=[trt.OnnxParserFlag.NATIVE_INSTANCENORM])
Expand Down Expand Up @@ -502,6 +505,7 @@ def trt_compile(
) -> torch.nn.Module:
"""
Instruments model or submodule(s) with TrtCompiler and replaces its forward() with TRT hook.
Note: TRT 10.3 is recommended for best performance. Some nets may even fail to work with TRT 8.x
Args:
model: module to patch with TrtCompiler object.
base_path: TRT plan(s) saved to f"{base_path}[.{submodule}].plan" path.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_trt_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from monai.handlers import TrtHandler
from monai.networks import trt_compile
from monai.networks.nets import UNet, cell_sam_wrapper, vista3d132
from monai.utils import optional_import
from monai.utils import min_version, optional_import
from tests.utils import skip_if_no_cuda, skip_if_quick, skip_if_windows

trt, trt_imported = optional_import("tensorrt")
trt, trt_imported = optional_import("tensorrt", "10.1.0", min_version)
KumoLiu marked this conversation as resolved.
Show resolved Hide resolved
polygraphy, polygraphy_imported = optional_import("polygraphy")
build_sam_vit_b, has_sam = optional_import("segment_anything.build_sam", name="build_sam_vit_b")

Expand Down
Loading