feat(backend): sliding-window PagedAttention #116
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/sliding-window-attention"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
backend.Ops.PagedAttentiongains awindowargument for sliding-window attention.window > 0, the token at position p attends only to positions p-window+1 through p. This is the masking used by OLMo 3'ssliding_attentionlayers (window 4096 on three of every four layers) and by Mistral 7B v0.1 (window on every layer). It matches transformers' sliding-window causal mask.window == 0keeps today's unlimited causal attention.Every existing caller (
mistral,mistral4,nemotronh) passes 0, so behavior is unchanged until a model asks for a window;config.Model.SlidingWindowFor(#115) supplies the per-layer value.What changes
PagedAttention(dst, q, kCache, vCache, blockTables, seqLens, queryLens, scale, window).max(0, end-window)instead of 0.paged_attention_kernelandpaged_attention_flash_kernel, start their position loop at the same point. The flash kernel's warps start from there; a warp left with no positions contributes nothing to the combine, as it already does for short spans.The KV cache still stores every position. Freeing blocks a window can no longer reach would cut memory for long sequences; that is a separate change.
Verification
go build ./...,go vet ./...,go test ./...pass; gofmt is clean.TestPagedAttentionVsReference(CPU) now runs at windows 0, 2, 5 and the full context against a float64 reference over the windowed positions, on scattered out-of-order blocks with GQA. Window = context matches unlimited.TestCUDAPagedAttentionWindowcompares the GPU against the CPU reference:internal/backend/cudaTestCUDAMatMulNVFP4W8A8: no FP8 GEMM on sm_86)internal/model/mistralinternal/model/nemotronhinternal/model/mistral4No throughput was measured. With
window == 0the kernels' loop starts at 0, as before.🤖 Generated with Claude Code
Automated review by pr-reviewer v0.54.0 | Safety Check | Nemotron 3 Nano | tracking id
r-c1e93c-f4307cThis is an AI-generated review and may contain mistakes.
Status: ❌ Failed
Review failed. Tracking id
r-c1e93c-f4307c— see logs for details.Comment
@pr-reviewer-bot retryto try again.