Skip to content

Commit ae733c6

Browse files
authored
chore: fix docs for export [release/2.1] (#2448)
Signed-off-by: Dheeraj Peri <[email protected]>
1 parent 42f87f2 commit ae733c6

File tree

4 files changed

+24
-108
lines changed

4 files changed

+24
-108
lines changed

docsrc/dynamo/dynamo_export.rst

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. _dynamo_export:
22

3-
Compiling ``ExportedPrograms`` with Torch-TensorRT
3+
Compiling Exported Programs with Torch-TensorRT
44
=============================================
55
.. currentmodule:: torch_tensorrt.dynamo
66

@@ -9,8 +9,6 @@ Compiling ``ExportedPrograms`` with Torch-TensorRT
99
:undoc-members:
1010
:show-inheritance:
1111

12-
Using the Torch-TensorRT Frontend for ``torch.export.ExportedPrograms``
13-
--------------------------------------------------------
1412
Pytorch 2.1 introduced ``torch.export`` APIs which
1513
can export graphs from Pytorch programs into ``ExportedProgram`` objects. Torch-TensorRT dynamo
1614
frontend compiles these ``ExportedProgram`` objects and optimizes them using TensorRT. Here's a simple
@@ -43,8 +41,7 @@ Some of the frequently used options are as follows:
4341

4442
The complete list of options can be found `here <https://github.com/pytorch/TensorRT/blob/123a486d6644a5bbeeec33e2f32257349acc0b8f/py/torch_tensorrt/dynamo/compile.py#L51-L77>`_
4543

46-
.. note:: We do not support INT precision currently in Dynamo. Support for this currently exists in
47-
our Torchscript IR. We plan to implement similar support for dynamo in our next release.
44+
.. note:: We do not support INT precision currently in Dynamo. Support for this currently exists in our Torchscript IR. We plan to implement similar support for dynamo in our next release.
4845

4946
Under the hood
5047
--------------

docsrc/user_guide/dynamo_export.rst

-82
This file was deleted.

docsrc/user_guide/saving_models.rst

+21-20
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ The following code illustrates this approach.
2929
import torch_tensorrt
3030
3131
model = MyModel().eval().cuda()
32-
inputs = torch.randn((1, 3, 224, 224)).cuda()
32+
inputs = [torch.randn((1, 3, 224, 224)).cuda()]
3333
trt_gm = torch_tensorrt.compile(model, ir="dynamo", inputs) # Output is a torch.fx.GraphModule
34-
trt_traced_model = torchtrt.dynamo.serialize(trt_gm, inputs)
34+
trt_traced_model = torch.jit.trace(trt_gm, inputs)
3535
torch.jit.save(trt_traced_model, "trt_model.ts")
3636
3737
# Later, you can load it and run inference
3838
model = torch.jit.load("trt_model.ts").cuda()
39-
model(inputs)
39+
model(*inputs)
4040
4141
b) ExportedProgram
4242
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -50,39 +50,40 @@ b) ExportedProgram
5050
import torch_tensorrt
5151
5252
model = MyModel().eval().cuda()
53-
inputs = torch.randn((1, 3, 224, 224)).cuda()
54-
trt_gm = torch_tensorrt.compile(model, ir="dynamo", inputs) # Output is a torch.fx.GraphModule
53+
inputs = [torch.randn((1, 3, 224, 224)).cuda()]
54+
exp_program = torch_tensorrt.dynamo.trace(model, inputs)
55+
trt_gm = torch_tensorrt.dynamo.compile(exp_program, inputs) # Output is a torch.fx.GraphModule
5556
# Transform and create an exported program
56-
trt_exp_program = torch_tensorrt.dynamo.export(trt_gm, inputs, call_spec, ir="exported_program")
57+
trt_exp_program = torch_tensorrt.dynamo.export(trt_gm, inputs, exp_program.call_spec, ir="exported_program")
5758
torch.export.save(trt_exp_program, "trt_model.ep")
5859
5960
# Later, you can load it and run inference
6061
model = torch.export.load("trt_model.ep")
61-
model(inputs)
62+
model(*inputs)
6263
6364
`torch_tensorrt.dynamo.export` inlines the submodules within a GraphModule to their corresponding nodes, stiches all the nodes together and creates an ExportedProgram.
6465
This is needed as `torch.export` serialization cannot handle serializing and deserializing of submodules (`call_module` nodes).
6566

66-
NOTE: This way of saving the models using `ExportedProgram` is experimental. Here is a known issue : https://github.com/pytorch/TensorRT/issues/2341
67+
.. note:: This way of saving the models using `ExportedProgram` is experimental. Here is a known issue : https://github.com/pytorch/TensorRT/issues/2341
6768

6869

6970
Torchscript IR
7071
-------------
7172

72-
In Torch-TensorRT 1.X versions, the primary way to compile and run inference with Torch-TensorRT is using Torchscript IR.
73-
This behavior stays the same in 2.X versions as well.
73+
In Torch-TensorRT 1.X versions, the primary way to compile and run inference with Torch-TensorRT is using Torchscript IR.
74+
This behavior stays the same in 2.X versions as well.
7475

75-
.. code-block:: python
76+
.. code-block:: python
7677
77-
import torch
78-
import torch_tensorrt
78+
import torch
79+
import torch_tensorrt
7980
80-
model = MyModel().eval().cuda()
81-
inputs = torch.randn((1, 3, 224, 224)).cuda()
82-
trt_ts = torch_tensorrt.compile(model, ir="ts", inputs) # Output is a ScriptModule object
83-
torch.jit.save(trt_ts, "trt_model.ts")
81+
model = MyModel().eval().cuda()
82+
inputs = [torch.randn((1, 3, 224, 224)).cuda()]
83+
trt_ts = torch_tensorrt.compile(model, ir="ts", inputs) # Output is a ScriptModule object
84+
torch.jit.save(trt_ts, "trt_model.ts")
8485
85-
# Later, you can load it and run inference
86-
model = torch.jit.load("trt_model.ts").cuda()
87-
model(inputs)
86+
# Later, you can load it and run inference
87+
model = torch.jit.load("trt_model.ts").cuda()
88+
model(*inputs)
8889

py/torch_tensorrt/dynamo/_exporter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def export(
5353
return exp_program
5454
else:
5555
raise ValueError(
56-
"Invalid ir : {ir} provided for serialization. Options include torchscript | exported_program"
56+
f"Invalid ir : {ir} provided for serialization. Options include torchscript | exported_program"
5757
)
5858

5959

0 commit comments

Comments
 (0)