SWGDN: Pseudo-Query Sliding-Window Attention in Gated Delta Networks (arXiv:2611.33257)

SWGDN (arXiv:2611.33257) replaces static depthwise short convolutions in Gated DeltaNet-2 and Kimi Delta Attention (KDA) with lightweight pseudo-query sliding-window attention (W=4). By constructing content-dependent local Q/K/V learning pairs before the unchanged chunkwise recurrent kernel, SWGDN2-G1 jumps S-NIAH-2 1K accuracy from 62.0% to 99.4% and cuts 4K prefill+decode latency 12.1%.
SWGDN: Pseudo-Query Sliding-Window Attention in Gated Delta Networks (arXiv:2611.33257): SWGDN (arXiv:2611.33257) replaces static depthwise short convolutions in Gated DeltaNet-2 and Kimi Delta Attention (KDA) with lightweight pseudo-query sliding-window attention (W=4). By constructing content-dependent local Q/K/V learning pairs before the unchanged chunkwise recurrent kernel, SWGDN2-G1 jumps S-NIAH-2 1K accuracy from 62.0% to 99.4% and cuts 4K prefill+decode latency 12.1%. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Zero Recurrent Kernel Changes: Modifies only the pre-recurrence local mixer (`W=4`), reusing existing FlashLinearAttention / GDN2 / KDA chunkwise parallel kernels unmodified.
- Solves Fixed-Offset Short-Conv Blindness: Uses 1 learned pseudo-query per head (`G=1`) over RMSNorm+RoPE keys so salient tokens carry across overlapping windows for multi-step TTR updates.
- +37.4pp Needle-in-a-Haystack Recall Jump: SWGDN2-G1 improves RULER S-NIAH-2 (1K) from 62.0% to 99.4%, and SWGDN2-G64 lifts S-NIAH-1 (4K) from 56.8% to 87.8%.
- 12.1%–15.2% Faster Cached Inference at 4K: On RTX 6000D, SWGDN2-G1 cuts 4K prefill+decode latency from 92.005 s to 80.888 s (-12.1%), and SWKDA-G1 drops KDA from 78.871 s to 66.919 s (-15.2%).
- Direct Fit for Modern Hybrid MoE Agents: Explains why linear-recurrent layers in Qwen3.5, Haru-4B, and Ling-3.2-air (`conv=4`) benefit from content-aware local mixing.
import { createAgent } from '@smoke-monkey/harness';// Configure an architecture-research & kernel-benchmarking agent for SWGDN2-G1 / SWKDA-G1const kernelAgent = createAgent({agentId: 'swgdn-kernel-benchmarker',provider: 'openai',baseUrl: process.env.VLLM_BASE_URL ?? 'http://127.0.0.1:8000/v1',apiKey: 'local-vllm',model: 'inclusionAI/Ling-3.2-air',workspacePath: process.cwd(),tools: ['filesystem', 'terminal', 'search'],permission: 'ask-default',});kernelAgent.on('permission.required', (event) => {const cmd = String(event.data.args?.command ?? '');const allow = ['read_file', 'write_file', 'grep', 'glob'].includes(event.data.toolName) ||(event.data.toolName === 'run_command' && cmd.startsWith('pytest'));kernelAgent.resolvePermission(event.data.toolCallId, allow ? 'allow' : 'deny');});async function main() {const res = await kernelAgent.run('Implement PseudoQueryWindowMixer (W=4, G=1) replacing nn.Conv1d in layers/gated_deltanet.py, run pytest tests/test_swgdn_equivalence.py, and benchmark 4K decode latency.');console.log('Kernel verification status:', res.status);}main().catch(console.error);
Watch: Related Video Guides
NVIDIA fixed a FLAW in LINEAR ATTENTION nobody was talking about (Gated DeltaNet-2)
Hybrid Attention and Gated DeltaNet: How 2026 LLMs Actually Work
What Is SWGDN? Local Pair Construction for Test-Time Regression
Sliding-Window Gated DeltaNet (SWGDN, arXiv:2611.33257) replaces the fixed depthwise conv1d (W=4) in Delta-Rule linear attention architectures—specifically Gated DeltaNet-2 (GDN2) and Kimi Delta Attention (KDA)—with pseudo-query-driven sliding-window attention. Keeping the recurrent state update and chunkwise parallel kernels untouched, it lets overlapping windows reinforce salient associations across consecutive gradient steps.
Under the Test-Time Regression (TTR) view, linear attention maintains a matrix S_t fitting S k_t ≈ v_t via online gradient descent. Existing architectures (GDN, KDA, GDN2, MesaNet) focus on the update step itself while feeding Q, K, V through static short convolutions whose coefficients depend solely on relative offset. When a subject token shifts from t-2 to t-3 due to an adverb (*"Yesterday Alice thanked Bob"* vs *"Alice warmly thanked Bob"*), static convolutions cannot dynamically track it.
Pseudo-Query Sliding-Window Mixing Mechanics (W = 4)
For each head and branch X ∈ {Q, K, V}, SWGDN learns a compact pseudo-query tensor p^{X,g} of shape G x d (G=1 shares one pseudo-query per head; G=16 or 64 splits channels). Applying RMSNorm + RoPE to p^{X,g} and pre-mixing keys k_i within causal window W_t = {max(1, t-3), ..., t} produces content-dependent weights a^{X,g}_{t,i} = softmax((p^{X,g}_t)^T k_i / sqrt(d)) and mixed outputs x_tilde = SiLU(sum a^{X,g}_{t,i} x_i). At the 340M/15B scale, SWGDN2-G1 cuts 1-token adjacent K/V pair distance in Layer 1 from 1.168 to 0.677 (1.237 -> 0.689 in Layer 18 of SWKDA-G1), turning sequential writes into approximate multi-step SGD on key associations.
Language Modeling, RULER Needle-in-a-Haystack & Real-World Recall
Trained from scratch at 340M parameters on 15B FineWeb tokens, SWGDN2-G1 and SWKDA-G1 beat both fixed-convolution baselines and DynamicConv across perplexity, zero-shot reasoning, RULER NIAH, and six recall-heavy QA tasks.
340M / 15B FineWeb, Recall & Latency Benchmarks
| Model Variant | FineWeb PPL ↓ | Wiki PPL ↓ | Zero-Shot Avg ↑ | 6-Task Recall Avg ↑ | 4K Prefill + Decode (s) ↓ |
|---|---|---|---|---|---|
| GDN2 (Baseline) | 11.6180 | 29.6074 | 44.69% | 19.36% | 92.005 s |
| GDN2 + DynamicConv | 11.4713 | 28.9051 | 44.52% | 19.19% | 106.960 s |
SWGDN2-G1 (1 group/head) | 11.4657 | 28.8916 | 45.00% | 20.23% | 80.888 s (-12.1%) |
SWGDN2-G64 (1 per channel) | 11.4473 | 29.1324 | 45.15% | 19.50% | 80.561 s |
| KDA (Baseline) | 11.1157 | 27.4184 | 45.62% | 19.91% | 78.871 s |
SWKDA-G1 (1 group/head) | 10.9243 | 27.0141 | 46.11% | 21.63% | 66.919 s (-15.2%) |
On RULER needle-in-a-haystack tests, SWGDN2-G1 jumps S-NIAH-2 (1K) from 62.0% to 99.4%, while SWGDN2-G64 boosts S-NIAH-1 (4K) from 56.8% to 87.8%. On real-world recall tasks, SWKDA-G1 gains +4.41pp on SWDE (15.66% -> 20.07%) and +4.62pp on FDA (3.18% -> 7.80%).
Why SWGDN Decodes Faster Than `conv1d` & PyTorch Implementation
Measured on an NVIDIA RTX 6000D (BS=1, FP32 weights + BF16 autocast), SWGDN2-G1 and SWKDA-G1 lower both prefill latency (0.044s -> 0.038s on GDN2; 0.041s -> 0.034s on KDA) and full 4K cached decode latency (-12.1% and -15.2%), whereas DynamicConv slows 4K decode down to 106.960 s. During training at BS=16, 2K, throughput stays at 85.3% (SWGDN2-G1) and 83.5% (SWKDA-G1).
import torch
import torch.nn as nn
import torch.nn.functional as F
class PseudoQueryWindowMixer(nn.Module):
"""Drop-in replacement for W=4 depthwise conv1d in GDN2/KDA (G=1 default)."""
def __init__(self, num_heads: int, head_dim: int, window_size: int = 4, groups: int = 1):
super().__init__()
self.W = window_size
self.G = groups
self.d_g = head_dim // groups
# Learned pseudo-queries for Q, K, V branches: (3, num_heads, G, d_g)
self.pseudo_q = nn.Parameter(torch.randn(3, num_heads, groups, self.d_g) * 0.02)
self.k_norm = nn.RMSNorm(self.d_g)
self.p_norm = nn.RMSNorm(self.d_g)
def forward(self, q: torch.Tensor, k: torch.Tensor, v: torch.Tensor):
# q, k, v: (B, T, H, D) -> unfold causal window of length W=4 and score against k
# Returns SiLU-activated mixed (q_tilde, k_tilde, v_tilde) for unchanged GDN2/KDA kernel
raise NotImplementedError("Apply RoPE on window offsets 0..W-1, softmax over W, then F.silu")Choose G=1 for Optimal Accuracy-to-Memory Ratio
Sharing a single pseudo-query per head (SWGDN2-G1 / SWKDA-G1) captures virtually all perplexity and NIAH gains while avoiding the extra training memory overhead of per-channel G=64 heads (+2.24 GiB at 32K sequence length).
Implications for Hybrid Linear-Attention Agents in Smoke Monkey Harness
Modern open-weight agent models—including Ling-3.2-air (35 KDA layers with short_conv_kernel_size: 4), Haru-4B (24 linear_attention layers with conv_kernel: 4), and Nemotron-Labs-Image-30B-A3B (Mamba-2 conv_kernel: 4)—all rely on static W=4 short convolutions before recurrent updates. SWGDN proves a general recipe for next-generation agent architectures:
- Higher Associative Recall Without Growing KV Cache: Content-dependent
K/Vwindow mixing preservesO(1)recurrent state size during long multi-file coding loops while sharply improving needle retrieval (S-NIAH-2 +37.4pp). - Drop-In Pre-Training & Mid-Training Upgrade: Teams training custom domain linear-attention checkpoints in Smoke Monkey Harness R&D loops can swap
conv1dforPseudoQueryWindowMixer(G=1)without touching Triton chunkwise kernels. - Faster Local Long-Context Prefill: Lowering 4K cached decode overhead by
12–15%directly speeds up iterative test-fix loops in local workstations.
Frequently Asked Questions
Q:How does SWGDN differ from standard Gated DeltaNet-2 and Kimi Delta Attention?
SWGDN leaves the recurrent state update equations and chunkwise parallel kernels completely unchanged. It only replaces the static W=4 short depthwise convolutions on Q, K, and V with content-dependent sliding-window attention scored by learned pseudo-queries.
Q:Why does SWGDN reuse pre-mixing projected keys across all three branches?
In Test-Time Regression, keys act as the regression inputs that determine state update directions. Scoring Q, K, and V against RMSNorm+RoPE projected keys lets the K and V branches reinforce the same salient token across overlapping windows.
Q:What accuracy gains does SWGDN achieve on RULER and real-world recall benchmarks?
At 340M/15B scale, SWGDN2-G1 raises S-NIAH-2 (1K) from 62.0% to 99.4%, SWGDN2-G64 lifts S-NIAH-1 (4K) from 56.8% to 87.8%, and SWKDA-G1 raises 6-task generative recall average from 19.91% to 21.63% (+4.41pp on SWDE, +4.62pp on FDA).
Q:Does replacing conv1d with sliding-window attention slow down inference?
No—on an RTX 6000D, SWGDN2-G1 reduces 4K prefill+decode latency by 12.1% (92.005 s to 80.888 s) and SWKDA-G1 reduces KDA latency by 15.2% (78.871 s to 66.919 s), whereas DynamicConv slows GDN2 down to 106.960 s.
Q:Which pseudo-query grouping setting (G1, G16, or G64) should I use?
G1 (one shared pseudo-query per head in each Q, K, V branch) captures virtually all recall and perplexity improvements with minimal parameter and memory overhead.
Related Alternatives & Comparisons
Claude Code Runtime Alternative: Open Source Stdio MCP Agent Harness
LangChain TypeScript Alternative: Zero Dependencies & Deterministic Loops
9 Best Free Open Source ChatGPT Alternatives in 2026 (Self-Hosted & Local)
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.