Skip to content

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

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

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

Argument is a hand-rolled real tagged union: an ArgKind tag over a C union
of the 13 payload structs (TensorArg, IntArg, TensorListArg, GraphArg,
...). This matches the value layer's existing style (Scalar, Value) and
keeps storage compact (size = largest payload + tag) rather than pulling in
std::variant. Because several payloads are non-trivial (std::string,
std::vector), lifetime is managed by hand via destroy() /
construct_from(const&) / construct_from(&&); copy-assign builds a temporary
then steals it through the noexcept move-assign for a strong exception
guarantee. Payloads are read via kind() + throwing as_*() accessors, the
same idiom as Value.

Symbolic scalar args carry both a literal value and a ref (valid ref =>
symbolic, e.g. a sym_size result). OptionalTensorListArg collapses the
schema's parallel has_value[] into a kInvalid sentinel per element.
GraphArg holds a GraphRef (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 GraphRef = int32_t; to Ids.h for the GraphArg handle.

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

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 71e74aa with merge base 9a2d135 (image):
💚 Looks good so far! There are no failures yet. 💚

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.

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