DL0029 Dilated Attention

Could you explain the concept of dilated attention in transformer architectures?

Answer

Dilated attention sparsifies self-attention by letting each query attend only to every d-th key position (a strided subset of the sequence) instead of all keys or a contiguous window. Borrowed from dilated convolutions in CNNs, the dilation rate d controls the stride: attention keeps a long global reach (the sampled keys span the whole sequence) while computing only about 1/d of the score matrix. The trade-off is granularity: nearby fine detail is skipped within each head.

(1) Strided Sampling: Query i attends to keys j where (j - i) is a multiple of d; d = 1 recovers full attention.
(2) Global but Sparse: Unlike sliding windows, coverage spans the entire sequence: long-range links survive, sampled coarsely.
(3) Cost Reduction: Each row computes roughly n/d scores, so compute and memory drop from O(n^2) toward O(n^2 / d).

A 16x16 attention matrix where each query attends only to every third key position forming a regular striped dilated pattern with dilation rate three.

Figure 1: Dilation d = 3: each query attends every 3rd key: full-span coverage with a third of the computations.

Mathematical Formulation:
\mathrm{Attention}_{dilated}(Q, K, V) = \mathrm{softmax}\left(\frac{Q K_d^{\top}}{\sqrt{d_k}}\right) V_d
K_d, V_d = \text{rows of } K, V \text{ at strided (dilated) positions}

Where:

  • d is the dilation rate, the stride between attended key positions.
  • K_d, V_d are the dilated subsets of keys and values (about n/d rows per query).
  • d_k is the key dimension, used for the usual softmax scaling.

Coverage Through Stacking: Layers with increasing dilation rates (e.g., 1, 2, 4, 8) progressively widen and interleave coverage, so deeper layers see the full sequence even though each layer is sparse: the same trick as WaveNet’s exponentially dilated convolutions.

Propagation of a single active position through two iterations of dilation-2 attention showing a regular grid of covered cells with gaps that never get attended.

Figure 2: Gridding artifacts: repeating one fixed dilation leaves some positions permanently unattended. Mixing dilation rates closes the gaps.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *