Sliding Window Attention › Key Parameters

Michael BrenndoerferUpdated June 26, 20252 min read
Language AI HandbookAll chapters
Part 17 of 67Efficient Attention
Chapter 119Sliding Window Attention › Key Parameters
Reading section 11 of 12 · Key Parameters · 2 minSection 11 of 12 · 2 min

Book contents

Section 11 of 12 · 2 min read

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 LL layers and window ww, information can propagate approximately L⋅(w/2)L \cdot (w/2) positions in each direction. Deeper models can use smaller windows.

  • d_k / d_head: The dimension of query and key vectors. Standard values follow dk=dmodel/hd_k = d_{\text{model}} / h where hh is the number of heads. This affects the scaling factor dk\sqrt{d_k} 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.