Foundations to Frontier
Tests
E. Deep Learning › E12 Transformer Architectures

Perceiver and Perceiver IO

The Perceiver (Jaegle and colleagues, DeepMind, 2021) handles any input modality with one architecture. A small, learned latent array (for example 512 vectors) reads the raw input (pixels, audio samples, point clouds) by cross-attention, and a deep Transformer then works only on the latents. Cost is linear in input size instead of quadratic. Perceiver IO (2022) adds output queries, so the same model can produce outputs of any size and structure: optical flow, language, or game actions. This page covers the latent bottleneck, Fourier position features and output queries. In the exercises you implement cross-attention and the cost model, then measure when a latent bottleneck can stand in for full attention. With 8 latents it reproduced attention over 256 clustered tokens (relative error 0.12). On unstructured tokens, even 64 latents failed; only one latent per token worked.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A small memory that reads everything

Transformers compare every input with every other input, which is far too expensive for raw images or audio with tens of thousands of elements. The Perceiver keeps a small set of learned “latent” vectors. These latents read the whole input once through cross-attention, and all further processing happens among the latents. Perceiver IO adds output queries: each query asks the latents for one output, such as one pixel’s motion or one word. The demo shows how attention cost grows with input length.

Transformer lab
Full attention stores 16,777,216 scores per head; a linear-time method with 64 features stores 262,144, 64 times fewer.
Why engineers care

One architecture for images, audio, point clouds and multimodal sensor data, with cost linear in input size, suits robots and vehicles that fuse many sensors.

📝 Quick check (Level 0)
0/3 answered
  1. 1. In a Perceiver, the deep Transformer works on…
  2. 2. Latents read the input by…
  3. 3. Perceiver IO adds…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Inputs: a byte array of N elements, each with features plus position features. A 224 × 224 image is N = 50,176 pixels.
  • Latents: K learned vectors of width d, for example K = 512 and d = 1024 for ImageNet.
  • Cross-attention:
    • queries come from the latents, keys and values from the inputs;
    • cost 2·N·K·d, linear in N, against 2·N²·d for self-attention over the inputs;
    • at N = 50,176 and K = 512 it is N/K = 98 times cheaper than one full self-attention layer.
  • Latent Transformer: L self-attention layers on the latents cost 2·K²·d each, independent of N. The ImageNet model interleaves repeated cross-attentions (with shared weights) with a deep latent stack.
  • Position features: Fourier features of each coordinate: the coordinate plus a sine and cosine at each of B frequency bands, giving D(2B + 1) values for D input dimensions (258 for images with 64 bands).
  • Perceiver IO decoding: M output queries attend to the K latents, cost 2·M·K·d, linear in the number of outputs.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Cross-attention cost in input size N:
  2. 2. Fourier features for 2-D inputs with 64 bands:
  3. 3. Latent self-attention cost depends on N?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Perceivers in code

Exercise 1.

  • Cross-attention from 4 latents to 100 inputs matched the direct softmax formula.
  • The cost model added one cross-attention to the latent layers.
  • Fourier features of 5 coordinates with 6 bands had 13 columns.

Practice.

  • Hugging Face transformers provides Perceiver IO models (PerceiverForImageClassificationLearned, PerceiverForOpticalFlow, PerceiverForMaskedLM).
  • Choose K and d by compute budget. Add more cross-attentions if the latents need to re-read details of the input.
  • For outputs, build one query per output element from its position features (and a modality embedding for multimodal outputs).
z = latents.expand(B, -1, -1)                      # K learned latents
z = z + cross_attn(q=z, kv=inputs)                 # read the whole input once: O(NK)
for block in latent_blocks: z = block(z)           # deep processing: O(K^2) per layer
out = cross_attn(q=output_queries, kv=z)           # Perceiver IO: one query per output
🐍 Exercise 1: cross-attention and cost
Implement latent cross-attention, the Perceiver cost model and Fourier position features.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Perceiver IO output queries attend to…
  2. 2. If latents miss input detail, add…
  3. 3. Perceiver IO was applied to…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why a bottleneck works.

  • Raw inputs are highly redundant: neighbouring pixels and audio samples carry similar information.
  • A modest number of latents can summarise them, much as an image compresses well.
  • Cross-attention lets each latent choose what to read, so the summary adapts to the input.

What it gives up.

  • Everything the model knows about the input must pass through K × d numbers per cross-attention.
  • When every input element carries independent information that later outputs need, a small bottleneck must lose some of it.
  • Repeated cross-attention and Perceiver IO’s queries soften this, but cannot remove the limit.

Few assumptions. The Perceiver uses no convolutions or grids. Structure enters only through position features, so the same model handles images, audio, point clouds and combinations. The price is that more data or compute may be needed than for an architecture with built-in assumptions.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A latent bottleneck works well when inputs are…
  2. 2. The Perceiver's structural assumptions come from…
  3. 3. Information per cross-attention is limited to…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

When can a few latents stand in for full attention?

History.

  • A. Jaegle, F. Gimeno, A. Brock, A. Zisserman, O. Vinyals and J. Carreira, “Perceiver: general perception with iterative attention” (ICML 2021).
  • A. Jaegle et al., “Perceiver IO: a general architecture for structured inputs and outputs” (ICLR 2022).
  • Related ideas: inducing points in the Set Transformer (2019) and latent bottlenecks in later multimodal models.

Exercise 2.

  • Setup: full self-attention over 256 tokens (d = 16) is compared with a Perceiver-style bottleneck.
    • K latents, placed at k-means centres of the tokens, read the tokens by cross-attention.
    • Each token then reads the latents.
  • Inputs: tokens drawn from 8 clusters, or unstructured random tokens of the same scale.
  • Measurement: relative error of the outputs (error divided by the outputs’ spread), plus the cost at a 224 × 224 image with 512 latents.
latents K 1 2 4 8 16 64 256
clustered tokens 1.07 1.16 0.86 0.12 0.12 0.14 0.12
unstructured tokens 1.00 1.02 1.09 1.14 1.12 1.09 0.08

Cost at N = 50,176, K = 512, d = 64: full attention 3.2 × 10¹¹ multiply–adds, bottleneck (encode + decode) 6.6 × 10⁹, 49× less.

  • Structured inputs need few latents: error drops sharply once K reaches the number of clusters (8), then stays at about 0.12. That remaining error is the detail within each cluster that the bottleneck averages away.
  • Unstructured inputs need one latent per token: with sharp attention each token mostly attends to itself, so no summary smaller than the input reproduces it. Error stays above 1 up to 64 latents. Seeds 1 and 2 gave the same pattern.
  • This is the Perceiver’s bet: real sensor data is redundant, like the clustered case, so a small latent array keeps cost linear without losing what matters.
  • Caveat: these latents are fixed k-means centres, not trained. A trained Perceiver can learn better latents and use several cross-attentions, but it cannot beat the information limit on unstructured inputs.
🐍 Exercise 2 (research): when can a few latents stand in for full attention?
Compare full self-attention with a k-means latent bottleneck on clustered and unstructured tokens.

Perceivers in AI, robotics and aerospace

  • Multimodal sensor fusion: one latent array can read camera, lidar and proprioception together, each tagged with position and modality features.
  • Large inputs: point clouds and long audio or telemetry streams, where quadratic attention is impractical.
  • Design lesson: a learned bottleneck trades exactness for linear cost; check that your data is redundant enough before relying on it.

References

  1. A. Jaegle et al. (2021). “Perceiver: general perception with iterative attention.” Proc. ICML.
  2. A. Jaegle et al. (2022). “Perceiver IO: a general architecture for structured inputs and outputs.” Proc. ICLR.
  3. J. Lee et al. (2019). “Set Transformer.” Proc. ICML.