feat(speculative): Nemotron 3.5 Super VL bundled MTP head as a drafter
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 8/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
Start from src/models/qwen4_exp_mtp_drafter.rs and src/models/drafter_loader.rs:47-70 to see how an MTP drafter is built from a target checkpoint, then read nemotron_h.rs sanitize_weights around lines 2361-2362. Done means the three acceptance tests in nemotron_h_mtp_drafter_tests.rs and nemotron_h_tests.rs pass and the real-checkpoint run gives a non-zero acceptance rate with byte-identical output. This is blocked by #3258 and needs Mamba rollback design, so it is not a first task.
索引モデルが issue の本文から書いたものです。
説明
Summary
Run the MTP head bundled in Nemotron 3.5 Super VL checkpoints as a speculative drafter, with the same checkpoint passed as target and --draft-model. This needs three pieces mlxcel does not have for Nemotron-H: the MTP draft model, an MtpTarget adapter, and a verify forward that can roll back Mamba-2 conv and SSM state to any accepted prefix. Blocked by #3258, because the only checkpoints that carry the head are nemotron_h_omni packs, which load only after that issue.
Upstream reference
- Neywa-Labs/mlx-vlm#2528, commit
63fc9795: https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/nemotron_h_mtp/nemotron_h_mtp.py,config.py,split.py, and thenemotron_h_mtpentry indrafters/__init__.pyandmtp_split.py. - The target verify path predates the analysis range: Neywa-Labs/mlx-vlm#2145 (commit
2a73dc2d, "Add Nemotron-H speculative decoding support"), https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/models/nemotron_h/speculative_verifier.py (_mamba_update_timewise,replay_mamba_state) andLanguageModel.speculative_verify_hiddenin https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/models/nemotron_h/language.py.
Architecture (from upstream code and the checkpoints)
- Config (
NemotronHMTPConfig):text_configis the target's Nemotron-H config;num_nextn_predict_layersmust be 1; the layer pattern comes frommtp_hybrid_override_patternormtp_layers_block_type(["attention", "moe"]on Super VL, so["*", "E"]) and may contain only*andE. Defaultblock_size2; a larger block reuses the same module recursively. - Draft forward (
_forward_hidden):h = eh_proj(concat(enorm(embed(token)), hnorm(hidden))), whereeh_projisLinear(2 * 4096, 4096, bias=False)and both norms are RMSNorm atlayer_norm_epsilon. Then each block in the pattern (attention block with its own KV cache, then the LatentMoE block), thenfinal_layernormon the last block. Token embeddings andlm_headare the target's (bind).hiddenis the target's post-norm_fhidden state (speculative_draft_hiddenreturns it unchanged), one per prompt token; a hidden count that differs from the prompt length is an error. - Weights (nativ-community NVFP4 pack, 26 tensors):
language_model.mtp.layers.0.{eh_proj,enorm,hnorm,norm}.weight,layers.0.mixer.{q,k,v,o}_proj.weight(dense),layers.1.norm.weight,layers.1.final_layernorm.weight,layers.1.mixer.{fc1_latent_proj,fc2_latent_proj}.weight,layers.1.mixer.gate.{weight,e_score_correction_bias}, and NVFP4layers.1.mixer.{shared_experts.{up,down}_proj,switch_mlp.{fc1,fc2}}.{weight,scales,weight_scale_2}. The native NVIDIA pack stores per-expertexperts.N.*withk_scale/v_scaleon attention;sanitizedrops.k_scale/.v_scaleand stacks experts with the target's own Nemotron-H sanitize run on the two-layer pattern.e_score_correction_biasstays f32 (cast_predicate). - Target verify (Neywa-Labs/mlx-vlm#2145): the verify forward runs the block of
Ltokens through every layer once, and for each Mamba layer it records the per-token SSM state and the conv input so that the state after any accepted lengthn <= Lcan be rebuilt (replay_mamba_state); attention KV is trimmed to the accepted offset. Rejected tokens therefore leave no trace in either cache.
Current mlxcel behavior
NemotronHModel::sanitize_weightsdrops everymtp.*tensor (src/models/nemotron_h.rs:2361-2362), and the Omni loader feeds it thelanguage_model.-stripped text weights (src/loading/vlm_nemotron_h_nano_omni.rs:416).- No Nemotron-H family is an MTP target:
mtp_target_family_supported(src/server/batch/speculative_burst.rs:771-786) lists Gemma 4, Qwen 3.5, Qwen4Exp, Inkling and GLM-4.7-Flash only, andspeculative_bench::mtp_target_supported(src/bin/speculative_bench.rs:460) matches it. Nemotron-H has snapshot and restore for its Mamba state (nemotron_h.rs:470-536) but no speculative verify or rollback hook. - The binary-side drafter factory
src/models/drafter_loader.rs:47-70already builds two MTP heads whose blocks live in this crate (GLM-4.7-Flash, Qwen4Exp); the Qwen4Exp case loads straight from the target checkpoint (Qwen4ExpMtpDraftModel::from_target_checkpoint, #2917), gated in core byhas_qwen4_exp_mtp_tensors(src/lib/mlxcel-core/src/drafter/mod.rs:615, used at:782-785). Follow that pattern exactly.
Required changes
src/models/nemotron_h_mtp_drafter.rs(new, +_tests.rs):NemotronHMtpDraftModelimplementing the coreDraftertrait forDrafterKind::Mtp, withfrom_path(a split directory withmodel_type: nemotron_h_mtp) andfrom_target_checkpoint(anemotron_h_omni/nemotron_h_nano_omni/nemotron_hdirectory). Load only tensors undermtp.orlanguage_model.mtp.throughmlxcel_core::weights::load_weights_from_dir_index_filtered, so the target's shards are not read whole. Strip the prefix, drop.k_scale/.v_scale, and reuse the existing Nemotron-H blocks, expert stacking and NVFP4weight_scale_2loading fromsrc/models/nemotron_h.rsandsrc/models/switch_layers.rsrather than copying them. Refuse at load, naming the field, whennum_nextn_predict_layers != 1, when the pattern contains anything but*/E, or when the target'shidden_size/vocab_sizediffer.src/models/nemotron_h_mtp_target.rs(new):NemotronHMtpTargetAdapterimplementingMtpTargetforNemotronHModel, plus a VL variant overNemotronHNanoOmniVlModel's text model, both routing through the model-owned per-sequence state likeqwen4_exp_mtp_target.rs.verify_forwardcaptures per-token Mamba state (conv window and SSM state per position, the Neywa-Labs/mlx-vlm#2145 scheme);verify_finalizerestores the state at the accepted length and trims attention KV. Batch 1, no tree rounds (refuse by name, as the Qwen4Exp adapter does).src/models/nemotron_h.rs: addforward_speculative_for_sequenceandrollback_speculative_cache_for_sequencehooks (the Qwen 3.5 shape atsrc/models/qwen3_5.rs:3353-3380), and keepsanitize_weightsdroppingmtp.*for the target. Update the// Used by:comments of any shared Mamba helper the capture reuses.- Core detection (
src/lib/mlxcel-core/src/drafter/mod.rs): addNEMOTRON_H_MTP_MODEL_TYPE = "nemotron_h_mtp"todrafter_kind_by_model_type()asMtp; addhas_nemotron_h_mtp_tensors(path)(tensor-presence, likehas_qwen4_exp_mtp_tensors), and resolve anemotron_h_omni,nemotron_h_nano_omniornemotron_hdirectory toMtponly when those tensors exist. Make coreload_drafterreturnDrafterError::BinaryCrateDrafterfor these types, so only the binary wrapper builds them. - Wiring:
src/models/drafter_loader.rsarms for the split and target-checkpoint cases; addLoadedModel::NemotronH(_)andLoadedModel::NemotronHNanoOmniVLM(_)tomtp_target_family_supportedand to the adapter dispatch insrc/server/batch/speculative_burst.rs,src/server/batch/scheduler.rs,src/commands/generate.rs(run_offline_mtp,:2502) andsrc/bin/speculative_bench.rs. Multimodal requests decline to classic decode through the existing burst gate; upstream allows image MTP, but mlxcel's other MTP targets do not, and that is a separate change.
Acceptance criteria
-
src/models/nemotron_h_mtp_drafter_tests.rsmtp_head_loads_only_mtp_tensors: a fixture directory with target tensors plus the 26 head tensors builds the drafter, and the filtered load never opens a target-only shard. - Same file,
native_layout_drops_kv_scales_and_stacks_experts: per-expertexperts.N.*withk_scale/v_scalesanitize to the same names as the stacked MLX layout. - Same file,
refuses_wrong_pattern_and_depth:num_nextn_predict_layers: 2and a pattern containingMboth fail with errors naming the field. -
src/models/nemotron_h_tests.rsmamba_rollback_matches_shorter_forward: on a toy hybrid config (M,*,E), verifying 4 tokens and rolling back ton = 0..=4leaves every Mamba conv/SSM state and KV offset equal to a plain forward over the firstntokens (1e-5). -
src/lib/mlxcel-core/src/drafter/mod.rstests: anemotron_h_omnidirectory withmtp.*tensors resolves toMtp, one without them does not, and coreload_drafteron it returnsBinaryCrateDrafter. -
src/server/batch/speculative_burst_tests.rs: the family gate admitsNemotronHandNemotronHNanoOmniVLM. - Real checkpoint, integrated:
mlxcel generate -m models/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4 --draft-model models/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4 -p "Write a quicksort in Python." -n 256 --temp 0reports a non-zero acceptance rate and its output is byte-identical to the run without--draft-model. The same pairing works onmlxcel-server --model-draft.
Validation
Checkpoint: nativ-community/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4 (80.2 GB, MLX nvfp4 mode, carries the head), which fits a 128 GB machine for short contexts. Duckets/...-MLX-4bit and the rapid-mlx packs carry no mtp.* tensors. The native nvidia/...-NVFP4 pack also carries the head but needs #3201 to load.
make verify-test
cargo test --profile test-fast nemotron_h_mtp
cargo test --profile test-fast -p mlxcel-core drafter::
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
python3 scripts/ci/check_cross_repo_refs.py
./target/release/mlxcel download nativ-community/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4
Related
#3258 (blocker: nemotron_h_omni loading), #2917 (target-checkpoint MTP pattern), #1201 (MTP byte-identity), #3201 (native NVFP4 pack), #2400 (generic native MTP detection; this issue does not depend on it because it adds its own tensor-presence check).
- 主要言語
- Rust
- スター
- 505
- フォーク
- 81
- 平均マージ
- 14時間 2分
- マージ済み PR(30日)
- 448
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
lablup/mlxcel のほかの issue
-
area:core priority:high status:ready type:security
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
priority:medium status:ready type:security
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
area:models modeltype:text priority:medium status:in-progress type:bug
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
メンテナーはふだん 1 日以内に返信
-
area:models priority:low status:ready type:test
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
area:models modeltype:omni priority:medium status:ready type:bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
psmux-resurrect: restoring a session with a numeric name puts its windows into the wrong session (`new-window -t 4` is read as window 4)対応中かも @ealwanlee が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
psmux/psmux-plugins#47 ·
-
Link Checker Reportオープンautomated issue report
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
ratatui/awesome-ratatui#598 ·
メンテナーはふだん 1 日以内に返信
-
release
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
github/gh-aw-mcpg#17603 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
C-Bug S-Needs-Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bevyengine/bevy#26718 ·
メンテナーはふだん 2 日以内に返信