Skip to content

feat(executorch): do not retrace by default when saving a .pte - #4881

Merged
cehongwang merged 1 commit into
pytorch:mainfrom
shoumikhin:executorch-save-no-retrace-default
Oct 20, 2026
Merged

cehongwang merged 1 commit into
pytorch:mainfrom
shoumikhin:executorch-save-no-retrace-default

Conversation

@shoumikhin

Copy link
Copy Markdown
Contributor

What is wrong today

torch_tensorrt.save() re-exports a compiled module by default (retrace=True), and re-exporting needs example inputs. So the shortest way to write an ExecuTorch file fails:

trt_gm = torch_tensorrt.compile(model, ir="dynamo", inputs=inputs)
torch_tensorrt.save(trt_gm, "model.pte", output_format="executorch")
# ValueError: ... retrace is True, however no inputs specs were provided ...

To make it work, users add retrace=False, and often arg_inputs, to every call. The ExecuTorch guide and its examples all do this. torch_tensorrt.executorch.export() already treats an unset retrace as False, so the two entry points disagree.

What this change does

  • retrace now defaults to None. save() picks the value from the output format: False for "executorch", True for every other format, as before.
  • An explicit retrace=True or retrace=False still wins.
  • The ExecuTorch save() snippets in the docs drop retrace=False and arg_inputs.

After this change:

torch_tensorrt.save(trt_gm, "model.pte", output_format="executorch")

Callers that pass inputs and relied on the old default now take the retrace=False path. For a module from torch_tensorrt.compile() this writes the same .pte, and the existing warning says the inputs are not needed. A GraphModule that did not go through Torch-TensorRT compilation still needs retrace=True.

Tests

  • Two new unit tests in tests/py/dynamo/executorch/test_api.py. The first saves a GraphModule to ExecuTorch with neither retrace nor inputs and checks it takes the no-retrace path. It fails without this change. The second checks that other formats still retrace by default.
  • tests/py/dynamo/executorch and test_exporter_inlining.py: same results before and after, apart from the new test.
  • End to end on one H100 with nightly wheels: static and dynamic shapes, with and without inputs, and with an explicit retrace=True. Each .pte loads in the ExecuTorch runtime and matches eager output. With inputs, the old and new code write the same file.
  • The four ExecuTorch examples (static shape, dynamic shape, TensorRT plus CUDA, device resident) run with no retrace and no inputs.

@meta-cla meta-cla Bot added the cla signed label Oct 19, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation component: tests Issues re: Tests component: api [Python] Issues re: Python API component: api [C++] Issues re: C++ API labels Oct 19, 2026
@github-actions
github-actions Bot requested a review from narendasan October 19, 2026 21:03
torch_tensorrt.save() re-exports a compiled GraphModule by default
(retrace=True). For output_format="executorch" that default does not fit:

- Re-exporting needs example inputs, so the shortest call,
  save(trt_gm, "model.pte", output_format="executorch"), fails with
  "no inputs specs were provided".
- The ExecuTorch guide and its examples pass retrace=False for this format.
- torch_tensorrt.executorch.export() already treats an unset retrace as
  False. Only save() differs.

retrace now defaults to None, and save() resolves it from the output
format: False for "executorch", True for every other format, as before.
An explicit retrace=True or retrace=False still wins.

Callers that passed inputs and relied on the old default now take the
retrace=False path. For a module from torch_tensorrt.compile() this writes
the same .pte, and the existing warning says the inputs are not needed. A
GraphModule that did not come from Torch-TensorRT still needs retrace=True.

The ExecuTorch save() snippets in the docs drop retrace=False and
arg_inputs.
@shoumikhin
shoumikhin force-pushed the executorch-save-no-retrace-default branch from 9ad4cee to 48c372f Compare October 19, 2026 21:10
@narendasan narendasan added this to the v2.15.0 milestone Oct 20, 2026

@cehongwang cehongwang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cehongwang
cehongwang merged commit 17b56b8 into pytorch:main Oct 20, 2026
55 checks passed
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 21, 2026
…ch#4881)

Co-authored-by: shoumikhin <shoumikhin@users.noreply.github.com>
(cherry picked from commit 17b56b8)
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 22, 2026
…ch#4881)

Co-authored-by: shoumikhin <shoumikhin@users.noreply.github.com>
(cherry picked from commit 17b56b8)
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 23, 2026
…ch#4881)

Co-authored-by: shoumikhin <shoumikhin@users.noreply.github.com>
(cherry picked from commit 17b56b8)
lanluo-nvidia pushed a commit that referenced this pull request Oct 26, 2026
Co-authored-by: shoumikhin <shoumikhin@users.noreply.github.com>
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 26, 2026
On this branch the guide was picked after the change that stops save()
from retracing, so its examples still pass retrace=False and
arg_inputs, and the text presents them as two extra arguments save
needs. For the ExecuTorch format save() now keeps the compiled graph as
it is and needs no example inputs. The examples now use one extra
argument, output_format="executorch", as on main.

The CUDA graph paragraph also said that engines on the shared
activation scratch never replay. With pytorch#4833 they do, each with its own
buffers for its inputs and outputs, and they record again when the
pool moves to a larger buffer. The paragraph now says so.
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 26, 2026
On this branch the guide was picked after the change that stops save()
from retracing, so its examples still pass retrace=False and
arg_inputs, and the text presents them as two extra arguments save
needs. For the ExecuTorch format save() now keeps the compiled graph as
it is and needs no example inputs. The examples now use one extra
argument, output_format="executorch", as on main.

The CUDA graph paragraph also said that engines on the shared
activation scratch never replay. With pytorch#4833 they do, each with its own
buffers for its inputs and outputs, and they record again when the
pool moves to a larger buffer. The paragraph now says so.
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 27, 2026
On this branch the guide was picked after the change that stops save()
from retracing, so its examples still pass retrace=False and
arg_inputs, and the text presents them as two extra arguments save
needs. For the ExecuTorch format save() now keeps the compiled graph as
it is and needs no example inputs. The examples now use one extra
argument, output_format="executorch", as on main.

The CUDA graph paragraph also said that engines on the shared
activation scratch never replay. With pytorch#4833 they do, each with its own
buffers for its inputs and outputs, and they record again when the
pool moves to a larger buffer. The paragraph now says so.
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 27, 2026
On this branch the guide was picked after the change that stops save()
from retracing, so its examples still pass retrace=False and
arg_inputs, and the text presents them as two extra arguments save
needs. For the ExecuTorch format save() now keeps the compiled graph as
it is and needs no example inputs. The examples now use one extra
argument, output_format="executorch", as on main.

The CUDA graph paragraph also said that engines on the shared
activation scratch never replay. With pytorch#4833 they do, each with its own
buffers for its inputs and outputs, and they record again when the
pool moves to a larger buffer. The paragraph now says so.
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 28, 2026
On this branch the guide was picked after the change that stops save()
from retracing, so its examples still pass retrace=False and
arg_inputs, and the text presents them as two extra arguments save
needs. For the ExecuTorch format save() now keeps the compiled graph as
it is and needs no example inputs. The examples now use one extra
argument, output_format="executorch", as on main.

The CUDA graph paragraph also said that engines on the shared
activation scratch never replay. With pytorch#4833 they do, each with its own
buffers for its inputs and outputs, and they record again when the
pool moves to a larger buffer. The paragraph now says so.
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Oct 29, 2026
On this branch the guide was picked after the change that stops save()
from retracing, so its examples still pass retrace=False and
arg_inputs, and the text presents them as two extra arguments save
needs. For the ExecuTorch format save() now keeps the compiled graph as
it is and needs no example inputs. The examples now use one extra
argument, output_format="executorch", as on main.

The CUDA graph paragraph also said that engines on the shared
activation scratch never replay. With pytorch#4833 they do, each with its own
buffers for its inputs and outputs, and they record again when the
pool moves to a larger buffer. The paragraph now says so.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [C++] Issues re: C++ API component: api [Python] Issues re: Python API component: tests Issues re: Tests documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants