Sliding Window Attention › Key Parameters
Language AI HandbookAll chapters Sliding Window Attention › Key ParametersOne section · Sections in this chapter11 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
When implementing or configuring sliding window attention, several parameters directly impact both performance and computational efficiency:
-
window_size: The number of positions each token can attend to. Larger windows capture more context but increase computation. Common values range from 128-512 for efficient models to 4,096 for models like Mistral. Choose based on the expected range of relevant dependencies in your task.
-
causal: Whether to use causal masking (True for autoregressive language models, False for bidirectional models like BERT). Causal masking ensures tokens cannot attend to future positions, which is required for text generation.
-
dilation_rate: For dilated sliding windows, controls the gap between attended positions. A rate of 1 gives standard consecutive attention; rate 2 skips every other position, doubling the effective range. Use multiple dilation rates across heads for multi-scale attention.
-
num_layers: The number of transformer layers affects the effective receptive field. With layers and window , information can propagate approximately positions in each direction. Deeper models can use smaller windows.
-
d_k / d_head: The dimension of query and key vectors. Standard values follow where is the number of heads. This affects the scaling factor in attention score computation.
-
dtype_bytes: Memory precision for KV cache storage. Use 2 bytes for fp16/bf16 (recommended) or 4 bytes for fp32. Half precision halves memory usage with negligible quality impact.