Skip to content

test(granitemoehybrid): validate the MoE mode on granite-4.0-h-tiny against mlx-lm - #3744

Merged
inureyes merged 3 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/granite4-moe-validate
Dec 4, 2026
Merged

inureyes merged 3 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/granite4-moe-validate

Conversation

@Jaeyeong-CHOI

@Jaeyeong-CHOI Jaeyeong-CHOI commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #3742.

Validates the Granite 4 hybrid MoE mode (granitemoehybrid with block_sparse_moe + shared_mlp) against mlx-lm on the public mlx-community/granite-4.0-h-tiny-4bit, pins it with a real-checkpoint test, and replaces the stale sentence in docs/supported-models.md that said the mode "awaits a public MLX checkpoint to validate". No defect was found, so there is no runtime code change.

What changed

  • tests/granitemoehybrid_moe_parity.rs (new): loads granite-4.0-h-tiny-4bit (revision 02c8783d: 40 layers, 4 of them attention, 64 experts, top-6, shared_intermediate_size 1024), asserts it is the MoE + shared-MLP variant, then teacher-forces mlx-lm's 64-token greedy continuation of a 26-token and a 494-token chat prompt (the long one carries the Mamba2 state across a whole prefill before decode). At every step the mlx-lm token must sit at most 1.0 below mlxcel's maximum logit, and it must be the argmax at 90% of the steps or more. Skipped when the checkpoint is absent, a failure under MLXCEL_REQUIRE_MODELS=1; MLXCEL_TEST_GRANITE4_MOE_DIR names the directory explicitly.
  • docs/supported-models.md: the Granite 4 entry names the validation checkpoint and the test instead of saying the mode awaits one, and states the result with its scope: argmax at every step with the default fused MoE kernel on CUDA, 63/64 on the long prompt with MLXCEL_FUSED_MOE=0, Metal not measured against mlx-lm. The granitemoehybrid.rs module doc names the MoE checkpoint next to the dense one.

Why teacher forcing rather than a free-running greedy comparison

A free run against mlx-lm parts at near-ties, and one flip there changes every later token, which measures rounding rather than the model. On main:

prompt first differing step mlx-lm top two at that step (bf16) same, float32
26 tokens 43 " more" 29.875, " scattered" 29.875 29.936 / 29.849
494 tokens (MLXCEL_FUSED_MOE=0) 5 " summarized" 30.5, " from" 30.0 29.869 / 29.741

With the fused single-token MoE kernel (the default) the 494-token free run matches all 64 tokens; the 26-token one parts at the same step 43.

Verification (NVIDIA GB10, sm_121, CUDA 13; mlx-lm 0.32.2, mlx 0.32.5; Rust 1.97.1)

Reference ids: mlx-lm greedy decode on the same checkpoint from the same prompt ids (a prefill, then single-token argmax steps, no EOS stop), via mlx_lm.load and the model's own prompt cache.

New test, on this branch (MLX_ENABLE_TF32=0 MLXCEL_REQUIRE_MODELS=1 MLXCEL_TEST_GRANITE4_MOE_DIR=... cargo test --profile test-fast --features cuda --test granitemoehybrid_moe_parity -- --test-threads=1 --nocapture):

prompt fused MoE kernel on (default) MLXCEL_FUSED_MOE=0
26 tokens argmax 64/64, largest deficit 0 64/64, 0
494 tokens 64/64, 0 63/64, 0.125 at step 5

Without the checkpoint and without MLXCEL_REQUIRE_MODELS both tests skip and pass.

The test is not vacuous. With the shared_mlp term dropped from the MoE feed-forward (FeedForward::Moe returning the routed experts' output alone; a local edit, not part of this PR) and the test rebuilt, both cases fail: on the 494-token prompt mlx-lm's token is mlxcel's argmax at 21 of 64 steps and the largest deficit is 16.5 (step 0); on the 26-token prompt it is 24 of 64 and 14.35 (step 45).

Teacher-forced logit traces over docs/architecture.md (scripts/mlx_lm_logit_trace.py vs the logit_trace example, compared with scripts/compare_logit_traces.py), on main:

arm positions top-1 disagreements on decided positions (gap ≥ 2) largest gap at a disagreement perplexity mlx-lm / mlxcel
4 × 256-token chunks 1024 38 (3.7%) 0 / 377 0.375 27.513 / 27.613 (+0.37%)
512-token context, then 256 single-token steps 768 22 (2.9%) 0 / 335 0.250 15.276 / 15.325 (+0.32%)
same, MLXCEL_FUSED_MOE=0 768 24 (3.1%) 0 / 335 0.250 15.276 / 15.281 (+0.03%)

Every disagreement is at a position where mlx-lm's own top two are within 0.5.

Gates on this branch. They ran on the tree before the last revision of this PR, which changed only the Granite 4 sentence of docs/supported-models.md (the scope of the result, above); no code or test differs from the gated tree.

  • cargo fmt --all -- --check: clean. cargo clippy --locked --workspace --all-targets --features cuda -- -D warnings: clean.
  • The make verify-test-cuda suite (cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1), run one test target at a time with the same profile, features and flags (the mlxcel and mlxcel-core lib targets split into groups by top-level module, --exact), totals summed from libtest's per-target summaries: 200 targets, 18,888 passed, 2 failed, 568 ignored (19,458, the number of listed tests); doctests 3 passed, 10 ignored. The new test file runs (and skips, without the checkpoint) inside that suite.
  • The two failures are tests/mlx_test_guard_coverage.rs::mlx_evaluating_lib_tests_take_mlx_test_guard (it flags src/vision/encoders/nemotron_h_nano_omni_tests.rs:276) and tests/step3p7_parity.rs::text_decode_delegates_sequence_local_native_batching (assertion failed: !wrapper.supports_padded_prefill()). Both fail identically on unmodified main (9402cf8), the base of this branch; current main fixes both (feat(speculative): add DeepSeek-V4.1 bundled DSpark drafter (#3262) #3686, test: restore MLX guard scan and no-GPU catalog test gates #3765).
  • python3 scripts/ci/check_used_by.py and bash scripts/ci/check_used_by_test.sh: pass. The other scripts/ci/check_*.py and scripts/ci/*_test.sh pass except check_helm_chart.py and helm_chart_package_test.sh, which need a helm binary the test machine does not have.
  • git merge-tree --write-tree origin/main <branch>: clean against current main (5bf7b8628). On the merged tree, the Python tooling tests (python3 -m unittest discover -s tests -p 'test_*.py'), the scripts/ci checks CI runs and cargo fmt --all -- --check pass.

Limits

…gainst mlx-lm

Teacher-force mlx-lm's 64-token greedy continuations of a 26-token and a
494-token prompt on mlx-community/granite-4.0-h-tiny-4bit and require the
reference token at or near mlxcel's maximum logit at every step. Replace the
docs sentence that said the MoE mode awaited a public checkpoint.
@inureyes inureyes added status:review Under review type:test Test related changes priority:medium Medium priority area:models Model architectures, weights, loading, metadata labels Dec 4, 2026
The stored mlx-lm greedy continuations in tests/granitemoehybrid_moe_parity.rs had a prose description but no runnable recipe, so a later checkpoint or mlx-lm bump could not regenerate them the same way. Add the exact mlx-lm prefill plus single-token argmax loop, pinned to checkpoint revision 02c8783d, to the module doc.

Re-running the gate on current main (GB10, CUDA) shows the "argmax at every step with the default fused MoE kernel" claim held only with MLX_ENABLE_TF32=0. With TF32 on (the default) the long prompt is 63/64 with a 0.25 deficit at the step-5 near-tie, the same as MLXCEL_FUSED_MOE=0. Correct the tolerance comment and docs/supported-models.md to state that; the 1.0 tolerance is unchanged and both cases pass.

Refs lablup#3742, lablup#3744
@inureyes

inureyes commented Dec 4, 2026

Copy link
Copy Markdown
Member

Hardening review against #3742.

  • Coverage: on main the only real-weights tests on granite-4.0-h-tiny-4bit were finiteness checks (tests/mamba2_hybrid_*finite.rs), so this is the first gate on the MoE + shared_mlp path against an external reference. The reference ids are stored mlx-lm outputs, not self-consistency, and the PR's shared_mlp-dropped run shows the gate catches a real defect.
  • test(models): add a granitemoehybrid MoE parity gate against mlx-lm on granite-4.0-h-tiny-4bit #3742 is a test/doc issue (parity gate plus doc sentence), so a test-only PR closes it.
  • Merged current main (includes perf(cuda): run one-row MoE gathers on gather_qmv, not qmm_naive #3732, which changes one-row MoE gathers on CUDA) and re-ran on GB10 under MLXCEL_REQUIRE_MODELS=1: default settings give 64/64 on the short prompt and 63/64 on the long one (deficit 0.25 at step 5); MLXCEL_FUSED_MOE=0 gives the same; MLX_ENABLE_TF32=0 gives 64/64 on both. All pass the 1.0 tolerance.
  • Fix (e1b25b1): the docs and tolerance comment said "argmax at every step with the default fused MoE kernel", which only held with TF32 off; both now state the TF32 dependence. The module doc also gains the exact mlx-lm script that produced the *_REF_OUT tables, so the fixtures can be regenerated.
  • Validation: cargo fmt --check, cargo clippy --features cuda --test granitemoehybrid_moe_parity -- -D warnings, scripts/ci/check_env_var_docs.py clean.

@inureyes
inureyes merged commit aa4de29 into lablup:main Dec 4, 2026
36 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:test Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(models): add a granitemoehybrid MoE parity gate against mlx-lm on granite-4.0-h-tiny-4bit

2 participants