Skip to content

fix: raise CoreMLExportError on incompatible palettization configs#44

Draft
guru-desh wants to merge 6 commits into
apple:mainfrom
guru-desh:expand-coreml-export-error
Draft

fix: raise CoreMLExportError on incompatible palettization configs#44
guru-desh wants to merge 6 commits into
apple:mainfrom
guru-desh:expand-coreml-export-error

Conversation

@guru-desh

Copy link
Copy Markdown
Contributor

Stacked on #42 — this branch is rebased onto remove-coreml-export-tests, so this diff includes #42's commits plus 3 new ones on top. Once #42 merges, only the last 3 commits here will remain.

In our test suite, we had pytest.skip some incompatible palettization configs, but this doesn't prevent users from using these configs.

We refactor the test by removing pytest.skip and changing the tests to check that CoreMLExportError is raised. We also create validate_coreml_palettization_compatibility that contains the logic that decides when CoremlExportError is raised.

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.
…hecks

Vector palettization, LUT quantization, and per-channel scale are each
independently CoreML-exportable, but combining any two breaks CoreML/MIL's
constexpr_lut_to_dense op with a rank mismatch, a missing vector_axis, or an
indices/LUT divisibility error depending on the pair. Add a dedicated
validator (composing the existing LUT dtype check) so the kmeans export path
has one entry point to reject these combinations with a clear
CoreMLExportError, instead of relying on a test-side skip to hide them.
…port

Wire validate_coreml_palettization_compatibility into prepare_for_mil_export
so finalize(backend=CoreML) raises immediately for a combo it can't fuse
into a single compatible op chain, rather than emitting an invalid model or
crashing deep inside ct.convert.
Replace the pytest.skip-based _skip_unsupported_mil_configs with a predicate
(_has_unsupported_mil_combo) and assert finalize() raises CoreMLExportError,
mirroring the existing float-LUT-dtype rejection path. Rename
_assert_coreml_rejects_unsupported_lut to _assert_coreml_rejects since it's
now shared by both rejection cases.
@guru-desh guru-desh added the bug Something isn't working label Jul 18, 2026
@guru-desh
guru-desh requested review from dengqiaoyu and u-simha July 18, 2026 07: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