← All tools

Interactive field guide

Build an attention mechanism

Change the mask, share the key-value cache, then assemble choices across all seven parts of the design.

01 / Connectivity

Choose a mask, then choose a query token.

querieskeys

Field guide

The seven questions

Use these to place any attention name. FlashAttention is execution, RoPE is position, GQA is heads and cache.

01 / Scoring

How is relevance measured?

The rule that scores a query against a key. Scaled dot product maps cleanly onto matrix multiplication; additive attention uses a small learned network; cosine attention compares direction only.

  • Scaled dot product
  • Additive
  • Cosine
Source: Attention Is All You Need ↗
02 / Connectivity

Who may look where?

The mask decides which pairs exist. Full attention fills the square, causal attention is a triangle that hides the future, local attention is a band near the diagonal. Cross-attention takes keys and values from another sequence.

  • Full
  • Causal
  • Local
  • Sliding window
  • Cross
Source: Swin Transformer ↗
03 / Heads and cache

What do the query heads share?

MHA gives every query head its own key and value head. MQA shares one across all of them, GQA shares one per group. MLA compresses keys and values into a smaller latent instead. Each trades KV-cache memory against variety.

  • MHA
  • GQA
  • MQA
  • MLA
Source: GQA ↗
04 / Growth

What grows with input length?

Full attention compares n × n pairs, so doubling the input can quadruple the work. Local and sparse patterns compare fewer pairs; linear attention keeps a running state instead of the full matrix, with different recall behaviour.

  • Full matrix
  • Sparse
  • Linear state
  • Hybrid
Source: Kimi Linear ↗
05 / Execution

How is it run and stored?

FlashAttention computes exact attention but tiles the work so it stays in fast on-chip memory. PagedAttention manages the serving KV cache in blocks. Neither changes which token attends to which.

  • FlashAttention
  • PagedAttention
  • Basic kernel
Source: FlashAttention ↗
06 / Position

How does order enter?

Plain attention sees a set. Sinusoidal and learned embeddings add a vector per position; RoPE rotates query and key features so their dot product carries relative position.

  • RoPE
  • Sinusoidal
  • Learned
Source: RoFormer ↗
07 / Domain

What structure does the input have?

Text is a sequence, images are patch grids, video adds time, graphs define neighbours by edges. The mask and position scheme should respect that structure.

  • Text
  • Image
  • Video
  • Graph

Read a model

Models are stacks of choices

A model name rarely maps to one attention type. Read it as one answer per axis.

Model / Llama 3

Causal + GQA + RoPE

A decoder language model. Its choices sit on three different axes, connectivity, heads and position, so they combine rather than compete.

  • Connectivity
  • Heads and cache
  • Position
Source: The Llama 3 Herd of Models ↗
Model / DeepSeek-V3

Multi-head latent attention

MLA shrinks the key-value representation used during inference. That is mainly a heads-and-cache decision inside a much larger architecture.

  • Heads and cache
Source: DeepSeek-V3 Technical Report ↗
Model / Kimi Linear

Linear layers with occasional full attention

Recurrent Kimi Delta Attention layers mixed with full MLA layers. It changes how work and memory grow at long context while keeping some full attention.

  • Growth
  • Heads and cache
Source: Kimi Linear ↗
Checklist / New paper

Seven answers for every new name

Which scoring rule changed? Which connections are allowed? How many heads, and what is cached? How does cost grow? Is it maths, a kernel or memory management? Where does position enter? What structure is the input?