[executorch][native] Add the .ptn package facade and its inspector - #22471
Open
SS-JIA wants to merge 2 commits into
Open
[executorch][native] Add the .ptn package facade and its inspector#22471SS-JIA wants to merge 2 commits into
SS-JIA wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22471
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit a3faec1 with merge base 2c1da32 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Sep 2, 2026
This PR needs a
|
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.
Stack from ghstack (oldest at bottom):
The three readers below this each handle one layer of a
.ptn.Packageis thefacade that puts them together and answers the question the runtime actually
has: give me the program, and give me the bytes for constant
key.Package::loadopens the archive, takes theprogram.ptgmember as theserialized program, parses
program.safetensorswhen present, and readsaliases.jsonwhen the exporter deduplicated byte-identical immutableconstants.
constant(key)resolves an alias to its owner and reports which keyowns the bytes, so a caller can tell a shared weight from a private one.
owner_keyscounts each blob once;keyslists everything resolvable.It takes ownership of a moved buffer rather than copying, so a model-sized
package is resident once. Every span it hands out -- and the zip and safetensors
readers it holds -- aliases that one buffer.
std::vector's move preserves thebuffer address, which is what makes the defaulted move constructor safe; copy is
deleted, because a package is model-sized.
A package with no constants is a normal case, not an error:
tensors_is astd::optionaland stays empty, since a program that references nothing has nosafetensors member at all.
ptn_inspectoris the tool that exercises all of it.--constantslists everykey with dtype, shape, size and an FNV-1a fingerprint of its bytes, then
reconciles the listing against the methods'
DataBindings in both directions --bindings with no package key, and package keys no binding claims. Two behaviour
notes:
--constantsis a flag rather than taking a path, since the externalconstant file it would have named does not exist in any current format; and the
default mode verifies the flatbuffer rather than only checking for
NPTGatoffset 4, which previously reported success on a truncated program. A bare
.ptgis rejected here with a message pointing atptg_inspector.Differential Revision: D118480654