Perceiver resampler

On this page 7

A Perceiver resampler is a neural module that converts a variable number of visual features into a small, fixed number of output tokens by letting a set of learned latent queries attend to those features through cross-attention. In multimodal AI, it sits between a vision encoder and a language model, so that an image or a video clip of any length reaches the language model as, for example, 64 compact visual tokens instead of hundreds or thousands of patch embeddings.

The module was popularized by the Flamingo family of vision-language models, which adapted ideas from the earlier Perceiver architecture. It belongs to the broader group of multimodal projectors and is one of the main techniques for visual token compression in artificial intelligence systems that combine images, video and text.

How the Perceiver resampler compresses visual features

The Perceiver resampler works by giving a fixed set of trainable vectors, called latents or queries, the job of summarizing whatever the vision encoder produced. A frozen encoder first turns each image or video frame into a grid of patch embeddings. These embeddings are flattened into one long sequence, and temporal position embeddings are added for video so that the module knows which frame each feature came from.

Each resampler layer then performs cross-attention from latents to features: the latents form the queries, while the keys and values come from the visual features concatenated with the latents themselves. A feed-forward block with residual connections follows. After several such layers, typically six in the original Flamingo design, the latents hold a condensed description of the visual input and are passed on as visual tokens.

The decisive property is that output length no longer depends on input length. Whether the encoder delivers 256 features for one image or 8,000 features for a short clip, the language model always receives the same number of tokens, which keeps its context budget and memory use predictable.

The following table summarizes the main components and the role each one plays in the module.

ComponentWhat it doesTypical setting
Learned latent queriesHold the compressed summary32 to 256 vectors
Cross-attention layerReads from visual featuresSeveral heads per layer
Feed-forward blockTransforms latent contentWidth about 4x model dimension
Temporal embeddingsMark frame order in videoOne vector per frame index
Layer stackRefines the summary iteratively1 to 6 layers
Components of a Perceiver resampler

Key parameters and design choices

The most important design choice is the number of latent queries, because it sets the trade-off between visual detail and language model cost. Fewer latents mean shorter sequences and faster inference, but they also limit how much fine-grained information, such as small text in a document, can survive the compression.

The table below shows how the main parameters influence quality and cost.

ParameterEffect when increasedMain cost
Number of latentsMore retained visual detailLonger language model sequence
Number of layersRicher, more selective summaryMore training compute
Input resolutionFiner source featuresQuadratic growth in encoder cost
Frames per clipBetter temporal coverageLarger cross-attention input
Parameters that shape resampler behavior

Because attention runs from M latents to N input features, the cost of each layer grows roughly with M times N rather than N squared. This linear scaling in input length is what makes the design attractive for video and for high-resolution images that produce very long feature sequences.

Perceiver resampler compared with other multimodal projectors

The Perceiver resampler is one of several ways to connect a vision encoder to a language model, and each approach balances token count against fidelity differently. The closest relative is the Q-Former of BLIP-2, which also uses learned queries but adds text interaction and a separate pretraining stage. Simple linear or MLP projectors, used in many instruction-tuned models, keep every patch token and therefore preserve more detail at higher cost.

This comparison highlights how the main connector types differ in practice.

ConnectorOutput token countMain strengthMain weakness
Perceiver resamplerFixed, smallPredictable cost for videoCan lose fine detail
Q-FormerFixed, smallText-aware query learningExtra pretraining stage
MLP projectorEqual to patch countHigh fidelity, simpleLong visual sequences
Pooling or pixel shuffleReduced by fixed ratioCheap and spatially faithfulRigid compression rate
Common ways to connect vision encoders to language models

In Flamingo, the resampler output feeds gated cross-attention layers inserted into a frozen language model, rather than being placed directly into the input sequence. Later open models often use resampler-style modules with a single cross-attention layer and place the resulting tokens straight into the prompt, which simplifies training.

Where the Perceiver resampler is used

A Perceiver resampler is most useful when the system must handle many images or long video inside a limited context window. Interleaved image-text documents, multi-frame video question answering and multimodal in-context learning with several example images all benefit, because each visual input costs the same small number of tokens.

  • Video-language models that sample dozens of frames per clip and need a stable token budget.
  • Few-shot multimodal prompting, where several image-text demonstrations must fit in one prompt.
  • On-device vision assistants, where shorter sequences reduce latency and memory.
  • Frozen-backbone training, where only the resampler and adapters are updated to save compute.

Limitations and common mistakes

The main limitation is information loss from fixed compression. Tasks that depend on small details, such as chart understanding, optical character recognition in dense documents or precise visual grounding, often degrade when only a few dozen latents represent a high-resolution page. Many recent models therefore prefer higher token counts or combine resampling with dynamic image tiling.

The table lists frequent problems, their usual cause and a practical remedy.

SymptomLikely causeRemedy
Small text is misreadToo few latents for pageAdd latents or use image tiles
Object positions are wrongWeak spatial informationAdd 2D position embeddings
Frame order is confusedMissing temporal embeddingsEncode frame index explicitly
Training is unstableResampler learns too fastLower learning rate, warm up
Typical resampler problems and fixes

A common misconception is that the latents correspond to fixed image regions. They do not: each latent learns to collect whatever information proves useful, so a single latent may draw from many regions, and interpretability is limited without dedicated probing.

A plain-language summary

Picture a reporter who must describe any event in exactly sixty-four short notes. A small event and a huge one both get the same number of notes. The reporter learns what matters and leaves the rest out.

A Perceiver resampler does this for pictures and videos. It reads everything the image system saw and writes a fixed, short summary for the language model. This keeps the model fast. The cost is that tiny details can be lost.

An example from practice

A team building a video question answering assistant for warehouse safety footage samples 32 frames from each two-minute clip. A vision transformer produces 256 patch features per frame, which would mean 8,192 visual tokens if passed through directly, far too many for the language model they want to run on a local GPU.

They insert a Perceiver resampler with 64 latent queries and temporal embeddings for frame order. Each clip now costs only 64 tokens, so the assistant can compare several clips in one prompt. Answers about whether a forklift entered a pedestrian zone stay accurate, while reading small labels on boxes becomes unreliable, so the team adds a separate high-resolution crop step for those questions.