Skip to content

feat: load a Qwen 3.5 base checkpoint's bundled MTP head - #3673

Merged
inureyes merged 2 commits into
mainfrom
feature/issue-2400-bundled-qwen35-mtp
Dec 2, 2026
Merged

inureyes merged 2 commits into
mainfrom
feature/issue-2400-bundled-qwen35-mtp

Conversation

@inureyes

@inureyes inureyes commented Dec 2, 2026

Copy link
Copy Markdown
Member

Closes #2400

A Qwen 3.5 / 3.6 / 3.8 base checkpoint keeps its MTP head inline as raw mtp.* tensors, but mlxcel could only draft with a head split into a qwen3_5_mtp directory, and it has no splitter for that family. This makes the checkpoint its own drafter: mlxcel generate -m <dir> --draft-model <dir> and mlxcel-server --model-draft <dir> read only the mtp.* tensors through the index-filtered loader and build the existing Qwen35MtpDraftModel from them, so the target's shards are not loaded twice.

resolve_drafter_kind recognizes a native MTP source from mtp_num_hidden_layers or num_nextn_predict_layers (root or text_config) or from mtp.* tensor presence. The rule sits after every family-specific arm, skips model types already in the kind map, and excludes qwen4_exp, so a family with its own bundled drafter is not captured (issue #3262's DSpark arm belongs above it too). A qwen3_5_text root uses the whole root config as the text config (Neywa-Labs/mlx-vlm#2677). Base families that declare a head but have no bundled runtime (deepseek_v3, glm4_moe_lite, qwen3_5_moe, qwen3_5_moe_text) now return a named NoBundledDrafterRuntime instead of the Gemma 4 assistant loader, and glm4_moe_lite points at mlxcel split-mtp. An explicit --draft-kind keeps priority with the existing mismatch warning.

Validation:

  • cargo test --profile test-fast -p mlxcel-core drafter::: 348 passed, covering detection from config and tensors, refusal by family, the from_base_checkpoint inventory, head-less and text-only fixtures, and the real Qwen/Qwen3.5-0.8B head load (ignored test, run by hand).
  • Integrated offline: mlxcel generate -m models/Qwen3.5-0.8B --draft-model models/Qwen3.5-0.8B -p "Write a quicksort in Python." -n 128 --temp 0 ran 51 MTP rounds with acceptance rate 0.507, and its completion was byte-identical to the run without --draft-model (258-character completion extracted from both runs).
  • Integrated server: mlxcel-server --model models/Qwen3.5-0.8B --model-draft models/Qwen3.5-0.8B served 128 tokens through 33 MTP rounds with 95 accepted draft tokens (rate 0.969).
  • cargo fmt --check passes. cargo clippy -p mlxcel-core --lib --tests -- -D warnings passes. Root clippy on the touched files reports nothing; the repository-wide root clippy is blocked by pre-existing lints in src/vision/dense/preprocess.rs and src/vision/encoders/qwen3_vl_tests.rs, which this change does not touch.

@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:inference Generation, sampling, decoding (incl. speculative, DRY) modeltype:text Text-only language model status:review Under review status:done Completed and removed status:review Under review labels Dec 2, 2026
inureyes added a commit that referenced this pull request Dec 2, 2026
Qwen 3.5 / 3.6 / 3.8 base checkpoints carry their MTP head inline as raw mtp.* tensors, but mlxcel could only use a head split into a qwen3_5_mtp directory. Detect a native MTP source from the checkpoint config (mtp_num_hidden_layers or num_nextn_predict_layers at the root or under text_config) or from mtp.* tensor presence, and build the existing Qwen35MtpDraftModel from only those tensors through the index-filtered loader.

The detection sits after every family-specific arm so a bundled drafter is not captured by it, and a qwen3_5_text root is read with the root config as the text config. Other base families that declare a head but have no bundled runtime (deepseek_v3, glm4_moe_lite, the qwen3_5_moe aliases) now fail with a named NoBundledDrafterRuntime instead of the Gemma 4 assistant loader, and glm4_moe_lite points at mlxcel split-mtp.

Refs #2400
@inureyes
inureyes force-pushed the feature/issue-2400-bundled-qwen35-mtp branch from aa8297b to 9ee1713 Compare December 2, 2026 01:21
@inureyes
inureyes marked this pull request as ready for review December 2, 2026 01:21
@inureyes
inureyes merged commit e50c0a2 into main Dec 2, 2026
1 check passed
@inureyes
inureyes deleted the feature/issue-2400-bundled-qwen35-mtp branch December 2, 2026 01:22
inureyes added a commit that referenced this pull request Dec 2, 2026
#3673 added MLXCEL_TEST_QWEN35_MTP_BASE in the qwen3_5_mtp drafter tests without documenting or allowlisting it, so the env-var-docs gate fails on main. It is the checkpoint path of an opt-in real-model test, the same as its MLXCEL_TEST_QWEN35_MTP_DRAFTER sibling, so it joins that allowlist group.

Refs #3660
inureyes added a commit that referenced this pull request Dec 2, 2026
## Problem

`main` is red on two jobs, both from the same cause:

- `env var docs`: `MLXCEL_TEST_QWEN35_MTP_BASE` is read in `src/lib/mlxcel-core/src/drafter/qwen3_5_mtp/tests.rs` but is neither documented nor allowlisted.
- `python tooling tests`: `test_check_env_var_docs.CheckEnvVarDocsTests.test_repository_passes` fails with `AssertionError: 1 != 0 : env-var-docs: FAIL`, the same check under pytest.

The name arrived with #3673's real-checkpoint gate and was missed because the per-unit pre-merge checks did not include `scripts/ci/check_env_var_docs.py`.

## Change

Add `MLXCEL_TEST_QWEN35_MTP_BASE` to `ALLOWLIST` in `scripts/ci/check_env_var_docs.py`, in a new group mirroring the existing GLM-4.7-Flash MTP test-parameter group. It is test-only, so the allowlist is the correct path rather than a `docs/environment-variables.md` entry.

## Verification

`python3 scripts/ci/check_env_var_docs.py` now exits 0:

```
env-var-docs: OK, 433 MLXCEL_* names in 3441 *.rs files under src/, 281 documented on docs/environment-variables.md, 152 allowlisted.
```

`pytest` is not installed in this environment, but `test_repository_passes` only asserts that this script exits 0, which is verified above.

## Note

`cargo-clippy` and `OpenXLA feature compile` are also red on `main` and were red before #3673 merged (`cdfd25473`, `96f1c55c4`, `5526a0cfa`). They are not addressed here.
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) modeltype:text Text-only language model priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Load bundled Qwen 3.5 MTP drafters and detect native MTP heads

1 participant