You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docsrc/user_guide/saving_models.rst
+22-11Lines changed: 22 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,10 @@ The `output_format` can take the following options
22
22
* `torchscript` (or) `ts` : This returns a TorchScript module
23
23
* `graph_module` (or) `fx` : This returns a torch.fx.GraphModule which can be traced into Torchscript to save to disk.
24
24
25
-
a) Converting to Torchscript
25
+
a) Torchscript
26
26
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27
27
28
-
`torch.fx.GraphModule` objects cannot be serialized directly. Hence we use `torch.jit.trace` to convert this into a `ScriptModule` object which can be saved to disk.
29
-
The following code illustrates this approach.
28
+
If you set the `output_format="torchscript"`, this will return a `ScriptModule` which can be serialized via torch.jit.save
30
29
31
30
.. code-block:: python
32
31
@@ -35,6 +34,7 @@ The following code illustrates this approach.
`torch_tensorrt.dynamo.export` inlines the submodules within a GraphModule to their corresponding nodes and stiches all the nodes together.
66
-
This is needed as `torch._export` serialization cannot handle serializing and deserializing of submodules (`call_module` nodes).
65
+
c) GraphModule
66
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67
+
68
+
We can also return a `torch.fx.GraphModule` object as the output of Torch-TensorRT compilation by setting `output_format="graph_module"`.
69
+
Internally, partitioning, lowering, conversion phases operate using GraphModule objects. These can be either traced into a Torchscript modules or
70
+
exported into `ExportedProgram` objects
71
+
72
+
.. code-block:: python
67
73
68
-
.. note:: This way of saving the models using `ExportedProgram` is experimental. Here is a known issue : https://github.com/pytorch/TensorRT/issues/2341
0 commit comments