Skip to content

Commit 7e5f96c

Browse files
committed
chore: Add note about Cuda Driver Error
- Update arguments to Dynamo compile call in line with new schema updates
1 parent 995c21c commit 7e5f96c

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

examples/dynamo/dynamo_compile_advanced_usage.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1010

1111
import torch
12-
from torch_tensorrt.fx.lower_setting import LowerPrecision
1312

1413
# %%
1514

@@ -68,12 +67,12 @@ def forward(self, x: torch.Tensor, y: torch.Tensor):
6867
# For accepted backend options, see the CompilationSettings dataclass:
6968
# py/torch_tensorrt/dynamo/backend/_settings.py
7069
backend_kwargs = {
71-
"precision": LowerPrecision.FP16,
70+
"enabled_precisions": {torch.half},
7271
"debug": True,
7372
"min_block_size": 2,
7473
"torch_executed_ops": {"torch.ops.aten.sub.Tensor"},
7574
"optimization_level": 4,
76-
"use_experimental_rt": True,
75+
"use_python_runtime": False,
7776
}
7877

7978
# Run the model on an input to cause compilation, as so:
@@ -89,5 +88,13 @@ def forward(self, x: torch.Tensor, y: torch.Tensor):
8988
# Finally, we use Torch utilities to clean up the workspace
9089
torch._dynamo.reset()
9190

92-
with torch.no_grad():
93-
torch.cuda.empty_cache()
91+
# %%
92+
# Cuda Driver Error Note
93+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
#
95+
# Occasionally, upon exiting the Python runtime after Dynamo compilation with `torch_tensorrt`,
96+
# one may encounter a Cuda Driver Error. This issue is related to https://github.com/NVIDIA/TensorRT/issues/2052
97+
# and can be resolved by wrapping the compilation/inference in a function and using a scoped call, as in::
98+
#
99+
# if __name__ == '__main__':
100+
# compile_engine_and_infer()

examples/dynamo/dynamo_compile_resnet_example.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# Maximum number of TRT Engines
3535
# (Lower value allows more graph segmentation)
36-
min_block_size = 3
36+
min_block_size = 7
3737

3838
# Operations to Run in Torch, regardless of converter support
3939
torch_executed_ops = {}
@@ -78,5 +78,13 @@
7878
# Finally, we use Torch utilities to clean up the workspace
7979
torch._dynamo.reset()
8080

81-
with torch.no_grad():
82-
torch.cuda.empty_cache()
81+
# %%
82+
# Cuda Driver Error Note
83+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
#
85+
# Occasionally, upon exiting the Python runtime after Dynamo compilation with `torch_tensorrt`,
86+
# one may encounter a Cuda Driver Error. This issue is related to https://github.com/NVIDIA/TensorRT/issues/2052
87+
# and can be resolved by wrapping the compilation/inference in a function and using a scoped call, as in::
88+
#
89+
# if __name__ == '__main__':
90+
# compile_engine_and_infer()

examples/dynamo/dynamo_compile_transformers_example.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# Maximum number of TRT Engines
3939
# (Lower value allows more graph segmentation)
40-
min_block_size = 3
40+
min_block_size = 7
4141

4242
# Operations to Run in Torch, regardless of converter support
4343
torch_executed_ops = {}
@@ -88,5 +88,13 @@
8888
# Finally, we use Torch utilities to clean up the workspace
8989
torch._dynamo.reset()
9090

91-
with torch.no_grad():
92-
torch.cuda.empty_cache()
91+
# %%
92+
# Cuda Driver Error Note
93+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
#
95+
# Occasionally, upon exiting the Python runtime after Dynamo compilation with `torch_tensorrt`,
96+
# one may encounter a Cuda Driver Error. This issue is related to https://github.com/NVIDIA/TensorRT/issues/2052
97+
# and can be resolved by wrapping the compilation/inference in a function and using a scoped call, as in::
98+
#
99+
# if __name__ == '__main__':
100+
# compile_engine_and_infer()

0 commit comments

Comments
 (0)