Skip to content

Arm backend: Prepare TOSA validation and lowering for int64 - #24128

Merged
zingo merged 7 commits into
pytorch:mainfrom
abm-77:arm-int64-spec-aware
Oct 29, 2026
Merged

zingo merged 7 commits into
pytorch:mainfrom
abm-77:arm-int64-spec-aware

Conversation

@abm-77

@abm-77 abm-77 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Map torch.int64 to TOSA INT64 and accept it in TosaArg when the
specification enables EXT-INT64. Extend dialect validators and node
visitors to accept int64 for operators covered by the extension.

Add dialect tests that verify int64 acceptance with the extension and
rejection without it.

Existing narrowing passes still convert int64 to int32. Preserving
int64 through those passes is deferred to a follow-up change.
Part 1 of 3.

This PR was authored with Claude Code.

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani

Copilot AI balanced review requested due to automatic review settings October 23, 2026 17:56
@pytorch-bot

pytorch-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⏳ No Failures, 1 Pending

As of commit 160c2b2 with merge base 4fe0253 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@meta-cla

meta-cla Bot commented Oct 23, 2026

Copy link
Copy Markdown

Hi @abm-77!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Oct 23, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@abm-77

abm-77 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: arm"

@pytorch-bot pytorch-bot Bot added the release notes: arm Changes to the ARM backend delegate label Oct 23, 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.

🟡 Changes recommended

Unresolved extension-handling gaps still cause unwanted narrowing, lowering failures, and CPU fallback for supported int64 operations.

4 open issues
What changed in this PR

This PR addresses #24095 by making the Arm backend preserve int64 tensors when the TOSA specification declares the int64 extension.

Changes:

  • Gate int64 narrowing passes on extension support.
  • Enable INT64 mapping and extension-aware validation across dialect operations and node visitors.
  • Add lowering cases for int64 arithmetic and scalar comparison.
File Description
backends/​arm/​tosa/​specification.py Add a context-based extension check.
backends/​arm/​tosa/​mapping.py Map INT64 and validate extension support.
backends/​arm/​tosa/​dialect/​ops/​unary_elementwise.py Allow extension-gated int64 unary operations.
backends/​arm/​tosa/​dialect/​ops/​ternary_elementwise.py Allow int64 SELECT values.
backends/​arm/​tosa/​dialect/​ops/​comparison.py Allow int64 comparisons.
backends/​arm/​tosa/​dialect/​ops/​binary_elementwise.py Allow int64 arithmetic and min/max validation.
backends/​arm/​test/​misc/​test_int64.py Add int64-extension lowering cases.
backends/​arm/​operators/​simple_node_visitor.py Support extension-gated input dtype lists.
backends/​arm/​operators/​operator_validation_utils.py Include INT64 in supported layout dtypes.
backends/​arm/​operators/​op_where.py Accept extension-gated INT64 values.
backends/​arm/​operators/​op_tosa_sub.py Enable INT64 subtraction.
backends/​arm/​operators/​op_tosa_reduce_sum.py Enable INT64 sum visitor validation.
backends/​arm/​operators/​op_tosa_reduce_min.py Enable INT64 minimum reduction validation.
backends/​arm/​operators/​op_tosa_reduce_max.py Enable INT64 maximum reduction validation.
backends/​arm/​operators/​op_tosa_neg.py Enable INT64 negation.
backends/​arm/​operators/​op_tosa_mul.py Enable INT64 multiplication validation.
backends/​arm/​operators/​op_tosa_minimum.py Enable INT64 elementwise minimum.
backends/​arm/​operators/​op_tosa_maximum.py Enable INT64 elementwise maximum.
backends/​arm/​operators/​op_tosa_identity.py Enable INT64 identity.
backends/​arm/​operators/​op_tosa_gt.py Enable INT64 greater-than operands.
backends/​arm/​operators/​op_tosa_ge.py Enable INT64 greater-or-equal operands.
backends/​arm/​operators/​op_tosa_eq.py Enable INT64 equality operands.
backends/​arm/​operators/​op_tosa_bitwise_not.py Enable INT64 bitwise NOT.
backends/​arm/​operators/​op_tosa_add.py Enable INT64 addition.
backends/​arm/​operators/​op_tosa_abs.py Enable INT64 absolute value.
backends/​arm/​operators/​op_flip.py Enable INT64 flip validation.
backends/​arm/​_passes/​insert_int32_casts_after_int64_placeholders.py Skip placeholder narrowing with the extension.
backends/​arm/​_passes/​convert_int64_output_ops_to_int32.py Guard output narrowing with an extension check.
backends/​arm/​_passes/​convert_int64_const_ops_to_int32.py Skip constant-operation narrowing with the extension.
backends/​arm/​_passes/​cast_int64_pass.py Skip buffer narrowing with the extension.

Review effort: Balanced

Comment thread backends/arm/_passes/convert_int64_output_ops_to_int32.py Outdated
Comment thread backends/arm/_passes/insert_int32_casts_after_int64_placeholders.py Outdated
Comment thread backends/arm/operators/operator_validation_utils.py
Comment thread backends/arm/operators/op_where.py Outdated
Copilot AI balanced review requested due to automatic review settings October 23, 2026 18:18
@nil-is-all

Copy link
Copy Markdown
Contributor

Thanks for filing the bug report and the PR, @abm-77. As we wait on Arm maintainers to review, could you sign the CLA?

@nil-is-all nil-is-all added the partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm label Oct 23, 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.

🟡 Changes recommended

Scalar precision loss and inconsistent partitioner checks can cause incorrect results or lowering failures, while the new tests do not verify int64 preservation.

4 open issues
3 previously missed issues

In code that hasn't changed since last review

Medium severity Reject unsupported int64 bitwise operators during partitioning

backends/​arm/​_passes/​insert_int32_casts_after_int64_placeholders.py:120

Skipping placeholder narrowing lets unsupported int64 operators reach lowering. Under TOSA-1.1+INT+int64, BoolBitwiseSupported accepts int64 x | y, but the BITWISE_OR dialect validator and visitor only accept int8/int16/int32. Lowering then raises instead of leaving the operation on the portable path; BITWISE_XOR has the same mismatch. Keep the narrowing skip, but reject these unsupported dtype/operator combinations during partitioning, or implement int64 lowering where the TOSA specification permits it.

Medium severity Assert delegation and preservation of INT64 operands

backends/​arm/​test/​misc/​test_int64.py:158

These cases only check that conversion completes; they do not assert delegation or preserved INT64 operands. They can therefore pass if the operators fall back to CPU or are silently narrowed. The small inputs would also hide narrowing in an output comparison. Assert that the expected operators delegate and retain INT64 operands, including the inputs to GREATER whose output is BOOL. Alternatively, assert delegation and compare execution results using values outside the int32 range.

Medium severity Allow extension-enabled int64 comparison inputs in negative checks

backends/​arm/​tosa/​dialect/​ops/​comparison.py:44

The dialect now accepts int64 comparisons under TOSA-1.1+FP+int64, but _floating_profile_negative_checks() still installs CheckFPComparisonInputs whenever the INT profile is absent. That check rejects int64 inputs, so eq/gt/ge with int64 placeholders remain undelegated under this valid spec. Pass the specification to the negative check and allow extension-enabled int64 comparison inputs while preserving rejection for specs without the extension.

3 resolved since last review

Review effort: Balanced

Comment thread backends/arm/tosa/dialect/ops/comparison.py
Comment thread backends/arm/operator_support/slice_copy_support.py Outdated
Comment thread backends/arm/operator_support/where_support.py Outdated
Copilot AI balanced review requested due to automatic review settings October 23, 2026 18:26

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.

🟡 Changes recommended

Retained int64 OR/XOR operands can fail during lowering, and the new tests do not verify delegation or int64 preservation.

4 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Add delegation, operator, and INT64 preservation assertions

backends/​arm/​test/​misc/​test_int64.py:158

This chain checks only that lowering completes. It still passes if every operation falls back to CPU or if tensors are narrowed to int32; it neither asserts delegation nor executes or inspects the lowered computation. Add delegate-count and no-leftover-operator assertions, then verify INT64 tensor dtypes in the delegated graph or compare exact outputs with width-sensitive inputs outside the int32 range. The current small inputs would not expose narrowing even if output comparison were added.

1 resolved since last review

Review effort: Balanced

Comment thread backends/arm/_passes/insert_int32_casts_after_int64_placeholders.py Outdated
Copilot AI balanced review requested due to automatic review settings October 23, 2026 18:53
@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 Oct 23, 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.

Comment thread backends/arm/_passes/insert_int32_casts_after_int64_placeholders.py Outdated
Comment thread backends/arm/operators/op_tosa_reduce_sum.py Outdated
Comment thread backends/arm/tosa/dialect/ops/comparison.py
Comment thread backends/arm/test/misc/test_int64.py Outdated
@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Oct 23, 2026
Copilot AI balanced review requested due to automatic review settings October 23, 2026 19:55
@abm-77
abm-77 force-pushed the arm-int64-spec-aware branch from 82778e4 to 07318e7 Compare October 23, 2026 19:57

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.

🟡 Changes recommended

Newly accepted mixed-width WHERE operands can still narrow int64 values to int32 and lose precision.

4 open issues
1 resolved since last review

Review effort: Balanced

Comment thread backends/arm/operator_support/where_support.py Outdated
@abm-77
abm-77 requested a review from YufengShi-dudu October 27, 2026 18:35

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.

🟡 Changes recommended

The new int64 paths need direct regression coverage, and the partitioning impact needs reconciliation with the stated behavior-preserving scope.

4 open issues

Review effort: Balanced

Comment thread backends/arm/tosa/cast_support.py Outdated
Comment thread backends/arm/tosa/dialect/ops/_common.py
@abm-77
abm-77 force-pushed the arm-int64-spec-aware branch from cde255c to e5e75fc Compare October 27, 2026 21:01
Copilot AI balanced review requested due to automatic review settings October 27, 2026 21:01

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 unresolved blocking issues remain in these preparatory changes, which leave existing int64 narrowing behavior unchanged.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

Comment thread backends/arm/operators/op_flip.py
Comment thread backends/arm/operators/op_tosa_neg.py
Comment thread backends/arm/operators/op_where.py Outdated
Comment thread backends/arm/operators/op_tosa_abs.py Outdated
Comment thread backends/arm/operators/simple_node_visitor.py
Comment thread backends/arm/tosa/specification.py Outdated
Comment thread backends/arm/tosa/specification.py Outdated


def keeps_int64(tosa_spec: "TosaSpecification | None" = None) -> bool:
"""Whether int64 is kept 64 bits wide; only INT has int64 lowerings."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

EXT-INT64 doesn't require PRO-INT. PRO-FP + EXT-INT64 is valid. For example, GATHER with FP32 input and INT64 indices is supported under this combination.
This might become clearer once EXT-INT64 is included in an officially released version of the TOSA specification.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that makes sense. keeps_int64 is out of this PR now, but the same question comes up in the second one, so I tried dropping the INT check there and ran single-op models under TOSA-1.1+FP+int64.

Data movement ops on int64 (squeeze, unsqueeze, permute, expand, select, stack, transpose, concat, flip, tile) start failing in InsertDataLayoutCastsPass. Under an FP-only spec it moves integer data by casting it to float, and _int_to_fp_map stops at int32, so int64 raises TypeError: Data type torch.int64 of operator aten.view_copy.default is not supported by TOSA-1.1+FP+int64. Integer arithmetic on int64 (add, sub, mul, maximum, minimum, abs, neg) also gets delegated, which the FP profile rejects for int32 today.

Handling PRO-FP + EXT-INT64 fully looks like it would need per-profile capability lists and per-node narrowing, so for now I'd lean toward scoping this series to PRO-INT + EXT-INT64. I'm not attached to the INT check itself, though. If you have a cleaner way to express this, or would rather structure it differently, I'm happy to rework it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make sense. Let's focus on PRO-INT + EXT-INT64 in the next PR.

Comment thread backends/arm/tosa/dialect/ops/_common.py Outdated
Copilot AI balanced review requested due to automatic review settings October 28, 2026 15:55

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 scoped EXT-INT64 mapping, validation, and visitor changes.

No open issues 🎉

Review effort: Balanced

@abm-77
abm-77 requested a review from YufengShi-dudu October 28, 2026 16:14
@YufengShi-dudu YufengShi-dudu changed the title Arm backend: Make int64 representable under EXT-INT64 (1/3) Arm backend: Prepare TOSA validation and lowering for int64 Oct 29, 2026
Copilot AI balanced review requested due to automatic review settings October 29, 2026 11:41

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 block the scoped EXT-INT64 validation and serialization changes.

No open issues 🎉

Review effort: Balanced

@YufengShi-dudu YufengShi-dudu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice work! I think it's good to go now. I've also updated the commit message a bit.
@zingo Could you take another look? Thanks!

@abm-77

abm-77 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews! I'll have the next PR up soon. Also, I don't have permission to merge, so I think someone would have to do so on my behalf.

@zingo
zingo merged commit 6a2784e into pytorch:main Oct 29, 2026
440 checks passed
@zingo

zingo commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Merged, the tests on "main" after merge can be monitored on this link https://hud.pytorch.org/hud/pytorch/executorch/main/1?per_page=50&name_filter=test-arm%7Ccortex-m%7Csize&useRegexFilter=true
(only showing Arm backends related tests :) )

I do not expect and problems so this is mostly for you info. :) It should be the exact same tests that as was runned on the PR but just once more on them merged version.

Thanks again for the great work.

@zingo

zingo commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

And also congratulation to the first PR in the project!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk 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) module: arm Issues related to arm backend partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: arm Changes to the ARM backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants