Skip to content

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
lablup:mainfrom
Jaeyeong-CHOI:fix/bailing-hybrid-embed-q-shape
Open

Jaeyeong-CHOI wants to merge 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:fix/bailing-hybrid-embed-q-shape

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Summary

Closes #3735.

bailing_hybrid::validate_weights checked the absorbed MLA embed_q plane as [H, qk_nope_head_dim, kv_lora_rank]. The plane is [H, kv_lora_rank, qk_nope_head_dim]: split_kv_b_proj builds it that way, mlx-lm's MultiLinear(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_rank 512, qk_nope_head_dim 128), 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: the embed_q call to validate_multi_linear swaps its out_features / in_features arguments, with a comment naming each plane's layout. The unembed_out check ([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_nope walks (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 raw kv_b_proj that sanitize_weights splits itself (asserting both split shapes).
    • synthetic_forward_runs_with_kv_lora_rank_unequal_to_nope loads the tiny model with kv_lora_rank 8 and qk_nope_head_dim 2 through from_weights and 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 the sanitize_weights doc comment: the published mlx-community/Ling-2.6-flash-mlx-4bit (revision bd458afd) ships embed_q / unembed_out 4-bit affine-quantized (embed_q.weight is U32 [32, 512, 16] with scales / 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's quant_predicate are kept.
  • CHANGELOG.md: ## [Unreleased] / ### Fixed entry.

Other callers: validate_multi_linear is private to bailing_hybrid.rs and has exactly these two call sites. No other module validates a bailing_hybrid embed_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. Base 9402cf893. Commit tree 2afacb93.

Tests

cargo test --locked --profile test-fast --features cuda --lib -- --test-threads=1 bailing_hybrid::

main + the new tests fix
validate_weights_reads_embed_q_as_kv_lora_by_nope FAIL: kv_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) pass
synthetic_forward_runs_with_kv_lora_rank_unequal_to_nope FAIL: unexpected model.layers.1.attention.embed_q.weight shape [2, 8, 2]: expected [2, 2, 8] (per-head absorbed MLA plane) pass
bailing_hybrid:: total 24 passed, 2 failed 26 passed, 0 failed

The fix column ran on tree e6e1a719; the final commit differs from it only in docs/supported-models.md, the sanitize_weights doc comment and CHANGELOG.md, and the full gate below ran on the final tree.

Real checkpoint

mlx-community/Ling-2.6-flash-mlx-4bit, revision bd458afdc97da0f60046f76f5ec96f204b4fb27f (58.6 GB; kv_lora_rank 512, qk_nope_head_dim 128). mlxcel generate -m <dir> -p "The capital of France is" -n 32 --temp 0 --no-chat-template, binaries built with --profile test-fast --features cuda from main and 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)
  • fix: loads (1,178 tensors, 58.6 GB materialized, 79 s) and generates 32 tokens at 13.2 tok/s:
    \nA.Paris\nB.London\nC.Berlin\nD.Madrid\nA\nThe problem is asking for the identification of the capital city
  • mlx-lm 0.32.2 (mlx 0.32.5, CUDA) on the same directory, stream_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 -- --check
  • cargo clippy --locked --workspace --all-targets --features cuda -- -D warnings
  • python3 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-cuda with a private 0700 TMPDIR, tree 2afacb93 before and after: 18,893 passed, 2 failed, 578 ignored over 207 test result lines. Both failures are on main already and unrelated to this change; test: fix two stale tests that keep make verify-test red #3720 fixes both:
    • tests/mlx_test_guard_coverage.rs mlx_evaluating_lib_tests_take_mlx_test_guard: src/vision/encoders/nemotron_h_nano_omni_tests.rs:276 pos_embed_resample_runs_in_f32 evaluates MLX without the guard. The two new tests here are not listed.
    • tests/step3p7_parity.rs text_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=1 fails both the same way (5 passed / 1 failed and 7 passed / 1 failed, same messages).

git merge-tree merges the commit onto current origin/main (9402cf893) without conflict.

Limits

  • One real prompt, 5 tokens in and 32 out, compared with mlx-lm as text. Longer prompts (the chunked GLA prefill path), batched decode and the server were not run on the real checkpoint.
  • While loading the real checkpoint, mlxcel::quant warns once per MoE layer that model.layers.N.mlp.gate.gate_proj is declared 4-bit but packed as 8-bit, and uses the shape-derived 8 bits (config.json declares those routers 8-bit per layer). The output still matches mlx-lm. The warning is independent of this change and was not investigated.
  • Not run on Metal.

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

Development

Successfully merging this pull request may close these issues.

fix(models): bailing_hybrid validates embed_q with its last two axes swapped, so Ling-2.6-flash cannot load

1 participant