Add config-selectable MLA draft attention - #758
Open
maocheng23 wants to merge 2 commits into
Open
Conversation
Select Multi-head Latent Attention with dflash_config.attention_mode: "mla" while keeping the DFlashDraftModel, DominoDraftModel, or DSparkDraftModel architecture, target-context injection, per-layer full/sliding masks, objectives, and eager/SDPA/FlexAttention backend selection. Omitting the option preserves the current GQA path. The mode is wired the same way gqa/mha already are: family-local, as a sibling projection class behind a shared attention scaffold. - Qwen3DFlashAttentionBase owns everything the modes must agree on (KV-cache updates, flex/eager/sdpa backend dispatch, fully-masked-query zeroing, output projection); Qwen3DFlashAttention (gqa/mha) and Qwen3DFlashMLAAttention only build projections and rotated q/k/v. - attention_mode has a single source of truth (resolve_dflash_attention_mode + _DFLASH_ATTENTION_CLASSES); DSpark imports it instead of re-declaring the mode set. - The rotary embedding stays model-level: DFlashDraftModel builds it with the mode-appropriate dim (qk_rope_head_dim under MLA) and every mode consumes the same position_embeddings pipeline. - MLA dimension validation runs once at model init, next to the existing resolve_dflash_attention_layout boundary. - Structural MLA dims use the standard top-level HF fields; behavioral knobs (mla_rope_interleaved, mla_use_output_gate) live in dflash_config only, with rope_interleave as the standard-config default. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
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 pathMLA is wired exactly the way
gqa/mhaalready are — family-local, selected per mode inside the shared decoder layer — so the repo keeps one convention for attention parameterization across draft families.Structure
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);Qwen3DFlashAttention(gqa/mha) andQwen3DFlashMLAAttentionimplement only projection construction and rotated q/k/vattention_modehas a single source of truth (resolve_dflash_attention_mode+_DFLASH_ATTENTION_CLASSES); DSpark imports it instead of re-declaring the mode setDFlashDraftModelbuilds it with the mode-appropriate dim (qk_rope_head_dimunder MLA) and all modes consume the sameposition_embeddingspipelineresolve_dflash_attention_layoutboundarymla_rope_interleaved,mla_use_output_gate) live indflash_configonly, defaulting the rotation convention from the standardrope_interleavefieldDocs 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.Validation
tests/test_modeling/test_dflash_mla.py: 10 passed, 5 subtests passed (CPU; the CUDA FlexAttention case is skipped without a GPU) — includes eager↔SDPA parity with grads, asymmetric-K/V-dim caching, an MLAspec_generatedecode smoke test, and a DSpark MLA case that exercises the head-count-policy bypasstests/test_modeling: 56 passed, 4 skipped, 20 subtests passed — existing GQA eager/sliding/flex-backend and Domino/DSpark tests confirm the scaffold extraction is behavior-preservingtests/test_runtime/test_model_loading.py+test_disaggregated_model_loading.py: 17 passedcompile_friendly_flex_attentiondispatch🤖 Generated with Claude Code