Add config-selectable MLA draft attention - #758
Open
maocheng23 wants to merge 2 commits into
Open
Conversation
maocheng23
force-pushed
the
agent/general-mla-draft-attention
branch
from
August 21, 2026 01:02
62e64fa to
4b72534
Compare
maocheng23
marked this pull request as ready for review
August 21, 2026 07:11
maocheng23
requested review from
FlamingoPg,
FrankLeeeee,
shuaills and
sleepcoo
as code owners
August 21, 2026 07:11
Split Qwen3DFlashAttention into Qwen3DFlashAttentionBase (KV-cache updates, eager/sdpa/flex backend dispatch, fully-masked-query zeroing, output projection) and a projection-only subclass. Pure code motion: state-dict keys, construction signature, and forward behavior are unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dflash_config.attention_mode: "mla" swaps only the attention projections inside the shared DFlash-family decoder layer; gqa (default) and mha keep the existing class. The MLA subclass implements the standard DeepSeek parameterization: optional low-rank Q, shared compressed KV latent, partial RoPE with the convention taken from the standard rope_interleave field, and YaRN mscale_all_dim logit scaling. Structural dims use the standard top-level HF fields; validation runs once at model init and CPU-side in apply_dflash_overrides. attention_mode 'mha' now requires equal query/KV head counts everywhere (previously only DSpark enforced it). The export gate rejects MLA since SGLang serves only the GQA/MHA draft layout. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
maocheng23
force-pushed
the
agent/general-mla-draft-attention
branch
from
August 25, 2026 03:09
c83ee51 to
6b9019f
Compare
Collaborator
Author
|
Force-pushed a rework (also rebased on current main, no conflicts):
|
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
dflash_config.attention_mode: "mla"keeps the existingDFlashDraftModel,DominoDraftModel, orDSparkDraftModelarchitecture and swaps only the attention projections; omitting the option preserves the current GQA pathrope_interleavefield, and DeepSeek YaRNmscale_all_dimlogit scalingMLA is wired exactly the way
gqa/mhaalready are — family-local, selected per mode inside the shared decoder layer — and every MLA parameter is a standard top-level HF config field: the mode introduces no new behavioral knobs.Structure (two commits)
refactor(dflash): extract shared attention scaffold— pure code motion, no behavior change:Qwen3DFlashAttentionBaseowns everything the modes must agree on (KV-cache updates, flex/eager/sdpa backend dispatch including theSPECFORGE_FLEX_ATTENTION_BACKENDoverride, fully-masked-query zeroing, output projection);Qwen3DFlashAttentionkeeps its name, constructor, and state-dict keys and implements only_init_projections/_compute_qkv. The subclass contract (scaling,num_key_value_groups,o_proj) is documented and asserted at init.Add config-selectable MLA draft attention— additive: this commit does not touch the scaffold or the GQA class again (its only deletions indflash.pyare the decoder-layer class lookup and the model-level rotary dim).Details:
attention_modehas a single source of truth (resolve_dflash_attention_mode+_DFLASH_ATTENTION_CLASSES); DSpark imports it instead of re-declaring the mode set, and"mha"now enforces equal query/KV head counts for every family (previously only DSpark checked this)DFlashDraftModelbuilds it with the mode-appropriate dim (qk_rope_head_dimunder MLA) and all modes consume the sameposition_embeddingspipelineresolve_dflash_attention_layoutboundary, and CPU-side inapply_dflash_overridesbefore GPU allocationDocs note the serving boundary explicitly: MLA is a training-side mode (train,
spec_generate, export--to hf); SGLang serving of DFlash-family drafts currently implements the GQA/MHA layout only, so the export gate rejects MLA.Validation
tests/test_modelingsuite unchanged (46 passed, 4 skipped, 15 subtests) — the scaffold extraction is behavior-preservingtests/test_modeling63 passed, 5 skipped, 24 subtests —test_dflash_mla.pycovers eager↔SDPA parity with grads, hand-computed RoPE reference values for both conventions, asymmetric-K/V-dim caching, an MLAspec_generatedecode smoke test, the DSpark MLA head-count-policy bypass, and MHA head-count enforcementtests/test_runtime/test_model_loading.py+test_disaggregated_model_loading.py+tests/test_scripts/test_gate_orchestration.py: 27 passed, 8 subtestscompile_friendly_flex_attentiondispatch🤖 Generated with Claude Code