Skip to content

Reject CoreML delegation for unsupported input dtypes#19245

Open
john-rocky wants to merge 2 commits intopytorch:mainfrom
john-rocky:coreml/catch-partitioner-dtype-exception
Open

Reject CoreML delegation for unsupported input dtypes#19245
john-rocky wants to merge 2 commits intopytorch:mainfrom
john-rocky:coreml/catch-partitioner-dtype-exception

Conversation

@john-rocky
Copy link
Copy Markdown

Summary

CoreMLPartitioner queries coremltools.converters.mil.frontend.torch.is_torch_fx_node_supported
to decide whether a node can be delegated, but that function only inspects the op
name — it does not validate input dtypes. When a graph contains a node whose
inputs use a dtype outside TORCH_DTYPE_TO_MIL_DTYPE (e.g. torch.uint8 /
torch.int8), the partitioner happily tags it and the failure only surfaces
later from deep inside coremltools as a KeyError, aborting the whole export.

This change adds an explicit dtype check in should_override_support so such
nodes fall back to the portable backend, and wraps the support query in
try/except as a defensive measure for any other case where the call might
raise instead of returning False.

Fixes #11686.

Test plan

Added test_unsupported_dtype_does_not_crash_partitioner which lowers
torch.abs on a uint8 input via to_edge_transform_and_lower and asserts
the op is not delegated. Verified locally on macOS 15 / Python 3.10 /
coremltools 9.0:

$ python -m unittest -v executorch.backends.apple.coreml.test.test_coreml_partitioner.TestCoreMLPartitioner
Ran 9 tests in 104.215s

OK

Authored with Claude.

coremltools' torch->MIL converter only knows the dtypes in
TORCH_DTYPE_TO_MIL_DTYPE.  When a node had any other input dtype
(notably torch.uint8 or torch.int8) the partitioner still tagged it
for delegation; the failure surfaced later as a KeyError raised from
deep inside coremltools, masking the underlying cause and crashing
the export.

Reject such nodes up front in should_override_support so they fall
back to the portable backend.  Also wrap the coremltools support
query in a try/except as a defensive measure for any other case
where the call might raise instead of returning False.

Fixes pytorch#11686.
@john-rocky john-rocky requested a review from shoumikhin as a code owner May 1, 2026 04:44
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 1, 2026

🔗 Helpful Links

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

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

⚠️ 12 Awaiting Approval

As of commit d324e22 with merge base 94d2881 (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
Copy link
Copy Markdown

meta-cla Bot commented May 1, 2026

Hi @john-rocky!

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!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

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.

@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 May 1, 2026
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.

CoreML partitioner errors out with 8-bit integer types

2 participants