Skip to content

Metal backend: Add INT32 and BOOL dtype support#18874

Open
manuelcandales wants to merge 2 commits intomainfrom
gh/manuelcandales/169/head
Open

Metal backend: Add INT32 and BOOL dtype support#18874
manuelcandales wants to merge 2 commits intomainfrom
gh/manuelcandales/169/head

Conversation

@manuelcandales
Copy link
Copy Markdown
Contributor

AOTI-generated code creates int32 tensors for topk indexing and bool
tensors for attention masks. Add both to the SupportedDTypes enum and
validation function.

Authored with Claude.

[ghstack-poisoned]
Copilot AI review requested due to automatic review settings April 14, 2026 16:25
@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 Apr 14, 2026
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Apr 14, 2026

🔗 Helpful Links

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

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:

❌ 2 New Failures, 3 Unrelated Failures

As of commit e7a7acc with merge base 5707e2a (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Apple Metal runtime shims’ dtype allowlist so AOTI-generated models can use int32 tensors (e.g., topk indices) and bool tensors (e.g., attention masks) without failing dtype validation.

Changes:

  • Add INT32 and BOOL entries to the Metal backend SupportedDTypes enum.
  • Extend is_dtype_supported_in_et_metal() to accept INT32 and BOOL.
  • Simplify the validate_dtype() error log message.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
backends/apple/metal/runtime/shims/utils.h Adds INT32 and BOOL to the supported dtype enum.
backends/apple/metal/runtime/shims/utils.cpp Allows INT32/BOOL in dtype validation and updates the unsupported-dtype log message.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +42 to +43
"Unsupported dtype: %d",
dtype);
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The updated log message in validate_dtype regresses debuggability vs the previous version: it no longer indicates which dtype codes are supported. Please either restore the supported-dtypes list (updated to include INT32 and BOOL) or log it in a way that stays in sync with is_dtype_supported_in_et_metal (e.g., via a single source of truth).

Suggested change
"Unsupported dtype: %d",
dtype);
"Unsupported dtype: %d. Supported dtype codes: [%d, %d, %d, %d, %d, %d]",
dtype,
static_cast<int32_t>(SupportedDTypes::UINT8),
static_cast<int32_t>(SupportedDTypes::INT32),
static_cast<int32_t>(SupportedDTypes::INT64),
static_cast<int32_t>(SupportedDTypes::FLOAT32),
static_cast<int32_t>(SupportedDTypes::BOOL),
static_cast<int32_t>(SupportedDTypes::BFLOAT16));

Copilot uses AI. Check for mistakes.
[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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants