feat(speculative): DeepSeek-V4.1 bundled DSpark drafter
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 8/100
Hướng nghiên cứu
This is a blocked design-heavy feature: it depends on the V4.1 text port (#2386) that adds src/models/deepseek_v41*.rs, which does not exist yet. Start by reading the DFlash drafter code in src/lib/mlxcel-core/src/drafter/dflash/markov.rs and src/server/batch/dflash_target.rs, and the detection pattern in src/lib/mlxcel-core/src/drafter/mod.rs. Done means the listed _tests.rs cases pass and the real-checkpoint generate run reports non-zero acceptance with byte-identical output.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Run the DSpark drafter bundled in every DeepSeek-V4.1 checkpoint (mtp.0 to mtp.2, 3,584 tensors in the MLX 2-bit pack) against the V4.1 target, with the same checkpoint passed as target and --draft-model. This is the "MTP and DSpark drafting" item #2386 lists as out of scope. It is filed separately and blocked by #2386 because every draft stage is a V4.1 block (V4.1 attention, HyperConnections, the V4.1 MoE and fake-quant helpers), and the target needs a transactional cache that only makes sense once the V4.1 cache exists.
Upstream reference
Neywa-Labs/mlx-vlm#2678 (merge 10199b59, commit dee11be3):
- https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/deepseek_v41_dspark/deepseek_v41_dspark.py (
DSparkAttention,DSparkStage,DeepseekV41DsparkDraftModel._hidden,sanitize) - https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/deepseek_v41_dspark/config.py and the base it extends, https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/deepseek_v4_dspark/config.py (
DeepseekV4DsparkConfig) anddeepseek_v4_dspark.py(draft_block) - https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/models/deepseek_v41/language.py:
DeepseekV41Cache.start_speculation/commit_speculation/abort_speculation, thespeculative_verifyandcapture_layer_idsbranches ofLanguageModel.__call__ mtp_split.pymapsdeepseek_v41anddeepseek_v41_texttoDeepseekV41DsparkSplitter(output_model_type: deepseek_v41_dspark).
Architecture
Config (mlx-community/DeepSeek-V4.1-Flash-MLX-2bit): num_nextn_predict_layers 3 (three stages), dspark_block_size 5 (proposals; verify block 5 + 1 = 6), dspark_noise_token_id 128799 (mask token), dspark_target_layer_ids [37, 38, 39], dspark_markov_rank 256, dspark_n_routed_experts 128, dspark_num_experts_per_tok 3, hidden_size 5120, hc_mult 4, o_groups 8, o_lora_rank 1024, sliding_window 128. runtime_block_size defaults to min(2, block_size), one proposal per round, because exact verification pays for each retained attention window; an explicit --draft-block-size wins.
- Target hidden tap: the target appends
h.mean(axis=2)(the mean over the 4 HyperConnection copies) at the input of each layer in[37, 38, 39], giving[B, L, 3 * 5120]. - Context:
context = main_norm(main_proj(fp8(target_hidden)))on stage 0 only, wherefp8is the V4.1fake_quant_fp8_ue8m0round trip andmain_projmaps3 * 5120to5120. - Draft input:
[anchor, mask, ..., mask](proposal_lengthtokens) embedded with the target's embedding table, broadcast to[B, L, 4, 5120], with an identity pre-mix. Each stage is a V4.1 block built from a draft copy of the config: one layer,compress_ratios [0], no kv, index or engram sources, 128 experts top-3. The stage output isnorm(hc_pre(h, pre_mix))after the last stage, then the targethead. - DSparkAttention:
kv = fp8(rope(kv_norm(wkv(fp8(context))), offset))is appended to the stage's cache and cut to the last 128 rows;q = rope(wq_b(fp8(q_norm(wq_a(fp8(x))))), offset + count); block KV fromxatoffset + countis concatenated after the context rows; non-causal SDPA with the learnedattn_sink, inverse RoPE on the output, the groupedwo_a(o_groupsxo_lora_rank) andwo_b, each input fake-quantized. - Stage-specific tensors: on the 2-bit pack
main_projandmain_normexist only onmtp.0, whilenorm,markov_headandconfidence_headexist only on the last stage,mtp.2. - Proposal:
VanillaMarkovblock sampling over the base logits, chained from the anchor (markov_head.embedismarkov_w1,markov_head.headismarkov_w2).confidence_head.*is dropped. - Sanitize:
mtp.N.*becomesstages.N.*; native.scalesidecars are repacked with the V4.1_pack_source_weight; the MoE is stacked with V4.1sanitize_moe_weightsat 128 experts;ffn.gate.weightis kept f32; a 2-Dattn.wo_ais reshaped to[o_groups, o_lora_rank, -1]. On the MLX 2-bit pack the Markov factors are quantized (markov_head.embed.{weight,scales,biases}); upstream casts every Markov tensor to f32, which is only meaningful for dense factors. - Target transaction: during speculation the V4.1 cache snapshots its whole state before the round and after every token, and verification advances one token at a time (compression groups, window eviction and the engram history all have token boundaries); commit restores the snapshot at the accepted length, abort restores length 0.
Current mlxcel behavior
- No V4.1 code exists yet; #2386 adds
src/models/deepseek_v41*.rsand dropsmtp.*for the text model. There is no V4 DSpark drafter either (onlysrc/models/deepseek_v4*.rs, the target). - mlxcel's DSpark support is the LFM2 drafter (#1339):
DFlashConfig::is_dspark(src/lib/mlxcel-core/src/drafter/dflash/config.rs:320),VanillaMarkovHead(src/lib/mlxcel-core/src/drafter/dflash/markov.rs:43, which already loads quantizedmarkov_w1/markov_w2through the unified loaders), and the DFlash-family burst insrc/server/batch/dflash_target.rs, whereDFlashTargetModel(:184) andDFlashDrafterFamily(:141,Dflash | DSpark | MuseAssistant | Laguna) gate which drafter a target accepts.
Required changes
src/models/deepseek_v41_dspark.rs(new, +_tests.rs):DeepseekV41DsparkDrafterimplementing the coreDraftertrait as a DFlash-kind drafter, built from the V4.1 block, attention, MoE, HyperConnection and fake-quant code that #2386 adds. Import those pieces, never copy them. Load from the target checkpoint (model_typedeepseek_v41/deepseek_v41_text) reading onlymtp.*throughload_weights_from_dir_index_filtered, or from a split directory (model_type: deepseek_v41_dspark). ReuseVanillaMarkovHead::from_weightsunder the renamed prefix, so a quantized Markov head stays quantized instead of being cast to f32.- V4.1 target (
src/models/deepseek_v41.rsfrom #2386): acapture_layer_idstap returning the HyperConnection-mean input of each requested layer, and a speculation transaction on the V4.1 cache (start(len), per-token snapshot,commit(accepted),abort()), with verification run as single-token steps. Starting a second transaction while one is active, or committing outside0..=len, is an error, not a silent reset. - Burst wiring: add
DFlashDrafterFamily::DeepseekV41DSpark, implementDFlashTargetModelfor the V4.1 model withrequired_drafter_family() = Some(DeepseekV41DSpark),first_hidden_rows() = EveryPromptRow,supports_batched() = false, and anexactness_allowsprobe like the other families. Wire the CLI (mlxcel generate --draft-model),mlxcel-server --model-draftandspeculative_benchthrough the binary-sidesrc/models/drafter_loader.rs, because the stages are binary-crate blocks. - Detection: in core
resolve_drafter_kind, adeepseek_v41ordeepseek_v41_textdirectory resolves to the DFlash kind only when the last stage'smtp.{num_nextn_predict_layers - 1}.markov_head.*tensors exist (mtp.2.*on the published packs) (tensor-presence check, thehas_qwen4_exp_mtp_tensorspattern atsrc/lib/mlxcel-core/src/drafter/mod.rs:615), and coreload_drafterrefuses it withBinaryCrateDrafter.
Acceptance criteria
-
src/models/deepseek_v41_dspark_tests.rsconfig_derives_block_and_runtime_width: the published config gives 3 stages, verify block 6, runtime block 2, mask 128799, taps[37, 38, 39]; an explicit block size overrides the runtime default. - Same file,
sanitize_maps_stages_and_drops_confidence_head: a toymtp.{0,1}.*key set maps tostages.{0,1}.*, stacks experts, reshapes 2-Dwo_ato[o_groups, o_lora_rank, -1], and dropsconfidence_head.*. - Same file,
quantized_markov_head_loads_without_cast: quantizedmarkov_head.embed/headload throughVanillaMarkovHeadand match the dequantized f32 reference within 1e-3. -
src/models/deepseek_v41_tests.rsspeculation_commit_equals_shorter_forward: on a toy config with compression and engram, starting a 4-token transaction and committingn = 0..=4leaves the cache equal to a plain forward overntokens; a nested start and an out-of-range commit both return errors. -
src/server/batch/dflash_target.rstests: the V4.1 target requiresDeepseekV41DSparkand declines an LFM2 DSpark drafter with a message naming both. - Real checkpoint, integrated:
mlxcel generate -m models/DeepSeek-V4.1-Flash-MLX-2bit --draft-model models/DeepSeek-V4.1-Flash-MLX-2bit -p "Explain the Sinkhorn algorithm briefly." -n 128 --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
mlx-community/DeepSeek-V4.1-Flash-MLX-2bit is 238.8 GB (Hub API, 2026-11-23) and needs 256 GB+ unified memory, the same host #2386 needs. The 4-bit pack is 552.9 GB.
make verify-test
cargo test --profile test-fast deepseek_v41
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
python3 scripts/ci/check_cross_repo_refs.py
Related
#2386 (blocker: V4.1 text port), #1339 (LFM2 DSpark drafter and VanillaMarkovHead), #3261 (official Speculators and OpenBMB DSpark checkpoints, Neywa-Labs/mlx-vlm#2676; independent of V4.1).
- Ngôn ngữ chính
- Rust
- Star
- 505
- Fork
- 81
- Merge trung bình
- 14 giờ 2 phút
- Pull request đã merge (30 ngày)
- 448
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của lablup/mlxcel
-
area:core priority:high status:ready type:security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:medium status:ready type:security
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:models modeltype:text priority:medium status:in-progress type:bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:models priority:low status:ready type:test
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:models modeltype:omni priority:medium status:ready type:bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của lablup/mlxcel
Issue tương tự
-
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)Có thể đã có người làm @ealwanlee đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
psmux/psmux-plugins#47 ·
-
Link Checker ReportĐang mởautomated issue report
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 76/100
ratatui/awesome-ratatui#598 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
release
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
github/gh-aw-mcpg#17603 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
C-Bug S-Needs-Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bevyengine/bevy#26718 ·
Maintainer thường phản hồi trong vòng 2 ngày