Repository navigation
Conversation
DeepSeek-V4.1 checkpoints bundle a three-stage DSpark head under `mtp.0..2` and no mlxcel path could run it: `resolve_drafter_kind` sent the family through the generic `num_nextn_predict_layers` rule to `Mtp`, core `load_drafter` had no builder for the V4.1 block stages, and the model-owned V4.1 cache could not rewind a verify block to its accepted prefix. Add `src/models/deepseek_v41_dspark.rs` (+ tests), a binary-side DFlash-kind drafter that imports the V4.1 block, attention, MoE, HyperConnection and fake-quant code instead of copying it. Add the `capture_layer_ids` hidden tap and a per-token speculation transaction (`start` / snapshot / `commit` / `abort`) on the V4.1 cache, with verification replayed as single-token steps. Resolve the family to `DrafterKind::Dflash` from the last stage's `markov_head.*` tensors above the generic MTP rule, refuse it in core with `BinaryCrateDrafter`, and wire the server family, `DFlashTargetModel` for the text and VL models, the drafter loader, block-size peeking and the offline/server drive paths. The integrated real-checkpoint check is deferred: it needs the 238.8 GB `mlx-community/DeepSeek-V4.1-Flash-MLX-2bit` pack on a 256 GB+ unified-memory host, while this work was developed and unit-tested on a 128 GB M1 Ultra. The PR body lists the unit tests that cover every other acceptance criterion and the pre-existing, unrelated fake-quant test failure observed on this host.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every DeepSeek-V4.1 checkpoint ships a three-stage DSpark drafter under
mtp.0tomtp.2. This PR makes the same checkpoint usable as--draft-model/--model-draft, so DFlash speculative decoding runs against the V4.1 target.src/models/deepseek_v41_dspark.rs(plus_tests.rs) implements theDraftertrait as a DFlash-kind drafter. It imports the V4.1 decoder pieces (V41Moe,V41Rope,fake_quant_fp8_ue8m0, the HyperConnections,hc_collapse) rather than copying them, canonicalizesmtp.N.*ontostages.N.*, repacks native scale sidecars, stacks the MoE experts, splits the flattened groupedwo_ainto[o_groups, o_lora_rank, -1], drops the unused confidence head, and keeps a quantized Markov head packed by loading it throughVanillaMarkovHead::from_weights(with themarkov_head.embed/markov_head.headrename).src/models/deepseek_v41.rsgains thecapture_layer_idstap (the HyperConnection-mean input, taken after the engram write) and a speculation transaction on the model-owned V4.1 cache: per-token snapshots,commit(accepted),abort(), and errors for a nested start or an out-of-range commit. Verification replays each row as one classic decode step, so temperature-0 output is byte-identical by construction.deepseek_v41/deepseek_v41_textdirectory toDrafterKind::Dflashwhen the last stage'smtp.{n-1}.markov_head.*tensors exist. That arm sits above the genericnum_nextn_predict_layersrule from feat: Load bundled Qwen 3.5 MTP drafters and detect native MTP heads #2400, and coreload_drafterrefuses the family withBinaryCrateDrafter.DFlashDrafterFamily::DeepseekV41DSpark,DFlashTargetModelfor the text and VL models (EveryPromptRow,supports_batched() = false, exactness allowed at every width), the binary-sidedrafter_loader, block-size peeking (so the default is the runtimemin(2, block_size)), and the offlinemlxcel generate --draft-modeland server--model-draftpaths.Validation
Unit tests run on this host:
deepseek_v41_dspark_tests::config_derives_block_and_runtime_width(3 stages, verify width 6, runtime width 2, mask 128799, taps[37, 38, 39], explicit runtime width wins).deepseek_v41_dspark_tests::sanitize_maps_stages_and_drops_confidence_head(stage rename, expert stacking, groupedwo_a, f32 router, confidence head dropped).deepseek_v41_dspark_tests::quantized_markov_head_loads_without_cast(packed factors stay packed and match the dense reference within 1e-3).deepseek_v41_dspark_tests::a_v41_checkpoint_with_markov_tensors_resolves_to_dflash_before_generic_mtp(the ordering requirement: DFlash, not Mtp, and core refuses withBinaryCrateDrafter).deepseek_v41_dspark_tests::without_markov_tensors_the_generic_mtp_rule_still_captures_a_v41_declaration(the control that makes the ordering meaningful).deepseek_v41_tests::speculation_commit_equals_shorter_forward(committingn = 0..=4of a 4-token transaction equals a plain forward overntokens, with compression and engram state).deepseek_v41_tests::speculation_rejects_a_nested_start_and_an_out_of_range_commit.dflash_target::a_v41_target_requires_its_bundled_dspark_and_declines_lfm2.Also green:
cargo fmt --check;cargo clippy -p mlxcel-core --lib --tests -- -D warnings;cargo clippy -p mlxcel --lib --tests --bins -- -D warnings;check_env_var_docs.py,check_cross_repo_refs.py,check_kernel_dtype_keys.py,check_crate_versions.py,check_technical_reports_layout.py.DEFERRED: the integrated real-checkpoint acceptance criterion (non-zero acceptance rate and byte-identical temperature-0 output for
mlxcel generate -m DeepSeek-V4.1-Flash-MLX-2bit --draft-model <same>, and the same pairing throughmlxcel-server --model-draft) needsmlx-community/DeepSeek-V4.1-Flash-MLX-2bit(238.8 GB) on a 256 GB or larger unified-memory host. This work was developed and unit-tested on a 128 GB M1 Ultra, which cannot load that checkpoint, so the end-to-end check is deferred to a 256 GB+ host.Known pre-existing failure, unrelated to this PR:
deepseek_v41_fakequant_tests::fp4_e4m3_scale_ties_round_to_the_even_grid_pointfails on this host when run alone. The test anddeepseek_v41_fakequant.rsare byte-identical tomain(git diff mainis empty for both), and the failure is inside the existing e4m3 block-scale path, not in any file this PR touches.Closes #3262