Apply local sliding-window mask in StaticAttentionIOManager single-chunk prefill (#21384)#21384
Open
YIWENX14 wants to merge 1 commit into
Open
Apply local sliding-window mask in StaticAttentionIOManager single-chunk prefill (#21384)#21384YIWENX14 wants to merge 1 commit into
YIWENX14 wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21384
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 1fb1945 with merge base fa4508e ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Contributor
|
@YIWENX14 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113574455. |
Contributor
Author
|
@pytorchbot label "release notes: none" |
billmguo
approved these changes
Jul 24, 2026
…unk prefill (pytorch#21384) Summary: `StaticAttentionIOManager.prefill` applied a full-causal input mask to every layer. For local (sliding-window) attention layers, the window is normally realized via KV-cache eviction across prefill chunks. But the numeric-comparison harness prefills the whole prompt in a single chunk, so the cache-eviction window is never exercised and local layers attend to the entire causal history instead of their `cache_len`-sized window. This diverged from the rlformers reference (which applies the correct local window via BlockDiagonalCausalMask) and made local-global (LGA) checkpoints look badly degraded in numeric SNR comparisons, while global-only checkpoints were unaffected. Fix: for local layers (`0 < cache_len < input_len`), also mask keys older than the window by adding `tril(diagonal=-cache_len)`. No-op for global layers (`cache_len >= input_len`) and on-device chunked prefill (`input_len <= cache_len`); skip layers (`cache_len == 0`) are excluded. Input mask, input_len=5, local window (cache_len)=2: Before (full causal, applied to ALL layers): ``` j=0 1 2 3 4 i=0 0 -inf -inf -inf -inf i=1 0 0 -inf -inf -inf i=2 0 0 0 -inf -inf i=3 0 0 0 0 -inf i=4 0 0 0 0 0 <- attends to all of j=0..4 ``` After (local layer, window=2): ``` j=0 1 2 3 4 i=0 0 -inf -inf -inf -inf i=1 0 0 -inf -inf -inf i=2 -inf 0 0 -inf -inf i=3 -inf -inf 0 0 -inf i=4 -inf -inf -inf 0 0 <- attends to j=3,4 only (window=2) ``` Reviewed By: billmguo Differential Revision: D113574455
YIWENX14
force-pushed
the
export-D113574455
branch
from
July 27, 2026 07:26
44e184a to
1fb1945
Compare
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:
StaticAttentionIOManager.prefillapplied a full-causal input mask to everylayer. For local (sliding-window) attention layers, the window is normally
realized via KV-cache eviction across prefill chunks. But the numeric-comparison
harness prefills the whole prompt in a single chunk, so the cache-eviction
window is never exercised and local layers attend to the entire causal history
instead of their
cache_len-sized window. This diverged from the rlformersreference (which applies the correct local window via BlockDiagonalCausalMask)
and made local-global (LGA) checkpoints look badly degraded in numeric SNR
comparisons, while global-only checkpoints were unaffected.
Fix: for local layers (
0 < cache_len < input_len), also mask keys older thanthe window by adding
tril(diagonal=-cache_len). No-op for global layers(
cache_len >= input_len) and on-device chunked prefill (input_len <= cache_len); skip layers (cache_len == 0) are excluded.Input mask, input_len=5, local window (cache_len)=2:
Before (full causal, applied to ALL layers):
After (local layer, window=2):
Reviewed By: billmguo
Differential Revision: D113574455