Repository navigation
fix(xla): expand Youtu-VL MLA latents in the transposed weight layout - #3393
Conversation
The single-sequence OpenXLA session uploads projection weights transposed to `[in, out]` (#2859), but the MLA latent expansion still reshaped `kv_b_proj` as the checkpoint's `[n_q, nope + v, kv_lora_rank]`. Every head's keys and values were scrambled, so `MLXCEL_BACKEND=xla mlxcel generate` on Youtu-VL repeated token 35 for image and text-only prompts. The continuous-batching engine keeps the checkpoint layout, which is why the HF oracle gate (and the server) stayed correct. The expansion now splits and contracts `kv_b` on the axes of the layout the graph declares. The Youtu-VL oracle gate now also loads the production session the CLI builds and requires its greedy tokens to match the HF reference on the image prompt and the gated batch engine on a text-only prompt. An emitter unit test pins the per-layout reshape. Closes #3364
The loader pushed StarCoder2's `mlp.c_fc.weight` as a `Whole` spec while the emitter declares it through `take_weight`, so the single-sequence `InOut` session failed at prefill (`expected shape 3072x12288, actual shape 12288x3072` on local-task, f16 vs f32 on cuda). This is the same #2859 regression class as the Youtu-VL MLA latent and the Phi4MM LoRA fixes. `c_fc` now goes through `push_proj` like `c_proj`. A new unit test emits prefill, decode and ragged graphs for every bundled family plus Youtu-VL and Mamba2, in both layouts and in f32 and f16, and checks that each declared weight argument has the shape and element type the loader uploads for its spec. It fails on StarCoder2 without this change. On starcoder2-3b-4bit, `--temp 0 -n 12` now gives the same 12 token ids on XLA cuda, XLA local-task and eager. Refs #3364
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Audit of
|
…vl-xla-repeat # Conflicts: # CHANGELOG.md
…vl-xla-repeat # Conflicts: # CHANGELOG.md
Summary
MLXCEL_BACKEND=xla mlxcel generateon Youtu-VL repeated token 35 (D) for image and text-only prompts oncudaandlocal-task. Root cause: the single-sequence session (IreeLlama) uploads projections transposed to[in, out]since #2859, butmla_expand_latentstill reshapedkv_b_projas the checkpoint's[n_q, nope + v, kv_lora_rank], scrambling every head's keys and values. #872's MLA landed before #2859, so it was correct then. The oracle gate and the server use the batch engine (IreeRaggedLlama), which keeps the checkpoint[out, in]layout, so both stayed correct.kv_bon the axes of the layout the graph declares (OutIn:[n_q, d, r]on axis 2;InOut:[r, n_q, d]on axis 0). The output shapes are unchanged.XlaInferenceSessionthat the CLI builds. On the image prompt its greedy tokens must equal the HFgreedy_tokens. On a text-only prompt they must equal the batch engine's (newgreedy_from_tokens: slot token prefill, then ragged decode).validate_youtu_vl_reference.shpassesMLXCEL_XLA_DEVICEto the run. The 27-stage comparison is unchanged.mla_latent_expansion_follows_the_projection_layoutpins the per-layout reshape.Same regression class: StarCoder2
Review audited every emitter consumer of a weight the single-sequence loader transposes under
InOut(#2859) without going throughlinear_proj. One more site was broken: StarCoder2'smlp.c_fc.weightwas pushed asWeightSpec::Wholewhile the emitter declares it throughtake_weight, sostarcoder2-3b-4bitfailed to load on XLA (expected shape 3072x12288, actual shape 12288x3072on local-task,expected f16 but have f32on cuda). It now goes throughpush_projlikec_proj; XLA cuda, XLA local-task and eager give the same 12 tokens. The newweights::tests::every_family_declares_weights_the_way_the_loader_uploads_thememits prefill, decode and ragged graphs for every bundled asset config plus Youtu-VL and Mamba2 in both layouts and both precisions and checks each declared weight against what the loader uploads; it failed on StarCoder2 before the fix. The full audit table is in the review comment.Test plan
cudawith main's emitter: production smoke fails with[35, 35, 35, 35]vs HF[576, 2870, 5658, 261]cudaandlocal-task: 27 stages pass,first_divergence=null, production image[576, 2870, 5658, 261], text-only[9495, 13, 128001, 198]youtu-vl-4b-instruct,--temp 0 -n 16, eager withMLXCEL_SDPA_DETERMINISTIC=1: XLAcudaandlocal-tasktoken ids equal eager for the image prompt (837 2870 371 261 6673 11 15589 2600 324 10282 19030 2467 13 2613 516 750), a chat text prompt (837 6849 324 7664 371 9495 13) and a--no-chat-templatetext prompt (9495 13)mlxcel-servereager, XLAcudaand XLAlocal-taskreturn identical text for the image chat, text chat and/v1/completionsrequestscargo test -p mlxcel-xla --lib emitter::tests::mla_,cargo check --features cuda,xla-iree --all-targets,cargo check --no-default-features --features xla-diagnostics --all-targets,python3 scripts/insert_apache_header.py --checkCloses #3364