Skip to content

Wrap iOS18 quantization errors with ExecuTorch-specific hint#19249

Open
john-rocky wants to merge 2 commits intopytorch:mainfrom
john-rocky:coreml/quantize-ios18-error-hint
Open

Wrap iOS18 quantization errors with ExecuTorch-specific hint#19249
john-rocky wants to merge 2 commits intopytorch:mainfrom
john-rocky:coreml/quantize-ios18-error-hint

Conversation

@john-rocky
Copy link
Copy Markdown

Summary

When a model prepared with torchao's quantize_(...) (e.g. blockwise int4)
is lowered without an iOS18+ minimum_deployment_target, coremltools raises
a ValueError from inside _construct_constexpr_dequant_op:

ValueError: The more fine-grained quantization (such as blockwise) is only supported since iOS18.Please set minimum_deployment_target to iOS18 for using it.

This message is technically correct but does not tell the ExecuTorch user
how to set the deployment target — the answer is buried in
CoreMLBackend.generate_compile_specs(...) plus
CoreMLPartitioner(compile_specs=...), which is not obvious unless you've
already been through the docs.

The two dequantize_affine / dequantize_codebook handlers in
backends/apple/coreml/compiler/torch_ops.py are the only call sites where
the failing coremltools utilities are invoked from ExecuTorch code, so I
wrap them and re-raise the error with an additional hint that shows the
exact partitioner call. After this change the user sees:

ValueError: The more fine-grained quantization (such as blockwise) is only supported since iOS18.Please set minimum_deployment_target to iOS18 for using it.
ExecuTorch hint: pass `compile_specs=CoreMLBackend.generate_compile_specs(minimum_deployment_target=ct.target.iOS18)` (or higher) to `CoreMLPartitioner` when lowering models that use `quantize_(...)`.

Fixes #13122.

Test plan

Added test_dequantize_affine_below_ios18_raises_with_hint which lowers a
PerGroup-int4 quantized linear with minimum_deployment_target=ct.target.iOS17
and asserts the raised ValueError mentions both iOS18 and the
CoreMLPartitioner / minimum_deployment_target keywords.

The existing iOS18 quantization tests still pass (test_dequantize_affine_b4w_linear exercised locally to confirm the wrapper does not affect the success path).

$ python -m unittest -v executorch.backends.apple.coreml.test.test_torch_ops.TestTorchOps.test_dequantize_affine_below_ios18_raises_with_hint
Ran 1 test in 0.653s

OK
$ python -m unittest -v executorch.backends.apple.coreml.test.test_torch_ops.TestTorchOps.test_dequantize_affine_b4w_linear
Ran 1 test in 0.536s

OK

Authored with Claude.

When the user lowers a model that was prepared with torchao's
`quantize_(...)` (e.g. blockwise int4) but does not pass an
iOS18+ `minimum_deployment_target` to the CoreML partitioner,
coremltools raises a generic ValueError pointing at coremltools
internals.  The user has no obvious way to discover that the
target is set via `CoreMLBackend.generate_compile_specs` and
plumbed through `CoreMLPartitioner(compile_specs=...)`.

Catch the ValueError around the two coremltools utilities used
by our overridden `dequantize_affine` / `dequantize_codebook`
handlers and re-raise it with an ExecuTorch-flavored hint that
shows the exact partitioner call to make.

Fixes pytorch#13122.
@john-rocky john-rocky requested a review from shoumikhin as a code owner May 1, 2026 05:00
@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/19249

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

⚠️ 12 Awaiting Approval

As of commit 65bac67 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.

quantize_ in CoreML only works on iOS18 and the error message is confusing

1 participant