Modern Attention Head

Experimental alpha. Expect breaking changes and major bugs. Your feedback is much appreciated.

Modern Attention Head

Multi-head causal self-attention as the late designs do it: Rotary Positions on queries and keys, a QK Normalizer between them, in one machine. A machine made from a verified design takes each row's scores a tile at a time with an online softmax and never holds them: see The Modern Block.

Shapes

A sequence [B×T×C] in, the same shape out.

Settings

  • Heads: 1, 2, 4 or 8. 4 by default. C must divide evenly by it, and with Rotary on, each head's width must be even.
  • Rotary: on by default. Off, it tells nothing about places: it needs a Position Table before it.
  • QK norm: on by default. Off, its scores are q·kᵀ/√d, with no bound.

Parameters

4 × C², and 1 for the temperature with QK norm on.

In PyTorch

q, k = rotate(q), rotate(k)
q, k = F.normalize(q, dim=-1) * t * dh ** 0.5, F.normalize(k, dim=-1)
y = F.scaled_dot_product_attention(q, k, v, is_causal=True)

Notes

Its picture shows the attention pattern of its first head, like the Attention Head's. Each picture comes from a separate pass the plain way, which holds the scores; the steps of training never do.

Making it

The Fabricator makes it from a photomask of Modern Attention: verify the spec on a Bench, or find a salvaged mask in the ruins, which makes it unfused. See The Bench and the Fabricator.