Skip to content

[executorch][native] Add Method + ValueRole to the in-memory IR - #22281

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

[executorch][native] Add Method + ValueRole to the in-memory IR#22281
SS-JIA wants to merge 1 commit into
gh/SS-JIA/618/basefrom
gh/SS-JIA/618/head

Conversation

@SS-JIA

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

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds ptn::Method, the stateful wrapper around one top-level Graph, and the
per-value ValueRole classification it drives. Graph is a pure function body;
Method binds its placeholder and output values to the things outside the pure
dataflow — external constant data, non-persistent buffers, and the per-output
classification that separates a real result from a state writeback. It mirrors
the schema Method but resolves every in-graph reference to a ValueId.

Method lives at runtime/ (peer to the Program reader), above the graph/
arena package, since it is a method-level rather than a graph-level concept.

New types:

  • ValueRole (on Value, in graph/Value.h): UserInput / Parameter / Buffer /
    ConstantTensor / Intermediate. The placeholder roles are pinned to the schema
    InputKind ids; Intermediate extends them for a value a node produces.
    Stamped by the deserializer, it gives an O(1) per-value answer to "how is this
    value's storage owned / sourced" (the memory planner and runtime binder are
    the eventual consumers).

  • DataBinding (schema NamedTensorRef + MutableBufferSpec, merged): binds a
    placeholder ValueId to external storage. key is the fqn (an
    external-constant-file key when has_data, else the buffer's cross-method
    identity), and the binding is the only place it lives; has_data selects the
    load path (fetch bytes vs zero-init at load); mutated marks a Buffer written
    in place whose state persists across executions; role mirrors the bound
    value's role for direct access when iterating bindings.

  • OutputKind (graph-level: UserOutput / BufferMutation / UserInputMutation) and
    OutputSpec (aligned to graph.output_ids by index). A mutation output's
    target_id is a ValueId to the mutated placeholder value in this graph
    (both the mutated user input and the mutated buffer are lifted placeholders
    here), replacing the schema's dual-namespace target string; the wire fqn /
    SSA name is recovered from that value.

  • Method itself: name, Graph graph, data_bindings, output_specs. HOP
    subgraphs carry no bindings (their params are lifted here and passed as
    operands), which is why Method wraps Graph rather than folding into it.

  • to_string(const Method&) (utils/Print.{h,cpp}, target runtime:print) —
    the method layer of the IR printer, split from the graph-level one only
    because Method sits above the graph/ package.

Pure std only (no ExecuTorch, no flatbuffers).

Differential Revision: D114426388

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22281

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit 809a1f7 with merge base a5f15b5 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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 28, 2026

@digantdesai digantdesai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants