Skip to content

feat(dflash): converge DFlash spec-decode stack → dev (supersedes #140) - #143

Merged
drunkcoding merged 64 commits into
devfrom
feat/dflash-tracks-abcd
Aug 10, 2026
Merged

feat(dflash): converge DFlash spec-decode stack → dev (supersedes #140)#143
drunkcoding merged 64 commits into
devfrom
feat/dflash-tracks-abcd

Conversation

@drunkcoding

Copy link
Copy Markdown
Contributor

What

Converges the DFlash speculative-decoding stack into dev. This is the up-to-date successor of #140 (feat/dflash-spec-decode) and supersedes itfeat/dflash-tracks-abcd fully contains #140's tree plus 12 newer commits (offloaded Qwen3.5 spec-decode + route-ahead, serving integration, sampled/batched decoding, GLM perf-model, prefetch null-deref fix, ruff/clang-format convergence).

origin/dev was merged in and the one conflict resolved (see below), so this is a clean merge.

Conflict resolution (moe_infinity/runtime/model_offload.py)

Only get_topology()'s routed-expert detector conflicted — two parallel implementations:

Resolved by adopting _is_routed_expert_key (drops the now-dead closure). Rationale: it is the intended detector for the offload/dflash path and, by design, keeps the MTP-layer experts offloaded (the closure's parse_expert_id dropped them via the layer_id ≥ num_layers guard).

Known limitation — tracked in #142

The adopted regex matches .mlp.experts.<id>. but not Mixtral's .block_sparse_moe.experts.<id>. naming (see _remap_v5_batched_experts). Mixtral routed experts may therefore be misclassified as non-routed. Documented inline as NOTE(#142) and tracked in #142 (proposed fix: widen regex to \.(mlp|block_sparse_moe)\.experts\.\d+\. + Mixtral smoke test).

Verification

  • model_offload.py: no conflict markers, py_compile OK, LSP clean.
  • qwen.py, gpt_oss.py (auto-merged) py_compile OK.

Notes

drunkcoding added 30 commits July 30, 2026 19:31
Add moe_infinity/spec_decode with DFlashSpeculator, DFlash config reader, and target/draft pairing validation for z-lab GPT-OSS DFlash drafters.
…nding (bit-exact vs python; dispatcher H2D integration deferred)
… patch, GLM use_native_engine=False, e_score_correction_bias device guard)
…ense offset) — fixes native dispatch SIGSEGV; tiny GLM now generates end-to-end
…ess-by-construction; validated on tiny model)
…ep stats, expert-fetch hook) — parity preserved
… on non-paged HF path; +tokenizer save +gated test)
…quant, gated) — Option A==B parity on tiny FP8 GLM; completes T15/T16
…de roofline (scaffold, cross-plan option b)
drunkcoding added 25 commits August 5, 2026 17:58
…reconstructible sliding-window KV rollback
GPT-OSS is excluded from the C++ expert dispatcher and runs a resident
Python expert loop in SyncGptOssMLP.forward, but the loader never
materialized the _PackedExperts params: expert weights stayed zeros,
biases NaN, attention sinks and router garbage, producing incoherent
output. Add _load_resident_gpt_oss to load the real MXFP4 blocks/scales
(uint8, output-major [E,N,K//2]/[E,N,K//32]), biases, router, and
self_attn.sinks into the live params and drop them from name_id_map.

Fix _expert_forward_mxfp4 to feed packed weights without the erroneous
.t() (checkpoint is already output-major; verified rel-err 0.0 vs
reference dequant on gate_up and down proj).

Real 120B: base output now coherent ('The capital of France is Paris.');
DFlash agreement 0.95->1.00, mean acceptance 1.0->6.57, ~21x decode
speedup. 103 dflash tests pass.
Per-token union of the verify block's routed experts, pinned/prefetched via the dispatch_local seam during DFlash verify. Adds union/coverage/waste pure helpers (_prefetch_route), a contextvars route-ahead context (_route_ahead_ctx), opt-in coverage/waste metrics (_route_ahead_stats), an explicit-set mode on ExpertPrefetcher.speculative_prefetch (legacy path byte-identical), and the executor observe seam. Non-spec decode unchanged.
Distribution-preserving block-diffusion accept rule for temperature/top-k/top-p, keeping greedy byte-identical.
Adds a spec branch to ContinuousBatchingEngine.step() for greedy batch==1 sequences: paged-KV rollback primitive (kv_cache.truncate_tokens), per-seq cached-vs-emitted accounting (SpecDecodeState), verify-commit orchestration (spec_verify.apply_verify_step), and variable-commit scheduler accounting (committed_counts, default byte-identical). Spec-off path unchanged.
… hooks, drafter-driven contract

Generalizes the native draft->verify->rollback loop to batch>1 (batched build_block/acceptance/committed_tokens with per-seq accept + rollback), wires the sampled accept + route-ahead context/stats into generate(), and makes validate_pairing drafter-driven (reads block_size/target_layer_ids from the drafter config instead of hardcoding the gpt-oss-120b contract) so any z-lab DFlash pair loads.
MOE_DFLASH_GPU-gated: gpt-oss-20b native DFlash == plain greedy (token-identical), and serving-path DFlash == sync DFlash.
…ang-format)

Pre-existing formatting drift on the feat/dflash-spec-decode base that CI enforces via 'pre-commit run --all-files' (ruff --fix, ruff-format, clang-format). Mechanical only; no logic changes.
Add null checks in archer_prefetch_handle ReleaseTensor for the
first-call (last_node_ null) and missing-node cases to prevent a native
segfault during offloaded expert release.
Keep the Qwen3.5-MoE text backbone (incl. GatedDeltaNet linear-attention
layers and shared expert) resident on GPU while offloading only the
routed experts, and generalize routed-expert key matching via
_is_routed_expert_key.
Make DFlash speculative decoding lossless/correct on offloaded,
executor-backed Qwen3.5 (rollback via clone instead of in-place copy_;
@torch.no_grad over @torch.inference_mode so worker-thread expert
index_add_ works), add resident route-ahead observation for the
non-executor path, and harden native-engine plumbing in MoE.generate.
Includes hybrid-rollback and route-ahead wiring tests.
Resolve model_offload.py get_topology conflict: adopt _is_routed_expert_key (regex) as the routed-expert detector, dropping the parse_expert_id-based is_routed_expert closure from #138. Keeps MTP-layer experts offloaded (dflash intent) but narrows detection to '.mlp.experts.<id>.'; Mixtral '.block_sparse_moe.experts.' is no longer matched -- tracked in #142.
@drunkcoding

Copy link
Copy Markdown
Contributor Author

Merging to converge the DFlash stack into dev. The unit-tests (3.10/3.12) failure is a pre-existing GLM transformers-compat gap (GlmMoeDsaMoE.route_tokens_to_experts), independent of this branch's model_offload.py conflict resolution — tracked in #144. Mixtral routed-expert detector caveat tracked in #142.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant