Repository navigation
fix(models): apply YaRN rope_scaling in DeepSeek-V3 and LongCat MLA - #3306
Merged
Merged
Conversation
DeepSeekV3Attention and the LongCat ngram MLA rotated q_pe / k_pe with plain frequencies whatever rope_scaling declared, so every shipped DeepSeek-V3 / Kimi-K2 / LongCat checkpoint (YaRN) rotated its low-frequency pairs factor times too fast past original_max_position_embeddings. Only the softmax scale read the block. Promote one shared MlaRope (src/models/mla_rope.rs) that resolves the block through RopeScalingKind::resolve (deepseek_yarn renamed to yarn, --rope-* overrides honored) and applies the table with its YaRN magnitude. DeepSeek-V3 (and through it Kimi-VL, the pipeline stage executor and Xing4.0) and the LongCat ngram MLA resolve it once per model; DsaRope (V3.2), the LongCat sparse rope and Xing4.0's opt-in table move onto it, each keeping its train_ctx choice. Youtu keeps its plain rotation. A config without a block keeps the exact fast_rope call. Validated with teacher-forced traces against mlx-lm: GigaChat3-10B-A1.8B (deepseek_v3, 8-bit) has 0 of 1264 decided disagreements past 4096 (pre-fix 971); longcat-flash-lite-4bit has 6 of 2446 past 32768 (pre-fix 671). Moonlight, Xing4.0 and LongCat-Flash-Lite-Sparse trace byte-identical before and after. Closes #3295
The --rope-* "reached no RoPE code path" error now lists the MLA families that honor the override, and the LongCat resolve_rope comment states upstream's initialize_rope arguments correctly. supported-models.md records that the mlx-lm LongCat reference is deterministic across prefill step sizes and that the residual decided disagreements grow with position (4 to 10 per 4096-position chunk from 12288 on) without a step at 32768. Adds the bilingual technical report for #3306. Refs #3295
inureyes
marked this pull request as ready for review
November 23, 2026 03:52
This was referenced Nov 23, 2026
inureyes
added a commit
that referenced
this pull request
Nov 23, 2026
Brings in eleven commits from main. The only conflict was docs/supported-models.md, where main reworded the Xing4.0 entry next to the Hy4 one: main's Xing4.0 text and the Hy4 entry are both kept. The shared DeepSeek MLA RoPE change (#3306) and the per-thread MLA dispatch counters (#3308) merged cleanly under the Hy4 attention. Refs #2354
inureyes
added a commit
that referenced
this pull request
Nov 23, 2026
The 39 decided disagreements left on longcat-flash-lite-4bit after #3306 are a weight difference between the two runtimes, not mlxcel drift. The checkpoint ships a fused 4-bit kv_b_proj: mlxcel splits it into dense embed_q / unembed_out, while mlx-lm quantizes both halves again (embed_q along the transposed axis). Against a reference whose split stays dense, the 36864-position trace has 4 decided disagreements, below the 5 between the bf16 and float16 references, and 2 against a float32 dense-split reference. The dtype (MLXCEL_KEEP_BF16), KV storage and attention-path arms leave the count at 39 (33 with an additive rope mask). The mlx_lm_logit_trace.py docstring now says mlxcel converts bf16 to f16 only for unquantized checkpoints on Apple Silicon, and warns that a fused quantized kv_b_proj loads different weights in the two runtimes. supported-models.md replaces "source not identified" with the finding, and the arm tables are in docs/benchmark_results. No runtime code changes. Closes #3318
inureyes
added a commit
that referenced
this pull request
Nov 23, 2026
The 39 decided disagreements left on longcat-flash-lite-4bit after #3306 are a weight difference between the two runtimes, not mlxcel drift. The checkpoint ships a fused 4-bit kv_b_proj: mlxcel splits it into dense embed_q / unembed_out, while mlx-lm quantizes both halves again (embed_q along the transposed axis). Against a reference whose split stays dense, the 36864-position trace has 4 decided disagreements, below the 5 between the bf16 and float16 references, and 2 against a float32 dense-split reference. The dtype (MLXCEL_KEEP_BF16), KV storage and attention-path arms leave the count at 39 (33 with an additive rope mask). The mlx_lm_logit_trace.py docstring now says mlxcel converts bf16 to f16 only for unquantized checkpoints on Apple Silicon, and warns that a fused quantized kv_b_proj loads different weights in the two runtimes. supported-models.md replaces "source not identified" with the finding, and the arm tables are in docs/benchmark_results. No runtime code changes. Closes #3318
inureyes
added a commit
that referenced
this pull request
Nov 23, 2026
The 39 decided disagreements left on longcat-flash-lite-4bit after #3306 are a weight difference between the two runtimes, not mlxcel drift. The checkpoint ships a fused 4-bit kv_b_proj: mlxcel splits it into dense embed_q / unembed_out, while mlx-lm quantizes both halves again (embed_q along the transposed axis). Against a reference whose split stays dense, the 36864-position trace has 4 decided disagreements, below the 5 between the bf16 and float16 references, and 2 against a float32 dense-split reference. The dtype (MLXCEL_KEEP_BF16), KV storage and attention-path arms leave the count at 39 (33 with an additive rope mask). The mlx_lm_logit_trace.py docstring now says mlxcel converts bf16 to f16 only for unquantized checkpoints on Apple Silicon, and warns that a fused quantized kv_b_proj loads different weights in the two runtimes. supported-models.md replaces "source not identified" with the finding, and the arm tables are in docs/benchmark_results. No runtime code changes. Closes #3318
inureyes
added a commit
that referenced
this pull request
Nov 23, 2026
…on (#3332) Closes #3318 The 39 decided disagreements left on `longcat-flash-lite-4bit` after #3306 come from a weight difference, not from mlxcel drift. The checkpoint ships a fused 4-bit `kv_b_proj`. mlxcel splits it into dense `embed_q` / `unembed_out`. mlx-lm quantizes both halves again, and `embed_q` is quantized along the transposed axis. No runtime code changes. ## Arms (36864 positions, #3306 corpus, 2048-step cached reference prefill) | Reference | Candidate | Per 4096-position chunk | Decided | PPL cand. / ref. | | --- | --- | --- | --- | --- | | mlx-lm bf16 | mlxcel main | 0 1 0 4 10 4 6 8 6 | 39 / 20486 | 25.45 / 25.82 | | same | `MLXCEL_KEEP_BF16=1` (byte-identical rows) | 0 1 0 4 10 4 6 8 6 | 39 / 20486 | same | | same | `MLXCEL_TRACE_KV_CACHE_MODE=fp16` (identical rows) | 0 1 0 4 10 4 6 8 6 | 39 / 20486 | same | | same | rope term as additive mask, fused 128-wide SDPA (local experiment, not committed) | 0 0 0 1 6 5 8 8 5 | 33 / 20486 | 25.40 / 25.82 | | mlx-lm bf16 | mlx-lm cast to float16 (dtype noise floor) | 0 0 0 1 1 0 0 1 2 | 5 / 20486 | 25.89 / 25.82 | | mlx-lm bf16, dense split | mlxcel main | 0 0 0 2 1 0 0 0 1 | 4 / 20489 | 25.45 / 25.63 | | mlx-lm float32, dense split | mlxcel main | 0 1 0 1 0 0 0 0 0 | 2 / 20208 | 25.45 / 25.82 | - Arm 1 does not move because `bf16_to_f16_at_load` already keeps a quantized checkpoint's bf16 side data. The issue's premise that this checkpoint runs in f16 does not hold. - Arm 3: `MLXCEL_TRACE_MLA_STATS=1` reports `decompressed=476` with no absorbed step, so there is no second path to force. - The per-layer bisection (arm 4) was not needed once the dense-split reference reached the floor. ## Changes - `scripts/mlx_lm_logit_trace.py` docstring: mlxcel converts bf16 to f16 only for unquantized checkpoints on Apple Silicon (unless `MLXCEL_KEEP_BF16`), and a fused quantized `kv_b_proj` loads different weights in the two runtimes. The `--mlx-vlm` block that #3281 edits is untouched. - `docs/supported-models.md`: the LongCat entry states the finding instead of "source not identified". - `docs/benchmark_results/longcat-flash-lite-trace-residual-m3ultra-2026-11-23.md`: all arm rows, plus a no-context check. - Bilingual technical report in `TECHNICAL_REPORTS/3332-longcat-trace-residual-20261123.*.md`. Because no runtime code changed, the sparse variant and the GigaChat3 traces are unaffected by construction. Checks: fmt, the `scripts/ci` contract scripts, the header check, and the `coverage_tests` (18 passed) and `longcat` (57 passed) lib selectors. The issue's broad `-- --test-threads=1 longcat` gate is left to the orchestrator.
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.
Closes #3295
DeepSeekV3Attentionand the LongCat ngram MLA rotatedq_pe/k_pewith plainbase^(2i/d)frequencies whateverrope_scalingdeclared, so every YaRN checkpoint (DeepSeek-V3 / Kimi-K2factor40 over 4096, LongCat-Flash-Litefactor10 over 32768) rotated its low-frequency pairsfactortimes too fast past the original context. Only the softmax-scale correction read the block.Changes
MlaRope(src/models/mla_rope.rs): resolves the block throughRopeScalingKind::resolve(deepseek_yarnrenamed toyarn,--rope-*/--yarn-*overrides honored), applies the table plus the YaRN magnitude to the rotated dims, and keeps the exactfast_rope(.., base, 1.0, offset)call when there is no block.deepseek_v3,kimi_k2,joyai_llm_flash, and through it Kimi-VL's text model and the V3 pipeline stage executor) and the LongCat ngram MLA resolve it once per model and duplicate it per layer.original_max_position_embeddingsfalls back to 4096 (notrain_ctx), as upstreamYarnRoPEdoes.DsaRope(V3.2), the LongCat sparse rope and Xing4.0's opt-in table now use it, each keeping its owntrain_ctx(None,max_position_embeddings,max_position_embeddings). Xing4.0 still refuseslinear. Youtu passesMlaRope::plainso its rotation stays plain. One plain-path change: the sparse rope's no-table rotation now follows--rope-freq-baselike its table (it usedrope_thetabefore).TECHNICAL_REPORTS/3306-mla-yarn-rope-20261123.*.md.supported-models.md(V3, LongCat, Xing), the--rope-*coverage list inllama-server-compat.md, and the Used-by lists inrope_utils.rs/rope_overrides.rs, and the override error text.Validation
Teacher-forced
logit_traceagainst mlx-lm (references/mlx-lm1bf8da0), with the pre-fix binary (main) as the negative arm:deepseek_v3, YaRN 64 over 4096), 8-bitmodels/gigachat3-10b-a1.8b-mlx-8bit) because thedeepseek_v3loader does not load an unquantized MoE checkpoint; mlx-lm needed a shim to drop the MTP layer at index 26 (it hardcodes 61).moonlight-16b-a3b-instruct-4bit(no block),xing4.0-29b-a4b-mlx-8bit,longcat-flash-lite-sparse-4bit.YarnRoPEat the V3, GigaChat3 and LongCat geometries, the alias, byte-identity of the no-block path, the magnitude, a syntheticdeepseek_v3YaRN config changingq_pepast the original context, YaRN reaching every layer and batched decode, and the ngram model carrying the table. I ran the narrow selectorscoverage_tests,mla_rope,deepseek_v3,deepseek_v32,xing4_0,longcat,kimi,youtu,rope_*and the stage executor, plus clippy, fmt and the CI scripts. The broad workspace gate is left to CI.xing4_0_tests.rswas edited only to follow the field rename (rope_tabletorope.freqs(),with_rope_tabletowith_rope). The assertions are unchanged.