feat(inkling2): train the released DSpark drafter #4839
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #4839"
general
weight: 0.35
ischencheng
What does this PR do ?
Adds DSpark draft training for Inkling-2-Small on top of the native Inkling 2 model from #4755. The release ships its drafter in
mtp.safetensors(84 tensors: 5 dense layers, block of 8, context K/V projections over 8 mixed target features, anrnn_hiddenMarkov head). This PR builds that drafter in the released layout, captures the target features from the #4755 model, and trains it withtrain_dspark.py. The consolidated export has the same 84 names and shapes plus aconfig.jsonwith themtp_config.#4751 had a version of this drafter on its own Inkling 2 model; this one is rebuilt on #4755's classes.
Changelog
models/inkling2/dspark.py(new): the drafter. Anchor slot plusmask_embedfor the 7 drafted slots, per-layer softmax mix of the target features (fuse_weight), context K/V from the mixed features with their own norms, bidirectional attention inside the block, a 1024-token window before the anchor on local layers and the full prefix on layer 2, the gatedrnn_hiddenMarkov head, logits through the frozen target LM head with the release's soft cap, and the state-dict adapter for the released names.models/inkling2/dspark_target.py(new): loads the frozen target through the recipe's EP/FSDP setup. The backend defaults to the one the Inkling 2 fine-tuning recipes use (flex attention,torch_mmexperts, HybridEP);target_attn_backend,target_expertsandtarget_dispatcheroverride it, as they do for the V4.1 target.models/inkling2/model.py:Inkling2DecoderLayergets a parameter-freepartial_input = nn.Identity()that its forward passesstate.partialthrough, andInkling2ForCausalLM.get_dspark_target_feature_modules(layer_ids)returns the modules whose first input is each feature (the same hook M3 and V4.1 implement). The layers take and returnResidualState, so without this no module sees the partial tensor. No parameters or buffers change, so state dicts, FSDP units and PP splits stay the same. A looped decoder (loop_config, Inkling 2 Mini) is rejected there, since its core layers run once per pass and have no single first input.models/inkling2/config.py:Inkling2Config.build_dspark_draftandbuild_dspark_target;mtp_configis typed asInkling2MtpConfig.speculative/dspark/registry.py:ModelOwnedDSparkTargetProviderprotocol.recipes/speculative_decoding/train_dspark.py: a config that implementsbuild_dspark_targetloads its own target on the recipe's mesh with thetarget_backend overrides,cp_size > 1is rejected for such a target (it does not run the HF SDPA path the CP hook needs), and the text config comes fromget_text_config().examples/speculative/dspark/inkling2_small_dspark.yaml(new) and the DSpark guide / Inkling 2 model page. The guide lists the checkpoint'smtp.safetensorsas adraft_weights_pathsource (#4725).tests/unit_tests/models/inkling2/test_inkling2_dspark.py(forward/backward vs the oracle, released names and shapes, a consolidated save and reload through the realCheckpointer, a warm start from a released-layoutmtp.safetensorsthroughload_dspark_draft_weights),test_inkling2_dspark_target.py(feature capture vs the native model andreference.py, backend defaults and overrides, the recipe training a step on a tiny native target, the CP and looped-decoder rejections).Feature ids: the checkpoint labels features by the layer they enter (5, 11, ..., 41, and 48 for the post-final-norm output). DSpark ids count the producing layer, so they are
[4, 10, ..., 40, 47], plus-1for the normalized embedding entering layer 0, which fills the anchor slot. Reading the anchor embedding from the target that way keeps the draft from holding its own copy of the 201k x 4608 embedding andembed_norm.Code provenance
Not applicable.
Before your PR is "Ready for review"
Pre checks:
Additional Information
Draft vs an FP64 per-block oracle written from the TokenSpeed and vLLM serving math for this drafter (CPU, FP32, TF32 off, tiny config: 3 layers, window 3, 4 slots):
| tensor | max abs err | max rel err |
|---|---|---|
| draft logits | 4.6e-7 | 2.9e-7 |
| parameter grads (all) | <= 3.0e-6 | <= 1.2e-6 |
| grad of the target features (incl. anchor embedding) | 3.2e-7 | 3.5e-7 |
Swapping in a per-row window instead of the block-anchored one gives 0.23 relative error on the logits, so the test tells the two window rules apart.
Target features on a 7-layer tiny
Inkling2ForCausalLMandInkling2ForConditionalGeneration(ids[-1, 1, 4, 5, 6], covering a global layer and a block boundary): bitwise equal to the native model's layer outputs, and within 4.8e-7 oftests/unit_tests/models/inkling2/reference.py.Released weights: the 84 tensors of
mtp.safetensorsload with no missing or unexpected keys (only the target'slm_head.weightis shared) and are bitwise equal after loading; a BF16 forward gives finite logits. Withdraft_weights_pathpointing at the real file,load_dspark_draft_weightsfills all 84 tensors of a fresh FP32 draft with the file's values and leaves the target's LM head as it was.Recipe smoke on 2x H100 (EP2 + FSDP2, AC on):
train_dspark.pywith this YAML on a tiny random Inkling 2 checkpoint in the HF layout that keeps the released 48-layer structure (hidden 256, 32 experts top-8), so the YAML's feature ids stay valid; 2-layer draft, seq 512, 64 anchors, lr 3e-4 instead of the YAML's 1e-5 so the loss moves.build_dspark_targetwith flex attention in all 48 layers andGroupedExpertsDeepEPon HybridEP, each rank holding 16 of the 32 experts. 11 spot-checked tensors (embedding, norms, router, two EP-sharded expert weights) match the written checkpoint by checksum.config.jsonwithmtp_config.Tests, CPU (x86 test container), on
b28c42eea(merged with current main4ac010479):tests/unit_tests/models/inkling2,tests/unit_tests/recipes/speculative_decoding, all 15tests/unit_tests/speculative/test_dspark_.pyfiles and the two MiniMax M3 DSpark tests: 1016 passed, 4 skipped. ruff 0.12.12 check and format on the changed files,tools/lint_no_globals.pyandtools/recipes/check_recipes.pypass; the source validation intools/docs/check_docs.pypasses (its local docs-stitch step needs the versioned docs tree, which I don't have here).Not tested: the real-size target and its NVFP4/MXFP8 dequantizing load (the feature mapping on the real checkpoint relies on #4755 matching the HF/release layer semantics, checked on the tiny model), EP above 2 and multi-node, the GPU feature values against
reference.py, padded batches, a training run started from the released draft, resume, offline cached targets and packing (the draft does not support packing; the recipe rejects it).Two things I'd like your take on: the
nn.Identitycapture point inInkling2DecoderLayer(the other option is a shared hook inHFDSparkTargetModelthat readsResidualState.partialfrom layer outputs), and reading the anchor embedding as feature-1, which makesvalidate_target_layer_idslog its SGLang warning for-1and47.Implementation and validation were AI-assisted.