Repository navigation
[5/6] feat(attention): sparse attention and SWA interfaces - #1029
Open
maocheng23 wants to merge 1 commit into
Open
maocheng23 wants to merge 1 commit into
maocheng23 wants to merge 1 commit into
Conversation
maocheng23
requested review from
FlamingoPg,
FrankLeeeee,
shuaills and
sleepcoo
as code owners
October 27, 2026 20:43
This was referenced Oct 27, 2026
Split from #1023 (originally 0e361e2). Interface-only; nothing executable yet: - attention/selection.py: IndexedSelection (token/block indices per KV source), SlidingWindowSelection and their union SparseSelection - attention/backends/sparse.py: typed SparseAttentionBackend protocol and SparseAttentionResult (values + per-head validity) - AttentionOutput.auxiliary_losses / AttentionAuxiliaryLoss for indexer or router objectives - AttentionConfig reserves the qsa/dsa kinds; build_attention raises NotImplementedError for them Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
maocheng23
force-pushed
the
maocheng/pr1023-4-visibility
branch
from
October 27, 2026 20:45
9c5967f to
4b48be0
Compare
maocheng23
force-pushed
the
maocheng/pr1023-5-sparse-interfaces
branch
from
October 27, 2026 20:45
a935f93 to
282a4b5
Compare
This branch has not been deployed
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.
Motivation
Interfaces for sparse attention, carried over from #1023 (author's commit
0e361e24). Nothing is executable yet. They define how sparse selections, KV sources and auxiliary objectives flow, before any DSA/QSA implementation lands.Modifications
attention/selection.py:IndexedSelectionholds token or block indices per named KV source.SlidingWindowSelectiondescribes a local window.SparseSelectionis their union, intersected with global visibility.attention/backends/sparse.py: the typedSparseAttentionBackendprotocol andSparseAttentionResult(values plus per-head validity).AttentionOutput.auxiliary_losses/AttentionAuxiliaryLoss: named, unweighted scalars, with the graph retained.AttentionConfigreserves theqsaanddsakinds;build_attentionraisesNotImplementedErrorfor them.Note: #1023's description says QSA/DSA are out of scope, but its commits 2–3 add them. They are split into this PR and the next one.
Accuracy Test
test_sparse_contract.py(from #1023).tests/test_modelingon CPU: 196 tests, 27 skipped. The only errors are the 4sglang/yunchangimport errors described in #1025.Stack
This is part of a split of #1023 (by @jiapingW) into reviewable layers. Each PR targets the branch of the previous one, and only its own commits show in the diff.
The code is @jiapingW's from #1023 (commits are authored by them). The split adds a parity test, legacy import shims, and two fixes in the visibility PR, each noted in the PR it belongs to.
🤖 Generated with Claude Code