feat(dflash): add reusable hybrid KDA attention - #791
Draft
maocheng23 wants to merge 2 commits into
Draft
Conversation
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
gqa/mha/mla/kdalayouts throughdflash_config.attention_modes;This PR is intentionally a draft. The implementation, correctness, FSDP, and performance gates pass, but a freshly trained KDA recipe has not yet improved the frozen end-to-end acceptance baseline. The experimental recipe is therefore not promoted as a new default.
Design
KDA and KV/latent attention share a small decoder-facing base class. GQA/MHA/MLA keep their shared cache, mask, and backend machinery, while KDA owns its recurrent projections, causal depthwise convolutions, gated RMSNorm, and optimized/reference dispatch.
Each block-parallel proposal is an independent KDA sequence, so recurrent and convolution state reset at proposal boundaries. Hybrid layouts retain at least one consistent GQA, MHA, or MLA layer for target-context injection.
The optimized KDA backend is optional and imported lazily. Non-KDA installations and existing uniform
attention_modeconfigurations remain backward-compatible.Correctness
Coverage includes:
Exact-stack result: 1,103 passed, 13 skipped, 1 xfailed, 685 subtests.
Optimized/reference maximum absolute differences on H200:
0.000244140625;7.34e-8.Performance
For a five-layer Qwen3-4B-sized hybrid draft, the selected 2KDA/3GQA layout was 1.031x faster, used 6.10% fewer attention parameters, and used 5.04% less incremental peak memory than the matched GQA draft in the isolated forward/backward benchmark.
The frozen Qwen3-4B speculative-generation harness also verified identical deterministic target outputs. KDA candidates were consistently faster, but the clean training runs did not clear the acceptance gate:
A diagnostic checkpoint composition did produce a +7.83% acceptance result with matching target outputs, which motivates further training work, but it is not presented as a clean trained result.
Serving boundary
SpecForge forward, training, save/reload, export, and
spec_generatesupport KDA. Production speculative serving still requires a paired serving-runtime change for recurrent KDA state, so the export normalizer rejects KDA/MLA serving layouts today.Stack
Built on the MLA attention scaffold merged in #758.