Repository navigation
fix(models): load published ERNIE-4.5 text MoE expert layouts - #3333
Conversation
Main changed `drain_numbered_expert_planes` to return `Result` (lablup#3335), so the ERNIE text loader now propagates its error instead of discarding it, which would also fail `clippy -D warnings` on `unused_must_use`. A plane whose dtype differs from expert 0 now fails with the helper's message naming the expert key instead of a later `Weight not found` for the stacked projection. Add a regression test covering the three malformed numbered-expert layouts the loader refuses: a dtype mismatch (reported by the shared helper), a missing expert, and an extra expert beyond `moe_num_experts`.
Hardening summarySummaryFixed and pushed. The loader changes are correct: the fused shared GLU loads once at its stored width, numbered routed experts stack in expert order (including affine sidecars), and the MTP tensors are dropped. Main had changed This PR is stacked on #3322 (it carries Reviewed (PR + issues)
Findings
Fixes
Security reviewThe numbered-expert path checks every plane's shape against expert 0, refuses gaps and surplus experts, and now also surfaces the shared helper's shape/dtype refusal before Performance reviewStacking materializes one projection at a time ( ValidationHost: spark-101 (NVIDIA GB10, CUDA), test-fast profile,
Merge-order notes
|
Summary
Closes #3323. Depends on #3322.
The ERNIE-4.5 text loader now accepts the expert layouts in the original Baidu checkpoint and both mlx-community exports. A GLU stored directly under
mlp.shared_expertsloads once at its stored width. A checkpoint with numbered shared GLUs still loads each configured module separately.For numbered routed experts, the loader stacks each projection in numeric expert order with
drain_numbered_expert_planes, including affine scales and biases when present. It checks that the expert planes cover the configured bank with matching shapes and materializes each projection before starting the next one. Already-stackedswitch_mlpprojections take their existing path. The loader drops the unusedmtp_block,mtp_linear_proj,mtp_hidden_norm, andmtp_emb_normcomponents.The directory loader and config-backed in-memory loader share this preparation. The public borrowed-weight constructor retains its signature. I checked the separate VL loader, which already reads a fused shared GLU and builds its modality-specific routed banks separately.
Original checkpoint verification
On Spark2 (NVIDIA GB10, CUDA 13.0), I ran the #3322 binary at
d2cde7ea9and the fix against the same download directories. Each run usedmlxcel generate --no-chat-template --temp 0 -n 12and one of three prompts:The capital of France is,Two plus two equals, or海洋是. The patched runs used the original shards, index, config, and tokenizer files in each directory.87db95487941cb39592ee0abca3b9155a6d19c5cswitch_mlp.gate_proj.weightin layer 16de3db650133247146f2feec80a94ae8d22de8d7shared_experts.0.gate_proj.weightin layer 16a55392c9930d43543bfa0a8ac6b67985bf4bd1dI compared the UTF-8 bytes printed between the generation marker and the timing footer, preserving whitespace. All nine fixed ERNIE runs had empty stderr. Both community downloads used their own SentencePiece file. The #3322 adapted copies had also included Baidu's tokenizer JSON.
The separate MoE control,
mlx-community/LFM2-8B-A1B-4bitat3266a85e9dabe5a6a711f889b8389cfa0c6b08d2, produced the same 68 output bytes on the France prompt with both binaries. Both emitted 22 quantization metadata warnings.Teacher-forced logits
I ran the CUDA
logit_traceexample on the original Baidu checkpoint using the samedocs/architecture.mdcorpus and256 4 8 512arguments as #3322. All 1,024 TSV data rows matched the saved #3322 adapted-checkpoint trace byte-for-byte, including target IDs, negative log-likelihoods, top-eight IDs, and their printed logits. Against the saved mlx-lm reference, the result reproduced 10/1,024 top-1 mismatches, 0/486 mismatches at a reference gap of at least 2, and perplexity 11.7712 (mlx-lm 11.7836).Regression tests
Four new CUDA tests passed on the fix. Restoring every production change to #3322 while retaining the new tests made all four fail.
Test plan
Spark2 tested tree
2297640dcc1b8d6e8d53a7897903b844865da39e, the tree ofe671e4fd98fc6b1b5e19f7cb578dd7d175a33283.cargo fmt --all -- --checkcargo clippy --locked --workspace --all-targets --profile test-fast --features cuda -- -D warningslogit_traceexample in the test-fast profile.erniepassed 79, with 5 ignored. The four new tests also passed in isolation and failed against the base implementation.make verify-test-cudacompleted 192 harnesses with 16,694 passed, 2 failed, 503 ignored using a private 0700 TMPDIR. The failed tests weremodels::deepseek_v32::rope_tests::prefill_and_decode_cache_yarn_rotated_keys_past_the_original_contextandtests::family_order_is_exhaustive. The archived fix(models): apply ERNIE-4.5 MoE text correction bias in float32 routing #3322 gate had 16,690 passed, the same two failures, and 503 ignored.Verification limits
Metal, ROCm, other ERNIE sizes, and real VL checkpoints were not verified. Numbered affine routed experts were tested with synthetic weights. The public 4-bit checkpoint supplies pre-stacked routed experts. The new teacher-forced trace covers Baidu only. The adapted generation and mlx-lm reference comparisons used saved #3322 evidence. Training and throughput were not measured.