Skip to content

[executorch][native] Add Graph index arena to the in-memory IR - #22103

Open
SS-JIA wants to merge 1 commit into
gh/SS-JIA/592/basefrom
gh/SS-JIA/592/head
Open

[executorch][native] Add Graph index arena to the in-memory IR#22103
SS-JIA wants to merge 1 commit into
gh/SS-JIA/592/basefrom
gh/SS-JIA/592/head

Conversation

@SS-JIA

@SS-JIA SS-JIA commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds ptn::Graph, the index arena that owns the value layer landed so far. It
is a pure function body (mirrors the schema Graph): it holds the Nodes and
Values that the NodeRef / ValueRef handles point into, the ordered graph
input / 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 Method type.

Design decisions baked in:

  • Per-graph subgraph arena. Graph owns std::vector<Graph> subgraphs and
    GraphRef indexes the enclosing graph's subgraphs, matching the schema's
    recursion and the per-Graph SSA namespace so a subgraph stays self-contained
    with its parent. (A std::vector<Graph> member of Graph is 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. nodes is an
    append-only arena so a NodeRef never shifts (the index-arena invariant),
    while schedule (std::vector<NodeRef>) carries the topological / execution
    order a runtime walks. At load the arena order equals the wire's topological
    order and schedule is the identity [0, n) (reset_schedule()); across
    mutation the arena order is no longer topological, so schedule is
    authoritative -- 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 / outputs are ValueRef lists (schema SSA names
    resolved to refs at deserialize); no tensor_values side table in memory
    (each Value already carries its TensorMeta); the name to ref map stays
    deserializer-local.

rebuild_def_use() recomputes every Value's producer / consumers from the
nodes (order-independent -- it walks the arena, not schedule). Placeholder and
Output nodes are real entries in nodes, so def-use is uniform: a graph input
value's producer is its placeholder node, and graph inputs are identified by
membership in inputs, not by producer == kInvalid. This corrects the now
stale Value.h producer comment (also in this diff). Bounds-checked
node() / value() / subgraph() accessors throw on an invalid ref, and
to_string() gives a multi-line dump in schedule order.

Pure std only (no ExecuTorch, no flatbuffers), consistent with the rest of the
standalone ptn runtime.

Differential Revision: D114396767

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

🔗 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 Job

As of commit 0cbcf8b with merge base 9a2d135 (image):

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant