Skip to main content

Module dflash

Module dflash 

Source
Expand description

DFlash block-diffusion drafter (DFLASH-BRINGUP-PLAN.md, 2026-07-13).

5-layer qwen3-class mini-transformer that drafts a 16-token block in ONE non-causal forward, conditioned on the TARGET’s hidden states at 6 tapped layers (concatenated through fc + hidden_norm). No embed / lm_head of its own — the round reuses the target’s. Reference: z-lab/dflash dflash/model.py (semantics frozen in the plan doc); oracle: tools/dflash_oracle.py -> /data/cache/dflash-oracle.npz.

FIRST LIGHT = f32-resident weights + fresh full-context forward (no draft KV cache) — correctness vs the oracle, then the cache/quant/window arms land measurement-gated.

Structs§

ConfidenceHead
AcceptRatePredictor: raw linear proj over [hidden ; markov_prev_embedding(rank)] (with_markov=true on the q38 arm-a export) — output is the PRE-sigmoid scalar.
Dflash2Conv
One GroupedDynamicCausalConv module (reference model.py): a causal 2-tap depthwise conv over the BLOCK rows (block-local — row 0 zero-pads its missing predecessor; stateless across rounds), with per-position dynamic per-group coefficients projected from the module INPUT. prepare convolves the sublayer input with base_kernel[0] + dyn half 0; finish convolves the sublayer OUTPUT with base_kernel[1] + dyn half 1 (both dyn halves come from the SAME projection of the pre-conv input).
Dflash2Head
DflashCfg
DflashDraft
DflashKv
Draft KV cache (round-cost fix, 2026-07-13): per-layer normed+roped ctx K and raw ctx V, append-only in committed order. Block K/V land TRANSIENTLY at [len..len+b] each round (never committed — the reference crops them identically). Kills the per-round full-ctx projection recompute (first light was O(ctx)/round -> 7 tok/s).
DflashLayer
DsparkSpecSession
MarkovHead

Enums§

DsparkHarvest
Draft-row harvest convention for DFlash-family block drafters (darklanes research/deepseek-flash-20260818/DSPARK-POSTMORTEM-20260820.md).
DsparkVtPolicy
Verify-window policy for the dspark round (H4, DSPARK-POSTMORTEM-20260820.md §3).

Functions§

dflash2_walk_greedy
Greedy selector walk (reference CandidateSelector.select at T=0): per draft slot p, score(k) = unary[p,k] + <pred_codebook[prev] .* hidden_proj_row[p], succ_codebook[cand[p,k]]>, argmax over the top-k candidate set; the CHOSEN candidate seeds the next slot (sequential — the chain is the semantics, not an optimization). Host math (~ndkrank fused ops per round) over host-resident bf16 codebooks; ties break to the LOWEST k (torch argmax convention). Pure so the selector semantics are CPU-gateable.
dflash2_walk_sampled
Sampled selector walk (reference CandidateSelector.select, temperature>0 arm): per draft slot the pair scores over the top-k candidate set become a softmax at temp (temperature ONLY — the reference passes no top-k/top-p here), one uniform draws the candidate (fixed-order CDF walk), and the CHOSEN candidate seeds the next slot exactly like the greedy chain. Returns (path, q_chosen[nd], q_rows[ndtop_k]) — q_rows are the recorded per-slot candidate probabilities (the residual’s scatter_add_ input), and q_chosen[j] == q_rows[jtop_k + chosen_j] is the accept-test q. Pure (uniforms injected) so the T->0 limit, the chain conditioning, and the recorded-q contract are CPU-gateable.
dspark_accept_prefix
Accepted-prefix length of a round’s candidates against the trunk’s verify argmaxes: cand[0] = the round anchor (already decided), cand[1..] = the drafts; vam[j] = the trunk’s argmax prediction for position anchor+j+1. Returns m = number of accepted drafts (cand[1..=m] committed, vam[m] becomes the next anchor). Pure so the harvest-alignment fixture can exercise it CPU-side.
dspark_confidence_vt
H4 window sizing (the sglang-planner/vLLM-#47808 mechanism, thresholded): raws[k] = the accept-rate head’s PRE-sigmoid score for draft slot k+1; survival S_k = prod_{j<=k} sigmoid(raws[j]); the window keeps leading slots while S_k >= tau. Returns vt = 1 (anchor) + kept drafts, clamped to [2, vt_cap]: the draft forward is already paid, so at least one draft rides every verify — one extra verify row costs less than a guaranteed empty round. Pure, so the policy’s knee is testable CPU-side like dspark_accept_prefix.
dspark_slot_confidence_vt
Owner-directive arm (2026-08-20, “take only high confidence offers”): keep the longest draft PREFIX whose EVERY slot clears tau on its own sigmoid — truncate at the first sub-threshold slot, so the low-confidence tail (B2 measured 0.2–0.5 slot rates at depth) never enters verify. Prefix truncation is forced by the accept rule anyway (dspark_accept_prefix stops at the first miss — a kept slot after a dropped one could never commit); the policy fork vs dspark_confidence_vt is only the stopping statistic (per-slot marginal vs cumulative survival). Same floor/cap contract.
dspark_strategy_census
Checkpoint training-strategy census over the raw config.json text (the loader’s minimal-extractor idiom — no json dep in-tree). TRUE iff the export declares the DSPARK strategy: architectures naming a DSpark model class (Qwen3DSparkModel, the SpecForge OnlineDSparkModel export form) or dflash_config.projector_type == "dspark". z-lab / OnlineDFlashModel mask-fill exports carry neither signal. Pure, so the census is testable against config fragments without files.
rejection_accept_len
Rejection-sampling prefix walk: accept draft j while u_j * q_j < p_j (strict, f64 — byte-identical to the frspec accept test). p/q are the FILTERED target/proposal probabilities of the drafted tokens; u the per-slot uniforms. Pure so the composition gate can pin the rule on CPU.