TL;DR
The Perceiver is a Transformer built to read inputs that are far too long for an ordinary one. Its input can be a million pixels, a long audio clip or a cloud of points. Instead of letting every input element attend to every other, it passes the input through a small, fixed set of learned vectors called latents, using attention from the latents to the input. The cost is then the input length times the number of latents, not the input length squared.
The same architecture works for images, audio and video without changing its core, which is why it was built as a general-purpose model.
Builds on: Transformer, Multi-Head Attention · Leads to: Perceiver IO and later latent-bottleneck architectures
Where it's used
Raw pixels. A 224 by 224 image has 50,176 pixels. A standard transformer that treats each pixel as a token would compare every pixel with every other one, which is about 2.5 billion score entries per head in each attention layer. Vision models avoid this by first cutting the image into patches. The Perceiver reads the pixels directly, so no patching step is needed.
Raw audio. A few seconds of audio sampled at 16,000 values per second produce tens of thousands of samples. Working on the waveform directly avoids the hand-designed spectrogram front end that many speech systems use, and the Perceiver's latent step keeps the cost of such long inputs manageable.
Multimodal inputs. Because the input is just an array of vectors, the same model can take a mix of image, audio and text tokens, each with its own position information. The original paper reported strong results on image, audio and point-cloud benchmarks with one architecture, which was the point of the design.
How it works
The walkthrough uses the smallest possible case: two input values and one latent. Real models use tens of thousands of inputs and hundreds of latents, but each step below is the same. Every number is a scalar, and the learned projections are left out so the arithmetic is visible.
-
Start with the input. The input array is x = [0, 2]. In a real model each entry is a vector, and there are many more of them. Check: two inputs, so the attention step will touch two entries.
-
Give the latent a query. The single latent has query value q = 1, a number a real model would learn. Score each input by multiplying: s = [1 × 0, 1 × 2] = [0, 2]. Check: a larger score means the input matches the latent better.
-
Turn the scores into weights. Apply Softmax: exponentiate each score and divide by the sum. e⁰ = 1 and e² ≈ 7.3891, with sum 8.3891. The weights are [1 / 8.3891, 7.3891 / 8.3891] ≈ [0.1192, 0.8808]. Check: the weights add to 1.
-
Mix the inputs. The latent's new value is the weighted sum of the inputs: 0.1192 × 0 + 0.8808 × 2 ≈ 1.7616. Check: the output sits between the inputs, closer to the one with the larger weight.
-
Pass the latent through its own blocks. In the real model this value is then updated by self-attention among the latents and a feedforward layer, and the whole cross-attention step is repeated with shared weights. Only the latents are updated; the input array stays as it was. Check: the input is read again at every iteration, so no information is discarded at step 4 alone.
The number of latents, not the input length, sets the size of everything after step 4.
flowchart LR X["Input array, M elements"] -->|"cross-attention: latents query the input"| Z["N latents"] Z -->|"self-attention among latents"| Z Z -->|"feedforward and repeat with shared weights"| Z Z --> O["Output: pooled latents, or a decoder in Perceiver IO"]
The math
Let the input be an array X in R^(M×D), with M elements, and let the latent array be Z in R^(N×C), with N learned vectors and N much smaller than M. A Perceiver block has two parts. First, cross-attention from the latents to the input:
Second, self-attention among the latents, followed by a feedforward layer, each with a residual connection and layer normalization. The weights W_Q, W_K and W_V are learned, and d is the key dimension.
Step 2 in symbols
For the walkthrough, let the query be q and the input values be x_j. The scores are s_j = q · x_j, and the weights are a_j = e^(s_j) / Σ_k e^(s_k). The output is z = Σ_j a_j x_j.
With q = 1 and x = [0, 2], this gives s = [0, 2], a ≈ [0.1192, 0.8808], and z ≈ 1.7616, matching steps 2 to 4.
Step 3 in symbols: the cost
A standard transformer layer compares every element with every other, so the score matrix has M² entries. A Perceiver cross-attention block has an N × M score matrix, and its latent self-attention has N² entries. Per layer, the score count is
Take M = 50,000 and N = 512. Then M² = 2.5 × 10⁹, while NM + N² = 2.56 × 10⁷ + 2.6 × 10⁵ ≈ 2.59 × 10⁷. The ratio is about 97, so the Perceiver computes roughly 97 times fewer score entries for this input.
These numbers count score entries for one head in one layer. The real comparison also depends on the feedforward layers and on how many iterations are run.
Why the latents can be few
The latent array is a learned summary. Each cross-attention step reads the whole input, so the latents can ask different questions of it, and repeating the step lets them refine what they have collected. The bottleneck is in the number of latents, which limits how much can be held at once.
Worked examples
Input x = [0, 2], one latent with query q = 1.
- Scores: s = [0, 2].
- Exponentials: [1, 7.3891].
- Sum: 8.3891.
- Weights: [0.1192, 0.8808].
- Output: 0.1192 × 0 + 0.8808 × 2 = 1.7616.
- Check: the weights sum to 1.0000.
Interpretation: the latent reads mostly the second input, the one with the larger score, and reads almost nothing from the first.
Input x = [0, 1, 2], two latents with queries q₁ = 1 and q₂ = -1.
- Latent 1 scores: [0, 1, 2]. Exponentials: [1, 2.7183, 7.3891], sum 11.1074.
- Latent 1 weights: [0.0900, 0.2447, 0.6652].
- Latent 1 output: 0 × 0.0900 + 1 × 0.2447 + 2 × 0.6652 = 0.2447 + 1.3305 = 1.5752.
- Latent 2 scores: [0, -1, -2]. Exponentials: [1, 0.3679, 0.1353], sum 1.5032.
- Latent 2 weights: [0.6652, 0.2447, 0.0900].
- Latent 2 output: 0 × 0.6652 + 1 × 0.2447 + 2 × 0.0900 = 0.2447 + 0.1800 = 0.4248, rounded.
Interpretation: the two latents read the same inputs in opposite directions. Latent 1 favours the largest input and latent 2 favours the smallest, so the pair records two different views of the same three values.
A 224 by 224 image has M = 50,176 pixels. A standard transformer layer, over pixel tokens, needs M² = 2,517,630,976 score entries per head, about 2.5 billion. Suppose the Perceiver uses N = 512 latents.
- Cross-attention scores: N × M = 512 × 50,176 = 25,690,112.
- Latent self-attention scores: N² = 512² = 262,144.
- Total: 25,690,112 + 262,144 = 25,952,256.
- Ratio to the standard layer: 2,517,630,976 / 25,952,256 ≈ 97.
- Interpretation: per head and per layer, the Perceiver makes about 97 times fewer score entries. Its cost still grows linearly with the number of pixels, because N is fixed.
Try it: an audio clip gives M = 80,000 samples, and N = 256 latents. What is the Perceiver's score count? Answer: N × M = 256 × 80,000 = 20,480,000, and N² = 65,536, for a total of 20,545,536.
Common mistakes and tradeoffs
It is tempting to think the latent bottleneck throws information away. In fact the latents are re-queried against the full input at every iteration, so the input stays available at each step. What is limited is how much the latents can hold at one time, which is set by N.
It is tempting to think the Perceiver is simply a faster transformer for text. In fact its output is a fixed set of latents, not a sequence, so generating long text one token at a time needs a decoder. The Perceiver IO extension adds one that produces outputs of arbitrary shape.
It is tempting to think position information is unnecessary because the input is an unordered array. In fact the Perceiver still needs to know where each element sits in the image, the audio or the cloud, and it adds position information to the input as encodings, as a positional encoding does in a transformer.
It is tempting to make N as large as possible. In fact a larger N brings the cost closer to a standard transformer, since the latent self-attention grows with N². N is a design choice that trades information capacity for compute.
| Setting | Perceiver | Standard transformer |
|---|---|---|
| Very long input, such as pixels or raw audio | Cost grows linearly with input length | Cost grows with the square of input length |
| Short input, a few hundred tokens | Overhead without much saving | Simple and usually strong |
| Long generated output | Needs a decoder (Perceiver IO) | Autoregressive decoding is standard |
| Pairwise access between input elements | Only through the latents | Every element attends to every other |
History
Transformers were introduced in 2017 by Vaswani and colleagues, and their attention cost grows with the square of the sequence length. That became a problem as people applied transformers to images and audio. The Vision Transformer of 2020 handled images by cutting them into patches, which reduced the number of tokens but required a fixed patch design for each kind of input.
In 2021 Andrew Jaegle and colleagues proposed the Perceiver, which kept the input in its raw form and reduced the cost with a fixed set of latent vectors. The same year they introduced Perceiver IO, which added flexible outputs. The idea of a latent bottleneck has since appeared in several other architectures.
Recap
- A transformer compares every element with every other, which costs M² in the input length M.
- The Perceiver lets a small set of N latent vectors read the input with cross-attention, so the cost is about NM + N².
- Latents are refined by self-attention and feedforward layers, and the cross-attention step repeats with shared weights.
- The design takes raw inputs of any kind, such as pixels, audio or points, without a hand-built front end.
- The bottleneck size N controls the tradeoff between capacity and cost.
Next, read Vision Transformer (ViT) to see the patch-based alternative for images, and the Perceiver IO paper for structured outputs.
Check yourself
QuestionWhat are the two attention steps in a Perceiver block, and which way does each one read?Show answer
The first is cross-attention, in which the latents form the queries and the input forms the keys and values, so the latents read the input. The second is self-attention among the latents, which lets the latents read each other. A feedforward layer follows, and the block repeats with shared weights.
QuestionWith input x = [1, 3] and one latent with query q = 0, what is the latent's output?Show answer
The scores are 0 × 1 = 0 and 0 × 3 = 0. Both exponentials are 1, so both weights are 0.5. The output is 0.5 × 1 + 0.5 × 3 = 2. With equal scores, the latent takes the plain average of the inputs.
QuestionWhy does the cost of a Perceiver grow more slowly than a standard transformer as the input gets longer?Show answer
A standard transformer's score matrix has one entry for every pair of input elements, so it grows with the square of the input length. The Perceiver's cross-attention scores the N latents against the M inputs, which is N times M. The latent-only part depends on N, not M. With N fixed, the cost grows linearly in M.
QuestionYou want to apply a Perceiver to a task whose output is a long sequence of tokens. What must you add, and why?Show answer
You need a decoder that turns the latents into an output sequence of the right length, because the latents are a fixed-size summary and do not produce a sequence by themselves. Perceiver IO adds this kind of decoder, which uses query vectors for each output position to read the latents. For a long sequence generated one token at a time, the decoding loop is itself sequential and costs extra.