[executorch][native] Add Graph index arena to the in-memory IR - #22103
Open
SS-JIA wants to merge 1 commit into
Open
[executorch][native] Add Graph index arena to the in-memory IR#22103SS-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/22103
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Cancelled JobAs of commit 0cbcf8b with merge base 9a2d135 ( CANCELLED JOB - The following job was cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Aug 24, 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):
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.Pure std only (no ExecuTorch, no flatbuffers), consistent with the rest of the
standalone
ptnruntime.Differential Revision: D114396767