Sparse MoE FFN for DFlash-family drafters - #799
Draft
sherlockwu wants to merge 1 commit into
Draft
sherlockwu wants to merge 1 commit into
sherlockwu wants to merge 1 commit into
Conversation
sherlockwu
requested review from
FlamingoPg,
FrankLeeeee,
shuaills and
sleepcoo
as code owners
September 1, 2026 19:10
sherlockwu
marked this pull request as draft
September 1, 2026 19:33
sherlockwu
force-pushed
the
kan/pr2-dsv4-dspark
branch
from
September 1, 2026 20:35
1b5031b to
f74b2d9
Compare
sherlockwu
force-pushed
the
kan/pr3-moe-drafter
branch
2 times, most recently
from
September 1, 2026 21:45
5abf509 to
f1ceac8
Compare
sherlockwu
force-pushed
the
kan/pr2-dsv4-dspark
branch
from
September 1, 2026 21:45
f74b2d9 to
b627abd
Compare
sherlockwu
force-pushed
the
kan/pr3-moe-drafter
branch
from
September 1, 2026 21:55
f1ceac8 to
a60f1de
Compare
sherlockwu
force-pushed
the
kan/pr2-dsv4-dspark
branch
2 times, most recently
from
September 2, 2026 00:24
09ff4cb to
decc438
Compare
sherlockwu
force-pushed
the
kan/pr3-moe-drafter
branch
from
September 2, 2026 00:24
a60f1de to
3c81322
Compare
sherlockwu
force-pushed
the
kan/pr2-dsv4-dspark
branch
from
September 2, 2026 00:44
decc438 to
1b0fbee
Compare
sherlockwu
force-pushed
the
kan/pr3-moe-drafter
branch
2 times, most recently
from
September 2, 2026 06:22
f90c498 to
c99dd7c
Compare
sherlockwu
force-pushed
the
kan/pr2-dsv4-dspark
branch
from
September 2, 2026 06:22
1b0fbee to
84dd507
Compare
sherlockwu
force-pushed
the
kan/pr3-moe-drafter
branch
2 times, most recently
from
September 2, 2026 06:52
dfbf40c to
8a985a8
Compare
sherlockwu
force-pushed
the
kan/pr2-dsv4-dspark
branch
from
September 2, 2026 06:52
df01afd to
22cb116
Compare
sherlockwu
force-pushed
the
kan/pr3-moe-drafter
branch
from
September 2, 2026 17:43
8a985a8 to
a4b3769
Compare
sherlockwu
force-pushed
the
kan/pr2-dsv4-dspark
branch
from
September 2, 2026 17:43
22cb116 to
3405412
Compare
sherlockwu
force-pushed
the
kan/pr3-moe-drafter
branch
2 times, most recently
from
September 2, 2026 18:40
d3d1964 to
e7e20ed
Compare
…lation pair - specforge/modeling/draft/moe.py: DeepSeek-V4-style MoE block — sqrtsoftplus top-k gate with the aux-loss-free balancing bias (fp32 buffer, sign-controller updates from all-reduced loads), one shared expert, routed experts as stacked [E, out, in] parameters with sorted segment dispatch and an opt-in grouped-GEMM path - dflash.py: draft configs with n_routed_experts > 0 swap the dense MLP for the MoE block; gate init through _init_weights; the deferred balance update runs in the model forward, outside checkpoint regions - backend.py: checkpoint FILES keep the official per-expert expert naming while modules expose FSDP-friendly stacked parameters (unstack/stack at the state-dict boundary) - configs/deepseek-v4-flash-dspark-moe.json + example recipe: the MoE arm of the drafter ablation vs the dense deepseek-v4-flash-dspark recipe (only the draft JSON's MoE fields differ) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
sherlockwu
force-pushed
the
kan/pr3-moe-drafter
branch
from
September 2, 2026 21:14
e7e20ed to
f9a6a80
Compare
This was referenced Sep 2, 2026
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.
Stacked on #798 (retarget to
mainas the stack merges).Adds a DeepSeek-V4-style sparse MoE FFN that any DFlash-family draft config can opt into, plus a ready-made dense-vs-MoE ablation pair for DeepSeek-V4-Flash.
What's here
specforge/modeling/draft/moe.py— self-contained MoE block:MoEGate: sqrtsoftplus top-k routing with the aux-loss-free balancing bias. The bias is an fp32 buffer updated by a sign controller from all-reduced expert loads (never by gradients) and survives module-wide dtype casts.GroupedExperts: routed experts as three stacked[E, out, in]parameters — grouped-GEMM-ready, and FSDPuse_orig_paramstracks 3 view tensors instead of3*E. Loads both native stacked keys and the official per-expert naming (experts.{i}.w{1,2,3}.weight).SparseMoE: sorted-segment dispatch (one argsort → contiguous per-expert segments; a per-experttorch.whereloop scales overhead with active experts, ~2× step time once the balancer spreads load), optionaltorch._grouped_mmpath with no host syncs, one shared expert.dflash.py: a draft JSON withn_routed_experts > 0swaps the dense MLP forSparseMoE; the bare gate Parameter is initialized via_init_weights;moe_bias_update_ratecomes fromdflash_config.backend.py: checkpoint files keep the official per-expert expert naming while modules keep stacked parameters —unstack/stack_grouped_expert_state_dictconvert at the save/load boundary, so warm starts, resumes, and export bundlers are unaffected.configs/deepseek-v4-flash-dspark-moe.jsonisdeepseek-v4-flash-dspark.jsonplus the MoE fields (64 routed + 1 shared, top-6,moe_intermediate_size2048 — activated width ≈ the dense 12288);examples/.../deepseek-v4-flash-dspark-moe.yamlmirrors the dense recipe so the draft config is the A/B diff.Tests
tests/test_modeling/test_moe.py: balance-update semantics (train stashes / eval doesn't / second apply is a no-op), fp32 bias through casts, stacked↔official state-dict round trip (including wrapper-levelstack), grouped-GEMM vs sorted-loop parity in outputs/grads on CUDA, DFlash wiring (MoE vs dense selection, gate init, model-level round trip).🤖 Generated with Claude Code