Repository navigation
fix(models): read bailing_hybrid embed_q as [H, kv_lora_rank, qk_nope_head_dim] - #3736
Open
Jaeyeong-CHOI wants to merge 1 commit into
Open
Jaeyeong-CHOI wants to merge 1 commit into
Jaeyeong-CHOI wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.CHANGELOG.md:## [Unreleased]/### Fixedentry.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 tree2afacb93.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; the final commit differs from it only indocs/supported-models.md, thesanitize_weightsdoc comment andCHANGELOG.md, and the full gate below ran on the final tree.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 are onmainalready and unrelated to this change; test: fix two stale tests that keep make verify-test red #3720 fixes both: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(9402cf893) without conflict.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.