Repository navigation
feat(executorch): do not retrace by default when saving a .pte - #4881
Merged
cehongwang merged 1 commit intoOct 20, 2026
Merged
Conversation
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
force-pushed
the
executorch-save-no-retrace-default
branch
from
October 19, 2026 21:10
9ad4cee to
48c372f
Compare
This was referenced Oct 21, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:To make it work, users add
retrace=False, and oftenarg_inputs, to every call. The ExecuTorch guide and its examples all do this.torch_tensorrt.executorch.export()already treats an unsetretraceas False, so the two entry points disagree.What this change does
retracenow defaults toNone.save()picks the value from the output format: False for"executorch", True for every other format, as before.retrace=Trueorretrace=Falsestill wins.save()snippets in the docs dropretrace=Falseandarg_inputs.After this change:
Callers that pass inputs and relied on the old default now take the
retrace=Falsepath. For a module fromtorch_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 needsretrace=True.Tests
tests/py/dynamo/executorch/test_api.py. The first saves a GraphModule to ExecuTorch with neitherretracenor 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/executorchandtest_exporter_inlining.py: same results before and after, apart from the new test.retrace=True. Each.pteloads in the ExecuTorch runtime and matches eager output. With inputs, the old and new code write the same file.retraceand no inputs.