Skip to content

Transforms: Keep integer scalars exact when replacing them with tensors - #24625

Open
abm-77 wants to merge 1 commit into
pytorch:mainfrom
abm-77:transforms-exact-integer-scalar
Open

abm-77 wants to merge 1 commit into
pytorch:mainfrom
abm-77:transforms-exact-integer-scalar

Conversation

@abm-77

@abm-77 abm-77 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ReplaceScalarWithTensorArgPass passes the scalar to full through float(), which rounds an integer above 2**53. With the Arm int64 extension, x == 2**53 + 1 then compares against 2**53. Integer scalars now go to full unchanged, and float scalars are unchanged.

Split out of #24128 at the Arm maintainers' request. Found while adding int64 comparisons in #24622.

Test Plan

Added test_replace_scalar_with_tensor.py: an integer scalar of 2**53 + 1 is carried exactly and a float scalar is unchanged. With #24622, x == 2**53 + 1 and x > 2**53 + 1 under TOSA-1.1+INT+int64 match the reference model.

This PR was authored with Claude Code.

cc @nil-is-all @YufengShi-dudu @Erik-Lundell

Copilot AI balanced review requested due to automatic review settings November 4, 2026 18:23
@pytorch-bot

pytorch-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 19 Awaiting Approval

As of commit 523020b with merge base d1f597e (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

@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 Nov 4, 2026

Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded for the change to preserve integer scalar precision during tensor replacement.

No open issues 🎉

What changed in this PR

This PR preserves large integer scalars in the shared ReplaceScalarWithTensorArgPass, supporting exact int64 comparisons in the related Arm backend work.

Changes:

  • Pass integer scalars directly to full, avoiding precision loss from conversion to float.
  • Add regression tests for exact handling of 2**53 + 1 and unchanged float handling.
File Description
backends/​transforms/​test/​test_replace_scalar_with_tensor.py Tests integer precision and unchanged float scalar handling.
backends/​transforms/​replace_scalar_with_tensor.py Preserves integer scalars when creating replacement tensors.

Review effort: Balanced

@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Nov 4, 2026
@abm-77
abm-77 force-pushed the transforms-exact-integer-scalar branch from 0d33694 to 523020b Compare November 5, 2026 17:14
Copilot AI balanced review requested due to automatic review settings November 5, 2026 17:14

Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded for the change to preserve large integer scalars in the scalar-to-tensor transform.

No open issues 🎉

Review effort: Balanced

@abm-77

abm-77 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: none"

@pytorch-bot pytorch-bot Bot added the release notes: none Do not include this in the release notes label Nov 5, 2026

This branch has not been deployed

No deployments
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. community: contribution PRs coming from community (excluding hardware partners) release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants