feat(speculative): Nemotron 3.5 Super VL bundled MTP head as a drafter
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 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 分钟
- 30 天内合并 PR
- 448
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
-
area:ui effort:medium enhancement P7 source:agent
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
marketing
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
documentation priority: low tech-debt
难度 2/5 1-3 小时 新手友好度 64/100
nledford/Ladderback#1823 ·
维护者通常 1 天内回复
-
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 ·
-
bug
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 1 天内回复