feat(speculative): Mellum bundled MTP head as a drafter

Open
#3,263 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
8/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust

Research direction

Start with src/models/mellum.rs (sanitize at lines 1081-1101, the rotating and standard cache setup near 771-815) and src/server/batch/speculative_burst.rs (mtp_target_family_supported near line 771). The work requires a new drafter module plus an MtpTarget adapter, and it is blocked by #2400. Done means the unit tests named in the issue pass and the real-checkpoint acceptance run is byte-identical with a non-zero acceptance rate.

Written by the indexing model from the issue text.

Description

arch:hybrid arch:moe area:inference modelsize:medium modeltype:text priority:low status:blocked type:enhancement

Summary

Use the MTP head bundled in JetBrains/Mellum2.1-12B-A2.5B-Thinking-MTP as a speculative drafter, with the same checkpoint passed as target and --draft-model. mlxcel runs the Mellum target (src/models/mellum.rs) but has no Mellum drafter and no Mellum MtpTarget adapter. Blocked by #2400, which adds the native-MTP detection (num_nextn_predict_layers > 0 or mtp.* tensors) and the bundled-drafter dispatch this issue plugs a second family into.

Upstream reference

Neywa-Labs/mlx-vlm#2677 (merge 8c5641c3, commit f417d6f5):

Architecture (from upstream code and the checkpoint)

Checkpoint config: model_type mellum, num_nextn_predict_layers 1, 28 layers, hidden 2304, 32 heads, 4 KV heads, head_dim 128, layer_types repeating [sliding, sliding, sliding, full], sliding_window 1024, 64 experts top-8, vocab 98304, tie_word_embeddings false. Sliding layers use plain RoPE at rope_theta 500000; full layers use YaRN (factor 16).

  • The head (205 tensors under mtp.): fc.weight (Linear(2 * 2304, 2304, bias=False)), pre_fc_norm_embedding.weight, pre_fc_norm_hidden.weight, one decoder layer layers.0.* (attention with q_norm/k_norm, per-expert MoE mlp.experts.N.{gate,up,down}_proj and router mlp.gate), and norm.weight.
  • Forward: h = fc(concat(pre_fc_norm_embedding(embed(token)), pre_fc_norm_hidden(hidden))), then the single layer with the type of layer_types[0] (sliding_attention, so window 1024 and the sliding RoPE), then norm; logits through the target's lm_head and embeddings through the target's table. hidden is the target's post-final-norm state, one per token.
  • The norms are ordinary RMSNorm: unlike Qwen3-Next, no +1 shift (MellumMTPSplitter.run_sanitize). Experts are stacked to switch_mlp as the target does.
  • The drafter cache is a plain, trimmable KV cache (not rotating), so a rejected draft never evicts accepted rows. Upstream requires exactly one prediction layer.

Current mlxcel behavior

  • MellumWrapper::sanitize (src/models/mellum.rs:1081-1101) drops a tied lm_head and stacks experts, but does not drop mtp.*; check whether the MTP checkpoint loads as a target today (the acceptance test below pins the answer).
  • Mellum's target caches are model-owned and mixed: Cache::Standard for full layers and Cache::Rotating(RotatingKVCache) for sliding layers (src/models/mellum.rs:771-815, MellumWrapper at :1135). A multi-row verify on a rotating cache can overwrite rows that rollback then needs; the Gemma 4 adapters solve the same problem by sizing a rollback buffer to the block (Gemma4MtpTargetAdapter::new_with_block_size, src/models/gemma4_mtp_target.rs:368).
  • mtp_target_family_supported (src/server/batch/speculative_burst.rs:771) does not list LoadedModel::Mellum. Mellum's YaRN helper is compute_yarn_rope (src/models/mellum.rs:196).

Required changes

  1. src/models/mellum_mtp_drafter.rs (new, + _tests.rs): MellumMtpDraftModel implementing the core Drafter trait for DrafterKind::Mtp, built from MellumModel's DecoderLayer, Attention, SparseMoeBlock and RMSNorm (src/models/mellum.rs:275-830) and its stack_experts; do not copy them. from_target_checkpoint(path) loads only mtp.* tensors with load_weights_from_dir_index_filtered; from_path accepts a split model_type: mellum_mtp directory. Refuse num_nextn_predict_layers != 1 and a hidden or vocab size that differs from the target, naming the field.
  2. src/models/mellum_mtp_target.rs (new): MellumMtpTargetAdapter implementing MtpTarget over MellumWrapper's per-sequence state, returning the post-norm hidden, with a block-sized rollback buffer on the rotating caches following the Gemma 4 adapter. Batch 1; tree rounds refuse by name.
  3. src/models/mellum.rs: drop mtp.* in sanitize; add the *_for_sequence verify and rollback hooks the adapter calls.
  4. Dispatch: in the #2400 dispatch, route a base model_type: mellum directory with mtp.* tensors to the binary-crate loader in src/models/drafter_loader.rs (core load_drafter returns BinaryCrateDrafter for it), and add mellum_mtp to drafter_kind_by_model_type() as Mtp. Add LoadedModel::Mellum to mtp_target_family_supported and to the adapter dispatch in speculative_burst.rs, scheduler.rs, src/commands/generate.rs (run_offline_mtp) and src/bin/speculative_bench.rs.

Acceptance criteria

  • src/models/mellum_mtp_drafter_tests.rs loads_only_mtp_tensors_and_stacks_experts: a fixture with target tensors plus a two-expert mtp.* head builds the drafter with switch_mlp planes and never reads target-only tensors.
  • Same file, norms_are_not_shifted: a pre_fc_norm_hidden.weight of ones yields unit scaling (a +1 shift would double it).
  • Same file, refuses_two_prediction_layers.
  • src/models/mellum_tests.rs sanitize_drops_mtp_tensors and sliding_rollback_after_verify_matches_shorter_forward: with sliding_window 4 and a 3-token verify past the window, rolling back to n = 0..=3 gives the same caches as a plain forward over n tokens.
  • src/server/batch/speculative_burst_tests.rs: the family gate admits Mellum.
  • Real checkpoint, integrated: mlxcel generate -m models/Mellum2.1-12B-A2.5B-Thinking-MTP --draft-model models/Mellum2.1-12B-A2.5B-Thinking-MTP -p "Write a Python function that adds two integers." -n 256 --temp 0 reports a non-zero acceptance rate and its output is byte-identical to the run without --draft-model; a prompt longer than 1024 tokens (past the sliding window) also matches. The same pairing works on mlxcel-server --model-draft.

Validation

JetBrains/Mellum2.1-12B-A2.5B-Thinking-MTP is 25.2 GB in BF16 (Hub API, 2026-11-23), so it fits a 128 GB machine. The non-MTP release (JetBrains/Mellum2.1-12B-A2.5B-Thinking) and mlx-community/Mellum2.1-12B-A2.5B-Thinking-6bit carry no mtp.* tensors.

make verify-test
cargo test --profile test-fast mellum
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
python3 scripts/ci/check_cross_repo_refs.py
./target/release/mlxcel download JetBrains/Mellum2.1-12B-A2.5B-Thinking-MTP

Related

#2400 (blocker: native MTP detection and bundled-drafter dispatch; it also carries the Qwen text-only aliases from the same upstream PR), #2917 (target-checkpoint MTP pattern), #1201 (MTP byte-identity).

Dominant language
Rust
Stars
505
Forks
81
Avg merge
14h 2m
Merged PRs (30d)
448

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lablup/mlxcel

All issues in lablup/mlxcel

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.