[Bugfix][MiMo] Apply vision attention sinks in the window attention path#49815
Open
almogtavor wants to merge 1 commit into
Open
[Bugfix][MiMo] Apply vision attention sinks in the window attention path#49815almogtavor wants to merge 1 commit into
almogtavor wants to merge 1 commit into
Conversation
1 task
almogtavor
force-pushed
the
fix-mimo-vision-sinks
branch
2 times, most recently
from
July 25, 2026 17:24
a169435 to
0babb74
Compare
MiMoVisionAttention allocates self.sinks only for blocks that are not in fullatt_block_indexes, which are exactly the blocks that run _forward_window_attn. That path never used the parameter, so the sink weights were loaded from the checkpoint and dropped. The reference implementation adds sinks[h] to the logit of each sequence's first key. Biasing a single key only rescales that key's softmax term, so the output is corrected in closed form from the weight the kernel already gave to key 0, recovered from the softmax LSE that flash attention returns. Only queries within the window of key 0 can attend to it, so at most window_size + 1 rows per sequence are touched. Fixes vllm-project#47864 Signed-off-by: almogtavor <almogtavor@gmail.com>
almogtavor
force-pushed
the
fix-mimo-vision-sinks
branch
from
July 25, 2026 19:42
0babb74 to
bbd5d51
Compare
almogtavor
requested review from
AndreasKaratzas,
DarkLight1337 and
ywang96
as code owners
July 25, 2026 19:42
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.
Fixes #47864.
MiMoVisionAttentionallocatesself.sinksonly when the block is not infullatt_block_indexes, which is exactly the set of blocks that run_forward_window_attn. That path never read the parameter, so the sink weights were loaded from the checkpoint and dropped.XiaomiMiMo/MiMo-V2.5shipsvisual.blocks.N.attn.sinksfor exactly those blocks, 24 of its 28, and none for the full attention blocks[0, 9, 18, 27].The reference adds
sinks[h]to the logit of each sequence's first key. Biasing one key only rescales that key's softmax term, so the output is corrected in closed form from the weight the kernel already gave to key 0, recovered from the softmax LSE flash attention already returns:Only the first
window_size + 1queries of a sequence can attend to its key 0, so only those rows are gathered and rewritten. Indices are built fromcu_seqlenson device, so there is no host sync and no Python loop over sequences.Real weights. One window block (block 1) of
XiaomiMiMo/MiMo-V2.5, its ownattn.sinks, compared againstMiMoVisionAttentionfrom the repo'smodeling_mimo_v2.py, H100, bf16, 1024 tokens in 2 sequences, rotary made identity on both sides so only the attention math is compared:1.9e-03 is the bf16 noise floor. The checkpoint's sink values are small (-0.10 to 0.59), so the per block effect is under 1%. It applies to 24 of 28 blocks; I did not measure the compounded error at the tower output.
Shape coverage. Same comparison with synthetic weights and larger sinks, over sequence lengths 128 to 4096, single and multi sequence batches, GQA, and TP=2 on both ranks: 1.8e-02 to 1.0e-01 before, 2.2e-03 after.
Test.
tests/models/multimodal/test_mimo_v2_omni.pycompares_forward_window_attnagainst a dense fp32 windowed softmax with the sink on key 0, for MHA and GQA, with one sequence shorter than the window and one longer. On this branch both cases land at 2.3e-03; on main they fail at 1.2e-01 and 2.1e-01.Cost. Window attention on 4096 tokens, 16 heads, head dim 80, window 64: 0.038 ms before, 0.248 ms after. On 16384 tokens: 0.134 ms before, 0.289 ms after. The overhead is roughly constant, so it is launch bound rather than data bound, and it applies once per window block.
Two alternatives, in case a reviewer prefers one:
s_aux, as suggested in the issue, is a different operation.s_auxadds a null logit to the softmax denominator while the reference biases key 0. Measured on the synthetic setup it moves the error to 5.2e-02, slightly worse than dropping the sinks entirely.The tradeoff here is that the key 0 logit is recomputed outside the kernel, so a little work the kernel already did is repeated, and the correction depends on the LSE convention of the varlen kernel. Adding real additive bias support to the flash attention wrapper would be cleaner but is a much larger change.
On the LSE convention: this call site takes the
DEFAULT_FA_VERSION = 2path, and cascade attention already feedssoftmax_lsefrom the same function intomerge_attn_statesunder any version, so the convention is shared in tree. Checked directly on H100 anyway, against a fp32logsumexpof the masked scaled logits, max abs difference(nheads, total_q):The omni checkpoint is not public, so this is validated against the MiMo-V2.5 vision tower, whose config surface and weight names match what this file implements.