Skip to content

Fix the CoreAI op-order check of the joint sparsity + palettization e2e test - #171

Merged
dengqiaoyu merged 1 commit into
apple:mainfrom
u-simha:u/usimha/fix-joint-sparse-pal-ci-bug
Oct 28, 2026
Merged

dengqiaoyu merged 1 commit into
apple:mainfrom
u-simha:u/usimha/fix-joint-sparse-pal-ci-bug

Conversation

@u-simha

@u-simha u-simha commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What:

  • Fix the CoreAI op-order check in tests/export/test_joint_sparsity_palettization_e2e.py so it passes with any Core AI build, not only the one it was written against

Why:

  • The check read the lowered MLIR text for coreai.build_sparse_with_bitmask and coreai.sparse_with_bitmask_to_dense. Builds of Core AI that lower the sparse ops under other names make it fail with assert 0 == 6, even though the conversion and the output comparison pass. That fails the six CoreAI test_mnist cases and both test_mnist_vector_palettization cases.

How:

  • For CoreAI, check the order on the exported torch program instead: lut_to_dense -> sparse_to_dense -> constexpr_blockwise_shift_scale (the last one only when a per-channel scale or a quantized LUT is used). This is the layer coreai-opt produces, and the test already uses it to count the ops, so the check no longer depends on how a Core AI version lowers or prints them.
  • The program is traced on a copy of the finalized model before it is converted, since converting may modify the model.
  • The CoreML check on the MIL program is unchanged.
  • The order check now lives in _export(..., check_order=True), so the tests no longer call a separate _assert_op_order.

Testing:

  • The non-slow tests of the file pass locally with the public coreai-core and coreai-torch releases.
  • Inserting an extra op between lut_to_dense and sparse_to_dense makes the same eight CoreAI cases fail, so the check still guards the order.
  • This is a test-only change. I could not run it against the other Core AI build that showed the failure, so a green CI run on this PR is the confirmation.

…d program

The CoreAI order check of the joint sparsity + palettization e2e test parsed the lowered MLIR
text for coreai.build_sparse_with_bitmask and coreai.sparse_with_bitmask_to_dense. That passes
with the public coreai-core / coreai-torch, but the internal CI installs internal Core AI
builds that do not lower the sparse ops to those names, so the six CoreAI test_mnist cases and
both test_mnist_vector_palettization cases failed with "assert 0 == 6" even though the
conversion and the output comparison passed.

Check the order on the exported torch program instead (lut_to_dense -> sparse_to_dense ->
constexpr_blockwise_shift_scale), which is what coreai-opt produces and which the test already
uses to count the ops, so it no longer depends on how a Core AI version lowers or prints them.
The CoreML check on the MIL program is unchanged.
@dengqiaoyu
dengqiaoyu self-requested a review October 28, 2026 20:19
@dengqiaoyu dengqiaoyu self-assigned this Oct 28, 2026

@dengqiaoyu dengqiaoyu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix!

@dengqiaoyu
dengqiaoyu merged commit 2b6d22b into apple:main Oct 28, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants