[executorch][native] Add Graph index arena to the in-memory IR - #22265
Closed
SS-JIA wants to merge 1 commit into
Closed
[executorch][native] Add Graph index arena to the in-memory IR#22265SS-JIA wants to merge 1 commit into
SS-JIA wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22265
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Aug 28, 2026
This PR needs a
|
SS-JIA
had a problem deploying
to
cherry-pick-bot
August 28, 2026 19:44 — with
GitHub Actions
Failure
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):
Adds
ptn::Graph, the index arena that owns the value layer landed so far. Itis a pure function body (mirrors the schema
Graph): it holds theNodes andValues that theNodeRef/ValueRefhandles point into, the ordered graphinput / output value lists, and -- recursively -- the subgraph bodies for
higher-order ops. Stateful method-level bindings (constants, output specs,
mutable buffers) are deferred to a later
Methodtype.Design decisions baked in:
Per-graph subgraph arena.
Graphownsstd::vector<Graph> subgraphsandGraphRefindexes the enclosing graph'ssubgraphs, matching the schema'srecursion and the per-Graph SSA namespace so a subgraph stays self-contained
with its parent. (A
std::vector<Graph>member ofGraphis legal C++17 --the standard containers permit an incomplete value type at the point of the
member declaration.)
Storage identity vs execution order are decoupled.
nodesis anappend-only arena so a
NodeRefnever shifts (the index-arena invariant),while
schedule(std::vector<NodeRef>) carries the topological / executionorder a runtime walks. At load the arena order equals the wire's topological
order and
scheduleis the identity[0, n)(reset_schedule()); acrossmutation the arena order is no longer topological, so
scheduleisauthoritative -- reorder / insert there (moving
int32s, invalidating no ref)rather than moving storage. Deletion via tombstone + a compacting pass is
deferred until a mutating pass needs it.
Pure arena.
inputs/outputsareValueReflists (schema SSA namesresolved to refs at deserialize); no
tensor_valuesside table in memory(each
Valuealready carries itsTensorMeta); the name to ref map staysdeserializer-local.
rebuild_def_use()recomputes everyValue'sproducer/consumersfrom thenodes (order-independent -- it walks the arena, not
schedule). Placeholder andOutput nodes are real entries in
nodes, so def-use is uniform: a graph inputvalue's producer is its placeholder node, and graph inputs are identified by
membership in
inputs, not byproducer == kInvalid. This corrects the nowstale
Value.hproducercomment (also in this diff). Bounds-checkednode()/value()/subgraph()accessors throw on an invalid ref, andto_string()gives a multi-line dump inscheduleorder.consumer_refsis a set of consuming nodes rather than a bag of uses, soadd(x, x)lists its consumer once andsize()counts consumers. Since nodesare walked in arena order a repeated operand appends consecutively, so a tail
check keeps that exact without a lookup structure.
rebuild_def_use()distinguishes the two things an unusable ref can mean.kInvalidis an absent operand and is skipped; a ref that is set but does notaddress the value arena can only be a corrupt graph, and now throws rather than
being skipped, which would have left def-use half-wired with no signal. That
matches the accessors, which already throw on a bad ref.
Pure std only (no ExecuTorch, no flatbuffers), consistent with the rest of the
standalone
ptnruntime.Differential Revision: D114396767