Skip to content

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

Open
Jaeyeong-CHOI wants to merge 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:fix/granite4-moe-validate
Open

Jaeyeong-CHOI wants to merge 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:fix/granite4-moe-validate

Conversation

@Jaeyeong-CHOI

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); they are the two stale tests test: fix two stale tests that keep make verify-test red #3720 fixes.
  • 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 9402cf8.

Limits

  • Only the 4-bit h-tiny export was run, and only on CUDA (GB10); granite-4.0-h-small, 8-bit exports and Metal were not compared with mlx-lm. The existing Metal M5 vs ROCm h-tiny traces (test(rocm): complete the #1809 matrix rows with Metal M5 traces #2083) compare two mlxcel backends, not mlxcel with mlx-lm.
  • This PR and the GraniteMoE port PR both edit the Granite 4 line of docs/supported-models.md; whichever lands second needs a trivial rebase. No CHANGELOG entry: that is written at release time.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant