Enable compact sliding-window attention for Gemma 3 and Gemma 4 variants - #496
Draft
ani300 wants to merge 5 commits into
Draft
Enable compact sliding-window attention for Gemma 3 and Gemma 4 variants#496ani300 wants to merge 5 commits into
ani300 wants to merge 5 commits into
Conversation
4 tasks
ani300
force-pushed
the
gemma4-swa-op
branch
from
September 9, 2026 17:39
dccdf96 to
744dc53
Compare
Route supported causal sliding layers through the fused torch-spyre kernel. Use bounded anchored KV caches and a fixed-shape runtime decode mask so prefill and decode stay on SWA while all decode positions reuse one compiled graph. Signed-off-by: Antoni Viros i Martin <aviros@ibm.com>
Signed-off-by: Antoni Viros i Martin <aviros@ibm.com>
Signed-off-by: Antoni Viros i Martin <aviros@ibm.com>
ani300
force-pushed
the
gemma4-swa-op
branch
from
September 10, 2026 14:47
744dc53 to
f64452e
Compare
Signed-off-by: Antoni Viros i Martin <aviros@ibm.com>
Signed-off-by: Antoni Viros i Martin <aviros@ibm.com>
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
spyre::sliding_window_attentionwindow + 64anchored bufferswindow AND (causal OR vision-blockwise)The SWA mode remains explicitly disableable for debugging. The existing Gemma 4 multimodal adapter still does not support the MoE VLM checkpoint; the MoE change here applies to the causal-LM adapter.
Dependency
Draft until torch-spyre/torch-spyre#4423 lands. That follow-up to merged #3405 provides the mandatory runtime-mask API, generic non-causal access mode, and kernel/compiler fixes exposed by Gemma 4 D=256 decode.
Compilation behavior
The removed API supplied Python
cache_seqlen,buffer_origin, andvalid_startvalues and could compile up to 64 decode-position variants per block. Position, unwritten rows, window placement, padding, and VLM blockwise regions now travel only in tensor data. Runtime-mask tests observe one graph per fixed shape/access mode; prefill and decode therefore retain the expected two shape variants per block.is_causalis static per prepared model. Text-only Gemma 3/4 and Gemma 4 MoE use the narrow causal square-prefill plan. Gemma 4 VLM uses the generic plan because its sliding mask contains future same-image pairs. Decode still scans only the compact 1088-row allocation.Correctness
The branch is based on upstream
mainat1b3c1a6; all commits are DCO-signed and GPG-signed.Performance
Local causal Gemma-like shape from the preceding revision: B=1, Hq=4, Hkv=2, D=256, W=1024.
The compact 1088-column mask build plus transfer measured 146.2 us median, paid once per decode step and shared across all sliding layers. Non-causal VLM prefill intentionally scans the full physical cache because future vision-block endpoints are runtime mask data.