Skip to content

Commit 117a98d

Browse files
authored
fix: Add new TRT 8.6 features to Dynamo compile [3 / x] (#1973)
1 parent 08e9d5a commit 117a98d

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

py/torch_tensorrt/dynamo/backend/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import torch_tensorrt
55
from functools import partial
66

7-
from typing import Any, Sequence
7+
from typing import Any, Optional, Sequence
88
from torch_tensorrt import EngineCapability, Device
99
from torch_tensorrt.fx.utils import LowerPrecision
1010

@@ -17,6 +17,9 @@
1717
WORKSPACE_SIZE,
1818
MIN_BLOCK_SIZE,
1919
PASS_THROUGH_BUILD_FAILURES,
20+
MAX_AUX_STREAMS,
21+
VERSION_COMPATIBLE,
22+
OPTIMIZATION_LEVEL,
2023
USE_EXPERIMENTAL_RT,
2124
)
2225

@@ -46,6 +49,9 @@ def compile(
4649
min_block_size=MIN_BLOCK_SIZE,
4750
torch_executed_ops=[],
4851
torch_executed_modules=[],
52+
max_aux_streams=MAX_AUX_STREAMS,
53+
version_compatible=VERSION_COMPATIBLE,
54+
optimization_level=OPTIMIZATION_LEVEL,
4955
use_experimental_rt=USE_EXPERIMENTAL_RT,
5056
**kwargs,
5157
):
@@ -95,6 +101,9 @@ def compile(
95101
workspace_size=workspace_size,
96102
min_block_size=min_block_size,
97103
torch_executed_ops=torch_executed_ops,
104+
max_aux_streams=max_aux_streams,
105+
version_compatible=version_compatible,
106+
optimization_level=optimization_level,
98107
use_experimental_rt=use_experimental_rt,
99108
**kwargs,
100109
)
@@ -119,6 +128,9 @@ def create_backend(
119128
min_block_size: int = MIN_BLOCK_SIZE,
120129
torch_executed_ops: Sequence[str] = set(),
121130
pass_through_build_failures: bool = PASS_THROUGH_BUILD_FAILURES,
131+
max_aux_streams: Optional[int] = MAX_AUX_STREAMS,
132+
version_compatible: bool = VERSION_COMPATIBLE,
133+
optimization_level: Optional[int] = OPTIMIZATION_LEVEL,
122134
use_experimental_rt: bool = USE_EXPERIMENTAL_RT,
123135
**kwargs,
124136
):
@@ -131,6 +143,10 @@ def create_backend(
131143
min_block_size: Minimum number of operators per TRT-Engine Block
132144
torch_executed_ops: Sequence of operations to run in Torch, regardless of converter coverage
133145
pass_through_build_failures: Whether to fail on TRT engine build errors (True) or not (False)
146+
max_aux_streams: Maximum number of allowed auxiliary TRT streams for each engine
147+
version_compatible: Provide version forward-compatibility for engine plan files
148+
optimization_level: Builder optimization 0-5, higher levels imply longer build time,
149+
searching for more optimization options. TRT defaults to 3
134150
use_experimental_rt: Whether to use the new experimental TRTModuleNext for TRT engines
135151
Returns:
136152
Backend for torch.compile
@@ -145,6 +161,9 @@ def create_backend(
145161
min_block_size=min_block_size,
146162
torch_executed_ops=torch_executed_ops,
147163
pass_through_build_failures=pass_through_build_failures,
164+
max_aux_streams=max_aux_streams,
165+
version_compatible=version_compatible,
166+
optimization_level=optimization_level,
148167
use_experimental_rt=use_experimental_rt,
149168
)
150169

py/torch_tensorrt/dynamo/backend/_defaults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
WORKSPACE_SIZE = 0
77
MIN_BLOCK_SIZE = 5
88
PASS_THROUGH_BUILD_FAILURES = False
9+
MAX_AUX_STREAMS = None
10+
VERSION_COMPATIBLE = False
11+
OPTIMIZATION_LEVEL = None
912
USE_EXPERIMENTAL_RT = False

py/torch_tensorrt/dynamo/backend/_settings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass, field
2-
from typing import Sequence
2+
from typing import Optional, Sequence
33

44
from torch_tensorrt.fx.utils import LowerPrecision
55
from torch_tensorrt.dynamo.backend._defaults import (
@@ -8,6 +8,9 @@
88
WORKSPACE_SIZE,
99
MIN_BLOCK_SIZE,
1010
PASS_THROUGH_BUILD_FAILURES,
11+
MAX_AUX_STREAMS,
12+
VERSION_COMPATIBLE,
13+
OPTIMIZATION_LEVEL,
1114
USE_EXPERIMENTAL_RT,
1215
)
1316

@@ -20,4 +23,7 @@ class CompilationSettings:
2023
min_block_size: int = MIN_BLOCK_SIZE
2124
torch_executed_ops: Sequence[str] = field(default_factory=set)
2225
pass_through_build_failures: bool = PASS_THROUGH_BUILD_FAILURES
26+
max_aux_streams: Optional[int] = MAX_AUX_STREAMS
27+
version_compatible: bool = VERSION_COMPATIBLE
28+
optimization_level: Optional[int] = OPTIMIZATION_LEVEL
2329
use_experimental_rt: bool = USE_EXPERIMENTAL_RT

py/torch_tensorrt/dynamo/backend/conversion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def convert_module(
4242
if settings.debug
4343
else trt.ProfilingVerbosity.LAYER_NAMES_ONLY
4444
),
45+
max_aux_streams=settings.max_aux_streams,
46+
version_compatible=settings.version_compatible,
47+
optimization_level=settings.optimization_level,
4548
)
4649

4750
if settings.use_experimental_rt:

0 commit comments

Comments
 (0)