Skip to content

[executorch][native] Add Scalar value type to the in-memory IR - #22220

Closed
SS-JIA wants to merge 3 commits into
gh/SS-JIA/600/basefrom
gh/SS-JIA/600/head
Closed

[executorch][native] Add Scalar value type to the in-memory IR#22220
SS-JIA wants to merge 3 commits into
gh/SS-JIA/600/basefrom
gh/SS-JIA/600/head

Conversation

@SS-JIA

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

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Add Scalar (backends/native/runtime/graph/Scalar.{h,cpp}), a concrete scalar
value — a std::variant<int64_t, double, bool>, analogous to c10::Scalar.
Tag is pinned to the variant's alternative order, so tag() is its index and
the two cannot drift apart.

Construct implicitly from int / int64_t / double / bool; read via strict
accessors (to_int / to_double / to_bool, which throw on a tag mismatch) or
the promoting to<T>() template (a std::visit that static_casts whichever
alternative is live, like c10::Scalar::to<T>()). Plus tag() / is_*()
predicates and tag_name() / to_string() debug helpers. No "none" state — the
graph's Value owns that.

Every pointer converts to bool, so the implicit constructors would otherwise
let Scalar s = some_ptr; compile and quietly produce a Bool. A deleted
Scalar(T*) template rejects that at the call site while leaving the numeric
constructors implicit.

to_string() renders a double through the shared ptn::format_double
(graph/Format.h) rather than std::to_string, whose fixed six-decimal format
prints 1e-300 as "0.000000" and 1e300 as 312 digits.

The constructors and the tag() / is_*() / to<T>() readers are constexpr,
so a Scalar can be built and inspected in a constant-evaluated context.

Pure std — no ExecuTorch and no flatbuffers dependency. Mirrored into both the
fbcode/ and xplat/ trees to match the native backend layout.

Authored with Claude Code.

Differential Revision: D114396762

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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.

[ghstack-poisoned]

@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.

[ghstack-poisoned]
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