Repository navigation
fix(executorch): safer .ptd output from save() with external_engine_data - #4916
Closed
shoumikhin wants to merge 3 commits into
Closed
shoumikhin wants to merge 3 commits into
shoumikhin wants to merge 3 commits into
Conversation
shoumikhin
force-pushed
the
executorch-ptd-save-safety
branch
from
October 22, 2026 18:58
ab6e3c5 to
956521e
Compare
save(file_path="engines.ptd", external_engine_data="engines") wrote the program, then wrote the engines to the same file, and returned normally. Only the engines were left, so there was no program to load. save() now checks the two names before it exports anything and raises a ValueError when they are the same file.
After writing a program's external data, save() logged "point the runtime's data-files at this directory". The loaders want the .ptd file itself: Runtime.load_program(pte, data_path=<directory>) fails with "Failed to load data map", and so does the C++ Module. The log line now lists the full path of every .ptd file it wrote and says to pass the file, not the directory.
The deployment and saving guides did not mention external_engine_data=, so a reader learned neither that such a program needs its .ptd at load nor how to pass it. And save() replaces an existing .ptd of the same name, so two programs saved into one directory with the same name share one file, and the first one then fails to load with no warning at save time. Add a short section to the ExecuTorch guide with a save and load example, a note that the .ptd is trusted input like the .pte, and a warning about the shared name. Link it from the saving guide, and say in the save() docstring that the file is replaced, so each program in a directory needs its own name.
shoumikhin
force-pushed
the
executorch-ptd-save-safety
branch
from
October 22, 2026 19:11
956521e to
2a984a7
Compare
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(..., output_format="executorch", external_engine_data="engines")writes the TensorRT engines toengines.ptdnext to the.pte. Three things can go wrong with that file, and none of them is reported:file_path="engines.ptd", save writes the program and then writes the engines over it. It returns normally, and there is no program left to load..ptdfile itself.Runtime.load_program(pte, data_path=<directory>)fails with "Failed to load data map", and so does the C++Module..ptdname does not depend on the.ptename, and save replaces an existing file. So two programs saved into one directory with the same name share one.ptdthat holds only the second program's engines. The first program then fails to load. The user guides do not mentionexternal_engine_data=at all.What this change does
Three commits, one per problem:
save()checks the two names before it exports anything, and raises aValueErrorwhen the program and the engine file would be the same file.The log line lists the full path of every
.ptdfile it wrote, and says to pass the file, not the directory.The ExecuTorch guide gets a short section on keeping engines in a
.ptdfile:It says the
.ptdis trusted input, like the.pte, and warns about two programs sharing one name in a directory, next to the existing warning for the CUDA backend's file. The saving guide links to it, and thesave()docstring says the file is replaced, so each program needs its own name.What was tested
On Linux x86-64 with the pinned ExecuTorch nightly:
tests/py/dynamo/executorch/test_external_engine_data.py: 29 passed..ptdpath in the message.