Skip to content

fix: apply YaRN rope scaling in the Qwen3.5 MTP drafter layer - #3491

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-3479-mtp-drafter-yarn
Nov 27, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-3479-mtp-drafter-yarn

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

The Qwen 3.5 MTP drafter rotated with plain rope_theta even when its rope_parameters declared YaRN, so on YaRN checkpoints it drafted from a different position encoding than the target verifies with. Output stayed exact (the target verifies every token), but acceptance dropped. The drafter now gets the same YaRN table and attention factor as the target.

  • mlxcel-core: Qwen35MtpAttention takes an optional YaRN table and attention factor (set_yarn_rope). When one is set, it rotates with fast_rope_with_freqs and scales only the rotary lanes. The lane scaling moved into mlxcel_core::rope_lanes::scale_rotary_lanes, and Qwen3NextAttention now calls that same function instead of keeping its own copy. Qwen35MtpDraftModel gained set_yarn_rope, yarn_rope and config, and the drafter text config now reads max_position_embeddings.
  • Binary crate: the body of Qwen35Config::yarn is now the free function qwen35_yarn(rope_parameters, rope_dims, rope_theta, max_position_embeddings), and drafter_loader::load_drafter handles qwen3_5_mtp itself. It loads the drafter through core and installs the table from that function, so the CLI, the server drafter slot and speculative_bench all pick it up, along with the --yarn-* knobs. A block that names yarn but cannot build a table fails the drafter load with the target's message. Configs without YaRN behave as before.

Test plan

Remote CI was cancelled by maintainer decision. Validation was local only (M3 Ultra, Metal):

  • cargo fmt --all -- --check
  • cargo clippy -p mlxcel-core --lib --tests --features metal,accelerate -- -D warnings
  • cargo clippy -p mlxcel --lib --tests --features metal,accelerate -- -D warnings
  • cargo test -p mlxcel-core --lib --profile test-fast --features metal,accelerate drafter::qwen3_5_mtp rope_lanes: 26 passed, existing tests.rs cases unchanged
  • cargo test -p mlxcel --lib --profile test-fast --features metal,accelerate filtered to qwen3_5, qwen3_next, rope_utils and drafter_loader: qwen3_5 62 passed (includes the 6 new qwen3_5_mtp_yarn_tests), qwen3_next 23, rope_utils 36, drafter_loader 3, all green
  • Greedy MTP speculative generation on qwen3.8-27b-4bit with qwen3.8-27b-mtp-4bit (a non-YaRN checkpoint), 64 tokens, before and after: identical text and identical acceptance (rounds=28, accepted=35/56, rate 0.625)

There is no local YaRN Qwen 3.5 checkpoint, so the acceptance gain on YaRN checkpoints was not measured. The new tests cover it instead: the drafter's table equals the target's bit for bit on the SenseNova YaRN config, and the loader installs that table.

Closes #3479

The Qwen 3.5 MTP drafter rotated with plain rope_theta even when its rope_parameters declared YaRN, so on YaRN checkpoints it drafted from a different position encoding than the target verifies with. Output stayed exact, but acceptance dropped.

Qwen35MtpAttention now accepts an optional YaRN table and attention factor and rotates with fast_rope_with_freqs. The rotary-lane scaling is shared with Qwen3NextAttention through mlxcel_core::rope_lanes. The body of Qwen35Config::yarn is now the free function qwen35_yarn, and drafter_loader::load_drafter loads qwen3_5_mtp through core and then installs the table that function builds. The CLI, the server drafter slot and speculative_bench all get it, along with the --yarn-* knobs. A block that names yarn but cannot build a table fails the drafter load with the target's message. Configs without YaRN behave as before.

Validated with fmt, clippy on mlxcel-core and mlxcel, and the focused drafter, qwen3_5, qwen3_next and rope_utils tests. A greedy MTP run on qwen3.8-27b produced identical output before and after.

Closes #3479
@inureyes inureyes added status:done Completed type:bug Bug fixes, error corrections, or issue resolutions priority:low Low priority area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Nov 27, 2026
@inureyes
inureyes marked this pull request as ready for review November 27, 2026 05:39
@inureyes
inureyes merged commit 944dbfc into main Nov 27, 2026
28 of 33 checks passed
@inureyes
inureyes deleted the fix/issue-3479-mtp-drafter-yarn branch November 27, 2026 05:40
inureyes added a commit that referenced this pull request Nov 28, 2026
## Summary

Adds the bilingual technical reports that were skipped when these three PRs merged on 2026-11-27:

- `TECHNICAL_REPORTS/3489-jiff-1x-strftime-now-20261127.{en,ko}.md` (#3489, jiff 1.0.3 and the `strftime_now` format and zone)
- `TECHNICAL_REPORTS/3490-vision-resize-frame-parity-20261127.{en,ko}.md` (#3490, resize and frame-sampling parity)
- `TECHNICAL_REPORTS/3491-qwen35-mtp-drafter-yarn-20261127.{en,ko}.md` (#3491, YaRN in the Qwen 3.5 MTP drafter)

Each report records the decisions the PR encodes (for example why ERNIE follows the checkpoint's `processing_ernie4_5_vl.py` rather than transformers or mlx-vlm, and why the drafter YaRN table is installed by the binary crate's loader) and what remains unverified.

## Test plan

Docs only. Remote CI was cancelled by maintainer decision.

- [x] Facts cross-checked against the merged diffs, PR bodies and the local validation output
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:low Low priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Apply YaRN rope scaling in the Qwen3.5 MTP drafter layer

1 participant