Skip to content

Commit 4c3d026

Browse files
committed
chore: documentation for release
Signed-off-by: Naren Dasan <naren@narendasan.com> Signed-off-by: Naren Dasan <narens@nvidia.com>
1 parent b50d12f commit 4c3d026

File tree

340 files changed

+148758
-10
lines changed

Some content is hidden

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

340 files changed

+148758
-10
lines changed

docs/v2.2.0/.nojekyll

Whitespace-only changes.

docs/v2.2.0/_cpp_api/classtorch__tensorrt_1_1DataType.html

+942
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/classtorch__tensorrt_1_1Device_1_1DeviceType.html

+879
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/classtorch__tensorrt_1_1TensorFormat.html

+911
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/classtorch__tensorrt_1_1ptq_1_1Int8CacheCalibrator.html

+875
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/classtorch__tensorrt_1_1ptq_1_1Int8Calibrator.html

+885
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/define_macros_8h_1a18d295a837ac71add5578860b55e5502.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/define_macros_8h_1a282fd3c0b1c3a215148ae372070e1268.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/define_macros_8h_1a31398a6d4d27e28817afb0f0139e909e.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/define_macros_8h_1a35703561b26b1a9d2738ad7d58b27827.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/define_macros_8h_1abd1465eb38256d3f22cc1426b23d516b.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/define_macros_8h_1abe87b341f562fd1cf40b7672e4d759da.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/define_macros_8h_1ad19939408f7be171a74a89928b36eb59.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/define_macros_8h_1adad592a7b1b7eed529cdf6acd584c883.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/dir_cpp.html

+753
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/dir_cpp_include.html

+754
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/dir_cpp_include_torch_tensorrt.html

+757
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/enum_logging_8h_1a130f65408ad8cbaee060f05e8db69558.html

+808
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/enum_torch__tensorrt_8h_1a3fbe5d72e4fc624dbd038853079620eb.html

+787
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/file_cpp_include_torch_tensorrt_logging.h.html

+809
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/file_cpp_include_torch_tensorrt_macros.h.html

+795
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/file_cpp_include_torch_tensorrt_ptq.h.html

+806
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/file_cpp_include_torch_tensorrt_torch_tensorrt.h.html

+821
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_logging_8h_1a0593f776f469c20469e2f729fc7861a3.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_logging_8h_1a0c012cb374addd90eb1f42eaec570650.html

+776
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_logging_8h_1a56e110feaaba2c3fd44bd201fd21a76a.html

+776
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_logging_8h_1a7cb50492421ea9de4e3db895819df6f2.html

+776
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_logging_8h_1ac46ac0901cb97e3ae6e93b45f24e90b8.html

+779
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_logging_8h_1ad2efd47b6c3689e58ccc595680579ae5.html

+776
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_logging_8h_1af8f3443813315af7901903d25dd495cc.html

+770
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_ptq_8h_1a226e3c83379d1012cde8578c1c86b16c.html

+785
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_ptq_8h_1a6186e305f47c1d94b6130ef6c7f7e178.html

+791
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_torch__tensorrt_8h_1a5b405fd3bf3c8fc2e2a54cbbab979797.html

+785
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_torch__tensorrt_8h_1a6e19490a08fb1553c9dd347a5ae79db9.html

+785
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_torch__tensorrt_8h_1a81f9783517335dda877d8cfcf38987c9.html

+791
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_torch__tensorrt_8h_1ac4ab8313ae72c2c899ea31548b528528.html

+776
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_torch__tensorrt_8h_1ad1acd06eaeaffbbcf6e7ebf426891384.html

+776
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_torch__tensorrt_8h_1ad6a4ee8ca6c8f6e5519eb1128ec7f4a1.html

+771
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/function_torch__tensorrt_8h_1ae8d56472106eeef37fbe51ff7f40c9b2.html

+785
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/namespace_torch.html

+756
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/namespace_torch_tensorrt.html

+804
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/namespace_torch_tensorrt__logging.html

+785
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/namespace_torch_tensorrt__ptq.html

+781
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/namespace_torch_tensorrt__torchscript.html

+782
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/program_listing_file_cpp_include_torch_tensorrt_logging.h.html

+785
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/program_listing_file_cpp_include_torch_tensorrt_macros.h.html

+784
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/program_listing_file_cpp_include_torch_tensorrt_ptq.h.html

+924
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/program_listing_file_cpp_include_torch_tensorrt_torch_tensorrt.h.html

+1,088
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/structtorch__tensorrt_1_1Device.html

+927
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/structtorch__tensorrt_1_1GraphInputs.html

+785
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/structtorch__tensorrt_1_1Input.html

+1,106
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/structtorch__tensorrt_1_1torchscript_1_1CompileSpec.html

+945
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/torch_tensort_cpp.html

+1,152
Large diffs are not rendered by default.

docs/v2.2.0/_cpp_api/unabridged_orphan.html

+842
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n\n# Compiling ResNet using the Torch-TensorRT `torch.compile` Backend\n\nThis interactive script is intended as a sample of the Torch-TensorRT workflow with `torch.compile` on a ResNet model.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"## Imports and Model Definition\n\n"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": null,
20+
"metadata": {
21+
"collapsed": false
22+
},
23+
"outputs": [],
24+
"source": [
25+
"import torch\nimport torch_tensorrt\nimport torchvision.models as models"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {
32+
"collapsed": false
33+
},
34+
"outputs": [],
35+
"source": [
36+
"# Initialize model with half precision and sample inputs\nmodel = models.resnet18(pretrained=True).half().eval().to(\"cuda\")\ninputs = [torch.randn((1, 3, 224, 224)).to(\"cuda\").half()]"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"## Optional Input Arguments to `torch_tensorrt.compile`\n\n"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"metadata": {
50+
"collapsed": false
51+
},
52+
"outputs": [],
53+
"source": [
54+
"# Enabled precision for TensorRT optimization\nenabled_precisions = {torch.half}\n\n# Whether to print verbose logs\ndebug = True\n\n# Workspace size for TensorRT\nworkspace_size = 20 << 30\n\n# Maximum number of TRT Engines\n# (Lower value allows more graph segmentation)\nmin_block_size = 7\n\n# Operations to Run in Torch, regardless of converter support\ntorch_executed_ops = {}"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"## Compilation with `torch_tensorrt.compile`\n\n"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {
68+
"collapsed": false
69+
},
70+
"outputs": [],
71+
"source": [
72+
"# Build and compile the model with torch.compile, using Torch-TensorRT backend\noptimized_model = torch_tensorrt.compile(\n model,\n ir=\"torch_compile\",\n inputs=inputs,\n enabled_precisions=enabled_precisions,\n debug=debug,\n workspace_size=workspace_size,\n min_block_size=min_block_size,\n torch_executed_ops=torch_executed_ops,\n)"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"Equivalently, we could have run the above via the torch.compile frontend, as so:\n`optimized_model = torch.compile(model, backend=\"torch_tensorrt\", options={\"enabled_precisions\": enabled_precisions, ...}); optimized_model(*inputs)`\n\n"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"metadata": {},
85+
"source": [
86+
"## Inference\n\n"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": null,
92+
"metadata": {
93+
"collapsed": false
94+
},
95+
"outputs": [],
96+
"source": [
97+
"# Does not cause recompilation (same batch size as input)\nnew_inputs = [torch.randn((1, 3, 224, 224)).half().to(\"cuda\")]\nnew_outputs = optimized_model(*new_inputs)"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {
104+
"collapsed": false
105+
},
106+
"outputs": [],
107+
"source": [
108+
"# Does cause recompilation (new batch size)\nnew_batch_size_inputs = [torch.randn((8, 3, 224, 224)).half().to(\"cuda\")]\nnew_batch_size_outputs = optimized_model(*new_batch_size_inputs)"
109+
]
110+
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"## Cleanup\n\n"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"metadata": {
122+
"collapsed": false
123+
},
124+
"outputs": [],
125+
"source": [
126+
"# Finally, we use Torch utilities to clean up the workspace\ntorch._dynamo.reset()"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"metadata": {},
132+
"source": [
133+
"## Cuda Driver Error Note\n\nOccasionally, upon exiting the Python runtime after Dynamo compilation with `torch_tensorrt`,\none may encounter a Cuda Driver Error. This issue is related to https://github.com/NVIDIA/TensorRT/issues/2052\nand can be resolved by wrapping the compilation/inference in a function and using a scoped call, as in::\n\n if __name__ == '__main__':\n compile_engine_and_infer()\n\n"
134+
]
135+
}
136+
],
137+
"metadata": {
138+
"kernelspec": {
139+
"display_name": "Python 3",
140+
"language": "python",
141+
"name": "python3"
142+
},
143+
"language_info": {
144+
"codemirror_mode": {
145+
"name": "ipython",
146+
"version": 3
147+
},
148+
"file_extension": ".py",
149+
"mimetype": "text/x-python",
150+
"name": "python",
151+
"nbconvert_exporter": "python",
152+
"pygments_lexer": "ipython3",
153+
"version": "3.10.12"
154+
}
155+
},
156+
"nbformat": 4,
157+
"nbformat_minor": 0
158+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""
2+
.. _torch_compile_advanced_usage:
3+
4+
Torch Compile Advanced Usage
5+
======================================================
6+
7+
This interactive script is intended as an overview of the process by which `torch_tensorrt.compile(..., ir="torch_compile", ...)` works, and how it integrates with the `torch.compile` API."""
8+
9+
# %%
10+
# Imports and Model Definition
11+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
import torch
14+
import torch_tensorrt
15+
16+
# %%
17+
18+
19+
# We begin by defining a model
20+
class Model(torch.nn.Module):
21+
def __init__(self) -> None:
22+
super().__init__()
23+
self.relu = torch.nn.ReLU()
24+
25+
def forward(self, x: torch.Tensor, y: torch.Tensor):
26+
x_out = self.relu(x)
27+
y_out = self.relu(y)
28+
x_y_out = x_out + y_out
29+
return torch.mean(x_y_out)
30+
31+
32+
# %%
33+
# Compilation with `torch.compile` Using Default Settings
34+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35+
36+
# Define sample float inputs and initialize model
37+
sample_inputs = [torch.rand((5, 7)).cuda(), torch.rand((5, 7)).cuda()]
38+
model = Model().eval().cuda()
39+
40+
# %%
41+
42+
# Next, we compile the model using torch.compile
43+
# For the default settings, we can simply call torch.compile
44+
# with the backend "torch_tensorrt", and run the model on an
45+
# input to cause compilation, as so:
46+
optimized_model = torch.compile(model, backend="torch_tensorrt", dynamic=False)
47+
optimized_model(*sample_inputs)
48+
49+
# %%
50+
# Compilation with `torch.compile` Using Custom Settings
51+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
53+
# First, we use Torch utilities to clean up the workspace
54+
# after the previous compile invocation
55+
torch._dynamo.reset()
56+
57+
# Define sample half inputs and initialize model
58+
sample_inputs_half = [
59+
torch.rand((5, 7)).half().cuda(),
60+
torch.rand((5, 7)).half().cuda(),
61+
]
62+
model_half = Model().eval().cuda()
63+
64+
# %%
65+
66+
# If we want to customize certain options in the backend,
67+
# but still use the torch.compile call directly, we can provide
68+
# custom options to the backend via the "options" keyword
69+
# which takes in a dictionary mapping options to values.
70+
#
71+
# For accepted backend options, see the CompilationSettings dataclass:
72+
# py/torch_tensorrt/dynamo/_settings.py
73+
backend_kwargs = {
74+
"enabled_precisions": {torch.half},
75+
"debug": True,
76+
"min_block_size": 2,
77+
"torch_executed_ops": {"torch.ops.aten.sub.Tensor"},
78+
"optimization_level": 4,
79+
"use_python_runtime": False,
80+
}
81+
82+
# Run the model on an input to cause compilation, as so:
83+
optimized_model_custom = torch.compile(
84+
model_half,
85+
backend="torch_tensorrt",
86+
options=backend_kwargs,
87+
dynamic=False,
88+
)
89+
optimized_model_custom(*sample_inputs_half)
90+
91+
# %%
92+
# Cleanup
93+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
95+
# Finally, we use Torch utilities to clean up the workspace
96+
torch._dynamo.reset()
97+
98+
# %%
99+
# Cuda Driver Error Note
100+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101+
#
102+
# Occasionally, upon exiting the Python runtime after Dynamo compilation with `torch_tensorrt`,
103+
# one may encounter a Cuda Driver Error. This issue is related to https://github.com/NVIDIA/TensorRT/issues/2052
104+
# and can be resolved by wrapping the compilation/inference in a function and using a scoped call, as in::
105+
#
106+
# if __name__ == '__main__':
107+
# compile_engine_and_infer()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
.. _torch_compile_stable_diffusion:
3+
4+
Torch Compile Stable Diffusion
5+
======================================================
6+
7+
This interactive script is intended as a sample of the Torch-TensorRT workflow with `torch.compile` on a Stable Diffusion model. A sample output is featured below:
8+
9+
.. image:: /tutorials/images/majestic_castle.png
10+
:width: 512px
11+
:height: 512px
12+
:scale: 50 %
13+
:align: right
14+
"""
15+
16+
# %%
17+
# Imports and Model Definition
18+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
20+
import torch
21+
from diffusers import DiffusionPipeline
22+
23+
import torch_tensorrt
24+
25+
model_id = "CompVis/stable-diffusion-v1-4"
26+
device = "cuda:0"
27+
28+
# Instantiate Stable Diffusion Pipeline with FP16 weights
29+
pipe = DiffusionPipeline.from_pretrained(
30+
model_id, revision="fp16", torch_dtype=torch.float16
31+
)
32+
pipe = pipe.to(device)
33+
34+
backend = "torch_tensorrt"
35+
36+
# Optimize the UNet portion with Torch-TensorRT
37+
pipe.unet = torch.compile(
38+
pipe.unet,
39+
backend=backend,
40+
options={
41+
"truncate_long_and_double": True,
42+
"precision": torch.float16,
43+
},
44+
dynamic=False,
45+
)
46+
47+
# %%
48+
# Inference
49+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
51+
prompt = "a majestic castle in the clouds"
52+
image = pipe(prompt).images[0]
53+
54+
image.save("images/majestic_castle.png")
55+
image.show()

0 commit comments

Comments
 (0)