Skip to content

refactor: expand CoreMLExportError to error on non-compatible configs for CoreML and remove more CoreML export tests#42

Open
guru-desh wants to merge 3 commits into
apple:mainfrom
guru-desh:remove-coreml-export-tests
Open

refactor: expand CoreMLExportError to error on non-compatible configs for CoreML and remove more CoreML export tests#42
guru-desh wants to merge 3 commits into
apple:mainfrom
guru-desh:remove-coreml-export-tests

Conversation

@guru-desh

@guru-desh guru-desh commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

There's some CoreML export error tests that are xfailed with SNRThresholdError. During test triaging, we noticed that they still failed.

Upon deeper investigation, we noticed that the tests were checking per channel activations, which CoreML doesn't support. The main changes in the PR are the following:

  1. A new function was created called validate_coreml_compatibility which uses CoreMLExportError to raise errors on both incompatible configs and incompatible dtypes (before it was just dtypes). This function centralizes the export raising logic for CoreML
  2. The tests were removed, but some were kept to verify that CoreMLExportError was being raised

Testing

I verified that CoreML doesn't support per-channel activations, and CI is passing too

@guru-desh
guru-desh force-pushed the remove-coreml-export-tests branch 2 times, most recently from 24813ce to dfc5a5f Compare July 17, 2026 19:26
ExportBackend.CoreML,
unsupported_configs={"backend": ExportBackend.CoreML, "act_dtype": torch.int8},
)
# CoreML rejects per-channel activation quantization outright.

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.

Currently, in the overall export test where we test configs, the quick fix is to exclude the configs that have per-channel activation quantization.

The reason we do this is because the configs that we use for testing CoreML export and CoreAI export are the same even though we know CoreML and CoreAI don't support the same things. Ideally, we'll have another PR that goes through these export configs and cleans it up

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.

I didn't want to do it in this PR itself as it would make the PR more complicated than it should be and go beyond the "remove bad CoreML export tests + refactor CoreMLExportError" scope

),
marks=pytest.mark.skip(reason="Crashes with segfault"),
),
)

@guru-desh guru-desh Jul 17, 2026

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.

This is the test we removed because we know that CoreML doesn't support per-channel activations.

When I looked at the CoreML model, it did actually have per-channel activations, but there is a bug in coremltools where it always convert dequantize(scale_A) → reshape → quantize(scale_B) to reshape. This works for per-tensor but not always for per-channel. To avoid this error, a user needs to specify pass_pipeline=ct.PassPipeline.EMPTY, but since that's not always guaranteed and there's no per-channel activation tests in coremltools, the easy solution is to reject the config.

@guru-desh guru-desh changed the title Remove coreml export tests refactor: expand CoreMLExportError to error on non-compatible configs for CoreML and remove more CoreML export tests Jul 17, 2026
Weight/activation/LUT dtype checks and the activation-granularity check
were duplicated across the eager, graph, and palettization export paths.
Consolidate them into validate_coreml_compatibility() so CoreML's actual
export constraints live in one place, including the per-channel/per-block
activation restriction: an upstream coremltools MIL optimizer pass can
silently corrupt per-channel-quantized activations across reshape
boundaries, so CoreML export now rejects that configuration outright
instead of letting it through to a numerics-level failure.
…eML export

CoreML export now rejects these configs outright instead of letting them
through to a numerics-level SNR failure. Replace the xfail-based coverage
with direct CoreMLExportError assertions, and collapse the now-redundant
per-axis/per-dtype combinatorial sweeps since the rejection doesn't depend
on any of those variables.
…clarity

assert_coreml_finalize_rejects_unsupported_dtype and
COREML_DTYPE_REJECTION_MATCH are now used for granularity rejections too,
not just dtype ones, so their names no longer matched what they check.
@guru-desh guru-desh added the bug Something isn't working label Jul 17, 2026
@guru-desh
guru-desh force-pushed the remove-coreml-export-tests branch from dfc5a5f to 1663dde Compare July 17, 2026 20:12
@guru-desh
guru-desh requested a review from pkmandke July 17, 2026 20:17
@guru-desh
guru-desh marked this pull request as ready for review July 17, 2026 20:18
@guru-desh
guru-desh requested review from crowbat and dengqiaoyu July 17, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants