Skip to content

[executorch][native] Add Argument tagged union to the in-memory IR - #22278

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

[executorch][native] Add Argument tagged union to the in-memory IR#22278
SS-JIA wants to merge 1 commit into
gh/SS-JIA/615/basefrom
gh/SS-JIA/615/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::Argument, the in-memory form of an fx node argument, mirroring the
schema ArgumentValue union but with in-graph references resolved to ValueId
arena indices instead of SSA-name strings (the deserializer will do the name ->
id resolution).

Argument is a tagged union over the 13 payload structs (TensorArg, IntArg,
TensorListArg, GraphArg, ...), backed by a std::variant whose alternatives
are declared in ArgKind order so kind() is the variant's index. A
static_assert pins each kind to its alternative and checks the two lists are
the same length, so they cannot drift apart -- and the variant keeps the
non-trivial payloads (std::string, std::vector) correct without hand-written
lifetime management. Payloads are read via kind() + throwing as_*()
accessors, the same idiom as Value.

Symbolic scalar args carry both a literal value and an id (valid id =>
symbolic, e.g. a sym_size result). OptionalTensorListArg collapses the
schema's parallel has_value[] into a kInvalid sentinel per element.
GraphArg holds a GraphId (index into a subgraph arena that lands with
Graph/Model), not an owned subgraph, so Argument needs no Graph
dependency, forward declaration, or incomplete-type destructor. NamedArgument
wraps an Argument with its op-schema parameter name and an in-place mutated
flag.

Also adds using GraphId = int32_t; to Ids.h for the GraphArg handle, and
extends the IR printer (utils/Print.{h,cpp}) with to_string(const Argument&).

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

Differential Revision: D114396764

[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/22278

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit 73ba529 with merge base a5f15b5 (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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.

@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