Repository navigation
fix(models): read bailing_hybrid embed_q as [H, kv_lora_rank, qk_nope_head_dim] - #3736
Conversation
9ffeddf to
23036c4
Compare
…bed-q-shape # Conflicts: # docs/supported-models.md
Hardening reviewReviewed against #3735. The fix is correct and complete; no code changes were needed beyond merging
Pushed a merge of current Validation on the merged tree: Follow-up note, not done here: |
Summary
Closes #3735.
bailing_hybrid::validate_weightschecked the absorbed MLAembed_qplane as[H, qk_nope_head_dim, kv_lora_rank]. The plane is[H, kv_lora_rank, qk_nope_head_dim]:split_kv_b_projbuilds it that way, mlx-lm'sMultiLinear(qk_nope_head_dim, kv_lora_rank, H)stores it that way, and the MLA forward consumes it that way. Any config whose two widths differ was refused at load, which includes Ling-2.6-flash (kv_lora_rank512,qk_nope_head_dim128), the checkpoint this family was written for. The check now passes(kv_lora_rank, qk_nope_head_dim)as(out_features, in_features).What changed
src/models/bailing_hybrid.rs,validate_weights: theembed_qcall tovalidate_multi_linearswaps itsout_features/in_featuresarguments, with a comment naming each plane's layout. Theunembed_outcheck ([H, v_head_dim, kv_lora_rank]) was already right and is unchanged.src/models/bailing_hybrid_tests.rs:validate_weights_reads_embed_q_as_kv_lora_by_nopewalks(kv_lora_rank, qk_nope_head_dim)= (2, 2), (4, 2), (2, 4), (8, 2) and (8, 1), the last two being Ling-2.6-flash's 4:1 ratio and a more extreme one. For each it checks the pre-split layout the mlx-community conversion ships, that the transposed plane is still refused whenever the widths differ, and a rawkv_b_projthatsanitize_weightssplits itself (asserting both split shapes).synthetic_forward_runs_with_kv_lora_rank_unequal_to_nopeloads the tiny model withkv_lora_rank8 andqk_nope_head_dim2 throughfrom_weightsand runs a 3-token prefill (materializing MLA path) and a decode step (absorbed path), checking shapes and finiteness.docs/supported-models.md(Ling-2.6-flash entry) and thesanitize_weightsdoc comment: the publishedmlx-community/Ling-2.6-flash-mlx-4bit(revisionbd458afd) shipsembed_q/unembed_out4-bit affine-quantized (embed_q.weightisU32 [32, 512, 16]withscales/biases[32, 512, 2]), not unquantized as both said; the entry now records the real-checkpoint run below instead of "unit-tested only". The existing sentences about current mlx-lm'squant_predicateare kept.Other callers:
validate_multi_linearis private tobailing_hybrid.rsand has exactly these two call sites. No other module validates a bailing_hybridembed_q.Verification
NVIDIA GB10 (sm_121), driver 580.178.04, CUDA 13.0.88, Linux 7.0.0-1019-nvidia aarch64, rustc 1.97.1,
--features cuda,--profile test-fast. Base9402cf893. Commit treecef9852d; the gate and checks below ran on tree2afacb93, which differs from it only inCHANGELOG.md(an entry since removed).Tests
cargo test --locked --profile test-fast --features cuda --lib -- --test-threads=1 bailing_hybrid::main+ the new testsvalidate_weights_reads_embed_q_as_kv_lora_by_nopekv_lora_rank 4, qk_nope_head_dim 2: unexpected model.layers.1.attention.embed_q.weight shape [2, 4, 2]: expected [2, 2, 4] (per-head absorbed MLA plane)synthetic_forward_runs_with_kv_lora_rank_unequal_to_nopeunexpected model.layers.1.attention.embed_q.weight shape [2, 8, 2]: expected [2, 2, 8] (per-head absorbed MLA plane)bailing_hybrid::totalThe fix column ran on tree
e6e1a719, which differs from2afacb93only indocs/supported-models.md, thesanitize_weightsdoc comment andCHANGELOG.md; the full gate below ran on2afacb93.Real checkpoint
mlx-community/Ling-2.6-flash-mlx-4bit, revisionbd458afdc97da0f60046f76f5ec96f204b4fb27f(58.6 GB;kv_lora_rank512,qk_nope_head_dim128).mlxcel generate -m <dir> -p "The capital of France is" -n 32 --temp 0 --no-chat-template, binaries built with--profile test-fast --features cudafrommainand from the fix (different sha256):main: exits 1 after 1.2 s, before any weight is materialized:Error: unexpected model.layers.7.attention.embed_q.weight shape [32, 512, 16]: expected [32, 128, 512] (per-head absorbed MLA plane)\nA.Paris\nB.London\nC.Berlin\nD.Madrid\nA\nThe problem is asking for the identification of the capital citystream_generate(..., max_tokens=32, sampler=make_sampler(temp=0.0)), prompt ids[678, 7706, 300, 11406, 341]: the same 32-token text, byte for byte.Checks
cargo fmt --all -- --checkcargo clippy --locked --workspace --all-targets --features cuda -- -D warningspython3 scripts/ci/check_used_by.py(used-by: OK, 78 top-level pub fn in 2 shared files, 57 annotated, 715 caller-file references resolved, 3498 Rust files scanned),bash scripts/ci/check_used_by_test.sh(all cases passed)make verify-test-cudawith a private 0700TMPDIR, tree2afacb93before and after: 18,893 passed, 2 failed, 578 ignored over 207test resultlines. Both failures were pre-existing on the base9402cf893and are unrelated to this change; currentmainfixes both (feat(speculative): add DeepSeek-V4.1 bundled DSpark drafter (#3262) #3686, test: restore MLX guard scan and no-GPU catalog test gates #3765):tests/mlx_test_guard_coverage.rsmlx_evaluating_lib_tests_take_mlx_test_guard:src/vision/encoders/nemotron_h_nano_omni_tests.rs:276 pos_embed_resample_runs_in_f32evaluates MLX without the guard. The two new tests here are not listed.tests/step3p7_parity.rstext_decode_delegates_sequence_local_native_batching:assertion failed: !wrapper.supports_padded_prefill().On unmodified
main(9402cf893),cargo test --locked --profile test-fast --features cuda --test mlx_test_guard_coverage --test step3p7_parity -- --test-threads=1fails both the same way (5 passed / 1 failed and 7 passed / 1 failed, same messages).git merge-treemerges the commit onto currentorigin/main(5bf7b8628) without conflict. On the merged tree, the Python tooling tests (python3 -m unittest discover -s tests -p 'test_*.py'), thescripts/cichecks CI runs andcargo fmt --all -- --checkpass.Limits
mlxcel::quantwarns once per MoE layer thatmodel.layers.N.mlp.gate.gate_projis declared 4-bit but packed as 8-bit, and uses the shape-derived 8 bits (config.jsondeclares those routers 8-bit per layer). The output still matches mlx-lm. The warning is independent of this change and was not investigated.