---
local: perceiver
sections:
- local: overview
  title: Overview
- local: transformers.models.perceiver.modeling_perceiver.PerceiverModelOutput
  title: Perceiver specific outputs
- local: transformers.PerceiverConfig
  title: PerceiverConfig
- local: transformers.PerceiverTokenizer
  title: PerceiverTokenizer
- local: transformers.PerceiverFeatureExtractor
  title: PerceiverFeatureExtractor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverTextPreprocessor
  title: PerceiverTextPreprocessor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverImagePreprocessor
  title: PerceiverImagePreprocessor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverOneHotPreprocessor
  title: PerceiverOneHotPreprocessor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverAudioPreprocessor
  title: PerceiverAudioPreprocessor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPreprocessor
  title: PerceiverMultimodalPreprocessor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverProjectionDecoder
  title: PerceiverProjectionDecoder
- local: transformers.models.perceiver.modeling_perceiver.PerceiverBasicDecoder
  title: PerceiverBasicDecoder
- local: transformers.models.perceiver.modeling_perceiver.PerceiverClassificationDecoder
  title: PerceiverClassificationDecoder
- local: transformers.models.perceiver.modeling_perceiver.PerceiverOpticalFlowDecoder
  title: PerceiverOpticalFlowDecoder
- local: transformers.models.perceiver.modeling_perceiver.PerceiverBasicVideoAutoencodingDecoder
  title: PerceiverBasicVideoAutoencodingDecoder
- local: transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalDecoder
  title: PerceiverMultimodalDecoder
- local: transformers.models.perceiver.modeling_perceiver.PerceiverProjectionPostprocessor
  title: PerceiverProjectionPostprocessor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverAudioPostprocessor
  title: PerceiverAudioPostprocessor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverClassificationPostprocessor
  title: PerceiverClassificationPostprocessor
- local: transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPostprocessor
  title: PerceiverMultimodalPostprocessor
- local: transformers.PerceiverModel
  title: PerceiverModel
- local: transformers.PerceiverForMaskedLM
  title: PerceiverForMaskedLM
- local: transformers.PerceiverForSequenceClassification
  title: PerceiverForSequenceClassification
- local: transformers.PerceiverForImageClassificationLearned
  title: PerceiverForImageClassificationLearned
- local: transformers.PerceiverForImageClassificationFourier
  title: PerceiverForImageClassificationFourier
- local: transformers.PerceiverForImageClassificationConvProcessing
  title: PerceiverForImageClassificationConvProcessing
- local: transformers.PerceiverForOpticalFlow
  title: PerceiverForOpticalFlow
- local: transformers.PerceiverForMultimodalAutoencoding
  title: PerceiverForMultimodalAutoencoding
title: Perceiver
---
<script>
import Tip from "./Tip.svelte";
import Youtube from "./Youtube.svelte";
import Docstring from "./Docstring.svelte";
import CodeBlock from "./CodeBlock.svelte";
import CodeBlockFw from "./CodeBlockFw.svelte";
import DocNotebookDropdown from "./DocNotebookDropdown.svelte";
import IconCopyLink from "./IconCopyLink.svelte";
export let fw: "pt" | "tf"
</script>
<!--Copyright 2021 The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

<h1 id="perceiver">Perceiver</h1>

<h2 id="overview">Overview</h2>

The Perceiver IO model was proposed in [Perceiver IO: A General Architecture for Structured Inputs &
Outputs](https://arxiv.org/abs/2107.14795) by Andrew Jaegle, Sebastian Borgeaud, Jean-Baptiste Alayrac, Carl Doersch,
Catalin Ionescu, David Ding, Skanda Koppula, Daniel Zoran, Andrew Brock, Evan Shelhamer, Olivier Hénaff, Matthew M.
Botvinick, Andrew Zisserman, Oriol Vinyals, João Carreira.

Perceiver IO is a generalization of [Perceiver](https://arxiv.org/abs/2103.03206) to handle arbitrary outputs in
addition to arbitrary inputs. The original Perceiver only produced a single classification label. In addition to
classification labels, Perceiver IO can produce (for example) language, optical flow, and multimodal videos with audio.
This is done using the same building blocks as the original Perceiver. The computational complexity of Perceiver IO is
linear in the input and output size and the bulk of the processing occurs in the latent space, allowing us to process
inputs and outputs that are much larger than can be handled by standard Transformers. This means, for example,
Perceiver IO can do BERT-style masked language modeling directly using bytes instead of tokenized inputs.

The abstract from the paper is the following:

*The recently-proposed Perceiver model obtains good results on several domains (images, audio, multimodal, point
clouds) while scaling linearly in compute and memory with the input size. While the Perceiver supports many kinds of
inputs, it can only produce very simple outputs such as class scores. Perceiver IO overcomes this limitation without
sacrificing the original's appealing properties by learning to flexibly query the model's latent space to produce
outputs of arbitrary size and semantics. Perceiver IO still decouples model depth from data size and still scales
linearly with data size, but now with respect to both input and output sizes. The full Perceiver IO model achieves
strong results on tasks with highly structured output spaces, such as natural language and visual understanding,
StarCraft II, and multi-task and multi-modal domains. As highlights, Perceiver IO matches a Transformer-based BERT
baseline on the GLUE language benchmark without the need for input tokenization and achieves state-of-the-art
performance on Sintel optical flow estimation.*

Here's a TLDR explaining how Perceiver works:

The main problem with the self-attention mechanism of the Transformer is that the time and memory requirements scale
quadratically with the sequence length. Hence, models like BERT and RoBERTa are limited to a max sequence length of 512
tokens. Perceiver aims to solve this issue by, instead of performing self-attention on the inputs, perform it on a set
of latent variables, and only use the inputs for cross-attention. In this way, the time and memory requirements don't
depend on the length of the inputs anymore, as one uses a fixed amount of latent variables, like 256 or 512. These are
randomly initialized, after which they are trained end-to-end using backpropagation.

Internally, [PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel) will create the latents, which is a tensor of shape `(batch_size, num_latents,
d_latents)`. One must provide `inputs` (which could be text, images, audio, you name it!) to the model, which it will
use to perform cross-attention with the latents. The output of the Perceiver encoder is a tensor of the same shape. One
can then, similar to BERT, convert the last hidden states of the latents to classification logits by averaging along
the sequence dimension, and placing a linear layer on top of that to project the `d_latents` to `num_labels`.

This was the idea of the original Perceiver paper. However, it could only output classification logits. In a follow-up
work, PerceiverIO, they generalized it to let the model also produce outputs of arbitrary size. How, you might ask? The
idea is actually relatively simple: one defines outputs of an arbitrary size, and then applies cross-attention with the
last hidden states of the latents, using the outputs as queries, and the latents as keys and values.

So let's say one wants to perform masked language modeling (BERT-style) with the Perceiver. As the Perceiver's input
length will not have an impact on the computation time of the self-attention layers, one can provide raw bytes,
providing `inputs` of length 2048 to the model. If one now masks out certain of these 2048 tokens, one can define the
`outputs` as being of shape: `(batch_size, 2048, 768)`. Next, one performs cross-attention with the final hidden states
of the latents to update the `outputs` tensor. After cross-attention, one still has a tensor of shape `(batch_size,
2048, 768)`. One can then place a regular language modeling head on top, to project the last dimension to the
vocabulary size of the model, i.e. creating logits of shape `(batch_size, 2048, 262)` (as Perceiver uses a vocabulary
size of 262 byte IDs).

<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/perceiver_architecture.jpg"
alt="drawing" width="600"/> 

<small> Perceiver IO architecture. Taken from the <a href="https://arxiv.org/abs/2105.15203">original paper</a> </small>

This model was contributed by [nielsr](https://huggingface.co/nielsr). The original code can be found
[here](https://github.com/deepmind/deepmind-research/tree/master/perceiver).

Tips:

- The quickest way to get started with the Perceiver is by checking the [tutorial
  notebooks](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/Perceiver).
- Refer to the [blog post](https://huggingface.co/blog/perceiver) if you want to fully understand how the model works and
is implemented in the library. Note that the models available in the library only showcase some examples of what you can do
with the Perceiver. There are many more use cases, including question answering, named-entity recognition, object detection, 
audio classification, video classification, etc. 

**Note**:

- Perceiver does **not** work with `torch.nn.DataParallel` due to a bug in PyTorch, see [issue #36035](https://github.com/pytorch/pytorch/issues/36035)

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverModelOutput">Perceiver specific outputs</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverModelOutput</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverModelOutput</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L66</source><parameters>[{"name": "logits", "val": ": FloatTensor = None"}, {"name": "last_hidden_state", "val": ": FloatTensor = None"}, {"name": "hidden_states", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "cross_attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}]</parameters><paramsdesc>- **logits** (`torch.FloatTensor` of shape `(batch_size, num_labels)`) --
  Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **last_hidden_state** (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`) --
  Sequence of hidden-states at the output of the last layer of the model.
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) --
  Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</paramsdesc><paramgroups>0</paramgroups></docstring>

Base class for Perceiver base model's outputs, with potential hidden states, attentions and cross-attentions.




</div>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverDecoderOutput</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverDecoderOutput</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L97</source><parameters>[{"name": "logits", "val": ": FloatTensor = None"}, {"name": "cross_attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}]</parameters><paramsdesc>- **logits** (`torch.FloatTensor` of shape `(batch_size, num_labels)`) --
  Output of the basic decoder.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</paramsdesc><paramgroups>0</paramgroups></docstring>

Base class for Perceiver decoder outputs, with potential cross-attentions.




</div>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverMaskedLMOutput</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverMaskedLMOutput</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L115</source><parameters>[{"name": "loss", "val": ": typing.Optional[torch.FloatTensor] = None"}, {"name": "logits", "val": ": FloatTensor = None"}, {"name": "hidden_states", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "cross_attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}]</parameters><paramsdesc>- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) --
  Masked language modeling (MLM) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`) --
  Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) --
  Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, num_latents,
  num_latents)`. Attentions weights after the attention softmax, used to compute the weighted average in the
  self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</paramsdesc><paramgroups>0</paramgroups></docstring>

Base class for Perceiver's masked language model outputs.




</div>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverClassifierOutput</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L146</source><parameters>[{"name": "loss", "val": ": typing.Optional[torch.FloatTensor] = None"}, {"name": "logits", "val": ": FloatTensor = None"}, {"name": "hidden_states", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}, {"name": "cross_attentions", "val": ": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}]</parameters><paramsdesc>- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) --
  Classification (or regression if config.num_labels==1) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`) --
  Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) --
  Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) --
  Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</paramsdesc><paramgroups>0</paramgroups></docstring>

Base class for Perceiver's outputs of sequence/image classification models, optical flow and multimodal
autoencoding.




</div>

<h2 id="transformers.PerceiverConfig">PerceiverConfig</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverConfig</name><anchor>transformers.PerceiverConfig</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/configuration_perceiver.py#L29</source><parameters>[{"name": "num_latents", "val": " = 256"}, {"name": "d_latents", "val": " = 1280"}, {"name": "d_model", "val": " = 768"}, {"name": "num_blocks", "val": " = 1"}, {"name": "num_self_attends_per_block", "val": " = 26"}, {"name": "num_self_attention_heads", "val": " = 8"}, {"name": "num_cross_attention_heads", "val": " = 8"}, {"name": "qk_channels", "val": " = None"}, {"name": "v_channels", "val": " = None"}, {"name": "cross_attention_shape_for_attention", "val": " = 'kv'"}, {"name": "self_attention_widening_factor", "val": " = 1"}, {"name": "cross_attention_widening_factor", "val": " = 1"}, {"name": "hidden_act", "val": " = 'gelu'"}, {"name": "attention_probs_dropout_prob", "val": " = 0.1"}, {"name": "position_embedding_init_scale", "val": " = 0.02"}, {"name": "initializer_range", "val": " = 0.02"}, {"name": "layer_norm_eps", "val": " = 1e-12"}, {"name": "is_encoder_decoder", "val": " = False"}, {"name": "use_query_residual", "val": " = True"}, {"name": "vocab_size", "val": " = 262"}, {"name": "max_position_embeddings", "val": " = 2048"}, {"name": "image_size", "val": " = 56"}, {"name": "train_size", "val": " = [368, 496]"}, {"name": "num_frames", "val": " = 16"}, {"name": "audio_samples_per_frame", "val": " = 1920"}, {"name": "samples_per_patch", "val": " = 16"}, {"name": "output_shape", "val": " = [1, 16, 224, 224]"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **num_latents** (`int`, *optional*, defaults to 256) --
  The number of latents.
- **d_latents** (`int`, *optional*, defaults to 1280) --
  Dimension of the latent embeddings.
- **d_model** (`int`, *optional*, defaults to 768) --
  Dimension of the inputs. Should only be provided in case [*PerceiverTextPreprocessor*] is used or no
  preprocessor is provided.
- **num_blocks** (`int`, *optional*, defaults to 1) --
  Number of blocks in the Transformer encoder.
- **num_self_attends_per_block** (`int`, *optional*, defaults to 26) --
  The number of self-attention layers per block.
- **num_self_attention_heads** (`int`, *optional*, defaults to 8) --
  Number of attention heads for each self-attention layer in the Transformer encoder.
- **num_cross_attention_heads** (`int`, *optional*, defaults to 8) --
  Number of attention heads for each cross-attention layer in the Transformer encoder.
- **qk_channels** (`int`, *optional*) --
  Dimension to project the queries + keys before applying attention in the cross-attention and self-attention
  layers of the encoder. Will default to preserving the dimension of the queries if not specified.
- **v_channels** (`int`, *optional*) --
  Dimension to project the values before applying attention in the cross-attention and self-attention layers
  of the encoder. Will default to preserving the dimension of the queries if not specified.
- **cross_attention_shape_for_attention** (`str`, *optional*, defaults to `'kv'`) --
  Dimension to use when downsampling the queries and keys in the cross-attention layer of the encoder.
- **self_attention_widening_factor** (`int`, *optional*, defaults to 1) --
  Dimension of the feed-forward layer in the cross-attention layer of the Transformer encoder.
- **cross_attention_widening_factor** (`int`, *optional*, defaults to 1) --
  Dimension of the feed-forward layer in the self-attention layers of the Transformer encoder.
- **hidden_act** (`str` or `function`, *optional*, defaults to `"gelu"`) --
  The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  `"relu"`, `"selu"` and `"gelu_new"` are supported.
- **attention_probs_dropout_prob** (`float`, *optional*, defaults to 0.1) --
  The dropout ratio for the attention probabilities.
- **initializer_range** (`float`, *optional*, defaults to 0.02) --
  The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
- **layer_norm_eps** (`float`, *optional*, defaults to 1e-12) --
  The epsilon used by the layer normalization layers.
- **use_query_residual** (`float`, *optional*, defaults to `True`) --
  Whether to add a query residual in the cross-attention layer of the encoder.
- **vocab_size** (`int`, *optional*, defaults to 262) --
  Vocabulary size for the masked language modeling model.
- **max_position_embeddings** (`int`, *optional*, defaults to 2048) --
  The maximum sequence length that the masked language modeling model might ever be used with. Typically set
  this to something large just in case (e.g., 512 or 1024 or 2048).
- **image_size** (`int`, *optional*, defaults to 56) --
  Size of the images after preprocessing, for [PerceiverForImageClassificationLearned](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForImageClassificationLearned).
- **train_size** (`List[int]`, *optional*, defaults to [368, 496]) --
  Training size of the images for the optical flow model.
- **num_frames** (`int`, *optional*, defaults to 16) --
  Number of video frames used for the multimodal autoencoding model.
- **audio_samples_per_frame** (`int`, *optional*, defaults to 1920) --
  Number of audio samples per frame for the multimodal autoencoding model.
- **samples_per_patch** (`int`, *optional*, defaults to 16) --
  Number of audio samples per patch when preprocessing the audio for the multimodal autoencoding model.
- **output_shape** (`List[int]`, *optional*, defaults to `[1, 16, 224, 224]`) --
  Shape of the output (batch_size, num_frames, height, width) for the video decoder queries of the multimodal
  autoencoding model. This excludes the channel dimension.</paramsdesc><paramgroups>0</paramgroups></docstring>

This is the configuration class to store the configuration of a [PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel). It is used to instantiate an
Perceiver model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the Perceiver
[deepmind/language-perceiver](https://huggingface.co/deepmind/language-perceiver) architecture.

Configuration objects inherit from [PretrainedConfig](/docs/transformers/pr_15592/en/main_classes/configuration#transformers.PretrainedConfig) and can be used to control the model outputs. Read the
documentation from [PretrainedConfig](/docs/transformers/pr_15592/en/main_classes/configuration#transformers.PretrainedConfig) for more information.



Example:

```python
>>> from transformers import PerceiverModel, PerceiverConfig

>>> # Initializing a Perceiver deepmind/language-perceiver style configuration
>>> configuration = PerceiverConfig()

>>> # Initializing a model from the deepmind/language-perceiver style configuration
>>> model = PerceiverModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```

</div>

<h2 id="transformers.PerceiverTokenizer">PerceiverTokenizer</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverTokenizer</name><anchor>transformers.PerceiverTokenizer</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/tokenization_perceiver.py#L27</source><parameters>[{"name": "pad_token", "val": " = '[PAD]'"}, {"name": "bos_token", "val": " = '[BOS]'"}, {"name": "eos_token", "val": " = '[EOS]'"}, {"name": "mask_token", "val": " = '[MASK]'"}, {"name": "cls_token", "val": " = '[CLS]'"}, {"name": "sep_token", "val": " = '[SEP]'"}, {"name": "model_max_length", "val": " = 2048"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **pad_token** (`str`, *optional*, defaults to `"[PAD]"`) --
  The token used for padding, for example when batching sequences of different lengths.
- **bos_token** (`str`, *optional*, defaults to `"[BOS]"`) --
  The BOS token (reserved in the vocab, but not actually used).
- **eos_token** (`str`, *optional*, defaults to `"[EOS]"`) --
  The end of sequence token (reserved in the vocab, but not actually used).

  <Tip>

  When building a sequence using special tokens, this is not the token that is used for the end of sequence.
  The token used is the `sep_token`.

  </Tip>

- **mask_token** (`str`, *optional*, defaults to `"[MASK]"`) --
  The MASK token, useful for masked language modeling.
- **cls_token** (`str`, *optional*, defaults to `"[CLS]"`) --
  The CLS token (reserved in the vocab, but not actually used).
- **sep_token** (`str`, *optional*, defaults to `"[SEP]"`) --
  The separator token, which is used when building a sequence from two sequences.</paramsdesc><paramgroups>0</paramgroups></docstring>

Construct a Perceiver tokenizer. The Perceiver simply uses raw bytes utf-8 encoding.

This tokenizer inherits from [PreTrainedTokenizer](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizer) which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods.





<div class="docstring">
<docstring><name>\_\_call\_\_</name><anchor>transformers.PreTrainedTokenizerBase.__call__</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L2379</source><parameters>[{"name": "text", "val": ": typing.Union[str, typing.List[str], typing.List[typing.List[str]]]"}, {"name": "text_pair", "val": ": typing.Union[str, typing.List[str], typing.List[typing.List[str]], NoneType] = None"}, {"name": "add_special_tokens", "val": ": bool = True"}, {"name": "padding", "val": ": typing.Union[bool, str, transformers.file_utils.PaddingStrategy] = False"}, {"name": "truncation", "val": ": typing.Union[bool, str, transformers.tokenization_utils_base.TruncationStrategy] = False"}, {"name": "max_length", "val": ": typing.Optional[int] = None"}, {"name": "stride", "val": ": int = 0"}, {"name": "is_split_into_words", "val": ": bool = False"}, {"name": "pad_to_multiple_of", "val": ": typing.Optional[int] = None"}, {"name": "return_tensors", "val": ": typing.Union[str, transformers.file_utils.TensorType, NoneType] = None"}, {"name": "return_token_type_ids", "val": ": typing.Optional[bool] = None"}, {"name": "return_attention_mask", "val": ": typing.Optional[bool] = None"}, {"name": "return_overflowing_tokens", "val": ": bool = False"}, {"name": "return_special_tokens_mask", "val": ": bool = False"}, {"name": "return_offsets_mapping", "val": ": bool = False"}, {"name": "return_length", "val": ": bool = False"}, {"name": "verbose", "val": ": bool = True"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **text** (`str`, `List[str]`, `List[List[str]]`) --
  The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
  (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
  `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
- **text_pair** (`str`, `List[str]`, `List[List[str]]`) --
  The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
  (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
  `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).

- **add_special_tokens** (`bool`, *optional*, defaults to `True`) --
  Whether or not to encode the sequences with the special tokens relative to their model.
- **padding** (`bool`, `str` or [PaddingStrategy](/docs/transformers/pr_15592/en/internal/file_utils#transformers.file_utils.PaddingStrategy), *optional*, defaults to `False`) --
  Activates and controls padding. Accepts the following values:

  - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
    sequence if provided).
  - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided.
  - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
    lengths).
- **truncation** (`bool`, `str` or [TruncationStrategy](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.tokenization_utils_base.TruncationStrategy), *optional*, defaults to `False`) --
  Activates and controls truncation. Accepts the following values:

  - `True` or `'longest_first'`: Truncate to a maximum length specified with the argument `max_length` or
    to the maximum acceptable input length for the model if that argument is not provided. This will
    truncate token by token, removing a token from the longest sequence in the pair if a pair of
    sequences (or a batch of pairs) is provided.
  - `'only_first'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the first sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `'only_second'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
    greater than the model maximum admissible input size).
- **max_length** (`int`, *optional*) --
  Controls the maximum length to use by one of the truncation/padding parameters.

  If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
  is required by one of the truncation/padding parameters. If the model has no specific maximum input
  length (like XLNet) truncation/padding to a maximum length will be deactivated.
- **stride** (`int`, *optional*, defaults to 0) --
  If set to a number along with `max_length`, the overflowing tokens returned when
  `return_overflowing_tokens=True` will contain some tokens from the end of the truncated sequence
  returned to provide some overlap between truncated and overflowing sequences. The value of this
  argument defines the number of overlapping tokens.
- **is_split_into_words** (`bool`, *optional*, defaults to `False`) --
  Whether or not the input is already pre-tokenized (e.g., split into words). If set to `True`, the
  tokenizer assumes the input is already split into words (for instance, by splitting it on whitespace)
  which it will tokenize. This is useful for NER or token classification.
- **pad_to_multiple_of** (`int`, *optional*) --
  If set will pad the sequence to a multiple of the provided value. This is especially useful to enable
  the use of Tensor Cores on NVIDIA hardware with compute capability >= 7.5 (Volta).
- **return_tensors** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*) --
  If set, will return tensors instead of list of python integers. Acceptable values are:

  - `'tf'`: Return TensorFlow `tf.constant` objects.
  - `'pt'`: Return PyTorch `torch.Tensor` objects.
  - `'np'`: Return Numpy `np.ndarray` objects.

- **return_token_type_ids** (`bool`, *optional*) --
  Whether to return token type IDs. If left to the default, will return the token type IDs according to
  the specific tokenizer's default, defined by the `return_outputs` attribute.

  [What are token type IDs?](../glossary#token-type-ids)
- **return_attention_mask** (`bool`, *optional*) --
  Whether to return the attention mask. If left to the default, will return the attention mask according
  to the specific tokenizer's default, defined by the `return_outputs` attribute.

  [What are attention masks?](../glossary#attention-mask)
- **return_overflowing_tokens** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return overflowing token sequences. If a pair of sequences of input ids (or a batch
  of pairs) is provided with `truncation_strategy = longest_first` or `True`, an error is raised instead
  of returning overflowing tokens.
- **return_special_tokens_mask** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return special tokens mask information.
- **return_offsets_mapping** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return `(char_start, char_end)` for each token.

  This is only available on fast tokenizers inheriting from [PreTrainedTokenizerFast](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast), if using
  Python's tokenizer, this method will raise `NotImplementedError`.
- **return_length**  (`bool`, *optional*, defaults to `False`) --
  Whether or not to return the lengths of the encoded inputs.
- **verbose** (`bool`, *optional*, defaults to `True`) --
  Whether or not to print more information and warnings.
  **kwargs -- passed to the `self.tokenize()` method</paramsdesc><paramgroups>0</paramgroups><rettype>[BatchEncoding](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.BatchEncoding)</rettype><retdesc>A [BatchEncoding](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.BatchEncoding) with the following fields:

- **input_ids** -- List of token ids to be fed to a model.

  [What are input IDs?](../glossary#input-ids)

- **token_type_ids** -- List of token type ids to be fed to a model (when `return_token_type_ids=True` or
  if *"token_type_ids"* is in `self.model_input_names`).

  [What are token type IDs?](../glossary#token-type-ids)

- **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
  `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names`).

  [What are attention masks?](../glossary#attention-mask)

- **overflowing_tokens** -- List of overflowing tokens sequences (when a `max_length` is specified and
  `return_overflowing_tokens=True`).
- **num_truncated_tokens** -- Number of tokens truncated (when a `max_length` is specified and
  `return_overflowing_tokens=True`).
- **special_tokens_mask** -- List of 0s and 1s, with 1 specifying added special tokens and 0 specifying
  regular sequence tokens (when `add_special_tokens=True` and `return_special_tokens_mask=True`).
- **length** -- The length of the inputs (when `return_length=True`)</retdesc></docstring>

Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
sequences.








</div></div>

<h2 id="transformers.PerceiverFeatureExtractor">PerceiverFeatureExtractor</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverFeatureExtractor</name><anchor>transformers.PerceiverFeatureExtractor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/feature_extraction_perceiver.py#L37</source><parameters>[{"name": "do_center_crop", "val": " = True"}, {"name": "crop_size", "val": " = 256"}, {"name": "do_resize", "val": " = True"}, {"name": "size", "val": " = 224"}, {"name": "resample", "val": " = 3"}, {"name": "do_normalize", "val": " = True"}, {"name": "image_mean", "val": " = None"}, {"name": "image_std", "val": " = None"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **do_center_crop** (`bool`, *optional*, defaults to `True`) --
  Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
  image is padded with 0's and then center cropped.
- **crop_size** (`int`, *optional*, defaults to 256) --
  Desired output size when applying center-cropping. Only has an effect if `do_center_crop` is set to `True`.
- **do_resize** (`bool`, *optional*, defaults to `True`) --
  Whether to resize the input to a certain `size`.
- **size** (`int` or `Tuple(int)`, *optional*, defaults to 224) --
  Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
  integer is provided, then the input will be resized to (size, size). Only has an effect if `do_resize` is
  set to `True`.
- **resample** (`int`, *optional*, defaults to `PIL.Image.BICUBIC`) --
  An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`,
  `PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect
  if `do_resize` is set to `True`.
- **do_normalize** (`bool`, *optional*, defaults to `True`) --
  Whether or not to normalize the input with `image_mean` and `image_std`.
- **image_mean** (`List[int]`, defaults to `[0.485, 0.456, 0.406]`) --
  The sequence of means for each channel, to be used when normalizing images.
- **image_std** (`List[int]`, defaults to `[0.229, 0.224, 0.225]`) --
  The sequence of standard deviations for each channel, to be used when normalizing images.</paramsdesc><paramgroups>0</paramgroups></docstring>

Constructs a Perceiver feature extractor.

This feature extractor inherits from [ImageFeatureExtractionMixin](/docs/transformers/pr_15592/en/main_classes/feature_extractor#transformers.ImageFeatureExtractionMixin) which contains most of the main methods. Users
should refer to this superclass for more information regarding those methods.





<div class="docstring">
<docstring><name>\_\_call\_\_</name><anchor>transformers.PerceiverFeatureExtractor.__call__</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/feature_extraction_perceiver.py#L121</source><parameters>[{"name": "images", "val": ": typing.Union[PIL.Image.Image, numpy.ndarray, ForwardRef('torch.Tensor'), typing.List[PIL.Image.Image], typing.List[numpy.ndarray], typing.List[ForwardRef('torch.Tensor')]]"}, {"name": "return_tensors", "val": ": typing.Union[str, transformers.file_utils.TensorType, NoneType] = None"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **images** (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`) --
  The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
  tensor. In case of a NumPy array/PyTorch tensor, each image should be of shape (C, H, W), where C is a
  number of channels, H and W are image height and width.

- **return_tensors** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*, defaults to `'np'`) --
  If set, will return tensors of a particular framework. Acceptable values are:

  - `'tf'`: Return TensorFlow `tf.constant` objects.
  - `'pt'`: Return PyTorch `torch.Tensor` objects.
  - `'np'`: Return NumPy `np.ndarray` objects.
  - `'jax'`: Return JAX `jnp.ndarray` objects.</paramsdesc><paramgroups>0</paramgroups><rettype>[BatchFeature](/docs/transformers/pr_15592/en/main_classes/feature_extractor#transformers.BatchFeature)</rettype><retdesc>A [BatchFeature](/docs/transformers/pr_15592/en/main_classes/feature_extractor#transformers.BatchFeature) with the following fields:

- **pixel_values** -- Pixel values to be fed to a model, of shape (batch_size, num_channels, height,
  width).</retdesc></docstring>

Main method to prepare for the model one or several image(s).

<Tip warning=&amp;lcub;true}>

NumPy arrays and PyTorch tensors are converted to PIL images when resizing, so the most efficient is to pass
PIL images.

</Tip>








</div></div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverTextPreprocessor">PerceiverTextPreprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverTextPreprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverTextPreprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2767</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) --
  Model configuration.</paramsdesc><paramgroups>0</paramgroups></docstring>

Text preprocessing for Perceiver Encoder. Can be used to embed `inputs` and add positional encodings.

The dimensionality of the embeddings is determined by the `d_model` attribute of the configuration.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverImagePreprocessor">PerceiverImagePreprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverImagePreprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverImagePreprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2924</source><parameters>[{"name": "config", "val": ""}, {"name": "prep_type", "val": " = 'conv'"}, {"name": "spatial_downsample", "val": ": int = 4"}, {"name": "temporal_downsample", "val": ": int = 1"}, {"name": "position_encoding_type", "val": ": str = 'fourier'"}, {"name": "in_channels", "val": ": int = 3"}, {"name": "out_channels", "val": ": int = 64"}, {"name": "conv_after_patching", "val": ": bool = False"}, {"name": "conv_after_patching_in_channels", "val": ": int = 54"}, {"name": "conv2d_use_batchnorm", "val": ": bool = True"}, {"name": "concat_or_add_pos", "val": ": str = 'concat'"}, {"name": "project_pos_dim", "val": ": int = -1"}, {"name": "**position_encoding_kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([*PerceiverConfig*]) --
  Model configuration.
- **prep_type** (`str`, *optional*, defaults to `"conv"`) --
  Preprocessing type. Can be "conv1x1", "conv", "patches", "pixels".
- **spatial_downsample** (`int`, *optional*, defaults to 4) --
  Spatial downsampling factor.
- **temporal_downsample** (`int`, *optional*, defaults to 1) --
  Temporal downsampling factor (only relevant in case a time dimension is present).
- **position_encoding_type** (`str`, *optional*, defaults to `"fourier"`) --
  Position encoding type. Can be "fourier" or "trainable".
- **in_channels** (`int`, *optional*, defaults to 3) --
  Number of channels in the input.
- **out_channels** (`int`, *optional*, defaults to 64) --
  Number of channels in the output.
- **conv_after_patching** (`bool`, *optional*, defaults to `False`) --
  Whether to apply a convolutional layer after patching.
- **conv_after_patching_in_channels** (`int`, *optional*, defaults to 54) --
  Number of channels in the input of the convolutional layer after patching.
- **conv2d_use_batchnorm** (`bool`, *optional*, defaults to `True`) --
  Whether to use batch normalization in the convolutional layer.
- **concat_or_add_pos** (`str`, *optional*, defaults to `"concat"`) --
  How to concatenate the position encoding to the input. Can be "concat" or "add".
- **project_pos_dim** (`int`, *optional*, defaults to -1) --
  Dimension of the position encoding to project to. If -1, no projection is applied.
- ****position_encoding_kwargs** (`Dict`, *optional*) --
  Keyword arguments for the position encoding.</paramsdesc><paramgroups>0</paramgroups></docstring>

Image preprocessing for Perceiver Encoder.

Note: the *out_channels* argument refers to the output channels of a convolutional layer, if *prep_type* is set to
"conv1x1" or "conv". If one adds absolute position embeddings, one must make sure the *num_channels* of the
position encoding kwargs are set equal to the *out_channels*.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverOneHotPreprocessor">PerceiverOneHotPreprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverOneHotPreprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverOneHotPreprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L3153</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) --
  Model configuration.</paramsdesc><paramgroups>0</paramgroups></docstring>

One-hot preprocessor for Perceiver Encoder. Can be used to add a dummy index dimension to the input.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverAudioPreprocessor">PerceiverAudioPreprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverAudioPreprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverAudioPreprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L3179</source><parameters>[{"name": "config", "val": ""}, {"name": "prep_type", "val": ": str = 'patches'"}, {"name": "samples_per_patch", "val": ": int = 96"}, {"name": "position_encoding_type", "val": ": str = 'fourier'"}, {"name": "concat_or_add_pos", "val": ": str = 'concat'"}, {"name": "out_channels", "val": " = 64"}, {"name": "project_pos_dim", "val": " = -1"}, {"name": "**position_encoding_kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([*PerceiverConfig*]) --
  Model configuration.
- **prep_type** (`str`, *optional*, defaults to `"patches"`) --
  Preprocessor type to use. Only "patches" is supported.
- **samples_per_patch** (`int`, *optional*, defaults to 96) --
  Number of samples per patch.
- **position_encoding_type** (`str`, *optional*, defaults to `"fourier"`) --
  Type of position encoding to use. Can be "trainable" or "fourier".
- **concat_or_add_pos** (`str`, *optional*, defaults to `"concat"`) --
  How to concatenate the position encoding to the input. Can be "concat" or "add".
- **out_channels** (`int`, *optional*, defaults to 64) --
  Number of channels in the output.
- **project_pos_dim** (`int`, *optional*, defaults to -1) --
  Dimension of the position encoding to project to. If -1, no projection is applied.
- ****position_encoding_kwargs** (`Dict`, *optional*) --
  Keyword arguments for the position encoding.</paramsdesc><paramgroups>0</paramgroups></docstring>

Audio preprocessing for Perceiver Encoder.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPreprocessor">PerceiverMultimodalPreprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverMultimodalPreprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPreprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L3276</source><parameters>[{"name": "modalities", "val": ": typing.Mapping[str, typing.Callable[..., typing.Tuple[torch.Tensor, typing.Optional[torch.Tensor], torch.Tensor]]]"}, {"name": "mask_probs", "val": ": typing.Union[typing.Mapping[str, float], NoneType] = None"}, {"name": "min_padding_size", "val": ": int = 2"}]</parameters><paramsdesc>- **modalities** (`Dict[str, PreprocessorType]`) --
  Dict mapping modality name to preprocessor.
- **mask_probs** (`Dict[str, float]`) --
  Dict mapping modality name to masking probability of that modality.
- **min_padding_size** (`int`, *optional*, defaults to 2) --
  The minimum padding size for all modalities. The final output will have num_channels equal to the maximum
  channels across all modalities plus min_padding_size.</paramsdesc><paramgroups>0</paramgroups></docstring>

Multimodal preprocessing for Perceiver Encoder.

Inputs for each modality are preprocessed, then padded with trainable position embeddings to have the same number
of channels.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverProjectionDecoder">PerceiverProjectionDecoder</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverProjectionDecoder</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverProjectionDecoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2011</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) --
  Model configuration.</paramsdesc><paramgroups>0</paramgroups></docstring>

Baseline projection decoder (no cross-attention).




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverBasicDecoder">PerceiverBasicDecoder</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverBasicDecoder</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverBasicDecoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2035</source><parameters>[{"name": "config", "val": ""}, {"name": "output_num_channels", "val": ""}, {"name": "position_encoding_type", "val": " = 'trainable'"}, {"name": "output_index_dims", "val": " = None"}, {"name": "num_channels", "val": " = 128"}, {"name": "subsampled_index_dims", "val": " = None"}, {"name": "qk_channels", "val": " = None"}, {"name": "v_channels", "val": " = None"}, {"name": "num_heads", "val": " = 1"}, {"name": "widening_factor", "val": " = 1"}, {"name": "use_query_residual", "val": " = False"}, {"name": "concat_preprocessed_input", "val": " = False"}, {"name": "final_project", "val": " = True"}, {"name": "position_encoding_only", "val": " = False"}, {"name": "**position_encoding_kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([*PerceiverConfig*]) --
  Model configuration.
- **output_num_channels** (`int`, *optional*) --
  The number of channels in the output. Will only be used in case *final_project* is set to `True`.
- **position_encoding_type** (`str`, *optional*, defaults to "trainable") --
  The type of position encoding to use. Can be either "trainable", "fourier", or "none".
- **output_index_dims** (`int`, *optional*) --
  The number of dimensions of the output queries. Ignored if 'position_encoding_type' == 'none'.
- **num_channels** (`int`, *optional*) --
  The number of channels of the decoder queries. Ignored if 'position_encoding_type' == 'none'.
- **qk_channels** (`int`, *optional*) --
  The number of channels of the queries and keys in the cross-attention layer.
- **v_channels** (`int`, *optional*, defaults to 128) --
  The number of channels of the values in the cross-attention layer.
- **num_heads** (`int`, *optional*, defaults to 1) --
  The number of attention heads in the cross-attention layer.
- **widening_factor** (`int`, *optional*, defaults to 1) --
  The widening factor of the cross-attention layer.
- **use_query_residual** (`bool`, *optional*, defaults to `False`) --
  Whether to use a residual connection between the query and the output of the cross-attention layer.
- **concat_preprocessed_input** (`bool`, *optional*, defaults to `False`) --
  Whether to concatenate the preprocessed input to the query.
- **final_project** (`bool`, *optional*, defaults to `True`) --
  Whether to project the output of the cross-attention layer to a target dimension.
- **position_encoding_only** (`bool`, *optional*, defaults to `False`) --
  Whether to only use this class to define output queries.</paramsdesc><paramgroups>0</paramgroups></docstring>

Cross-attention-based decoder. This class can be used to decode the final hidden states of the latents using a
cross-attention operation, in which the latents produce keys and values.

The shape of the output of this class depends on how one defines the output queries (also called decoder queries).




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverClassificationDecoder">PerceiverClassificationDecoder</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverClassificationDecoder</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverClassificationDecoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2215</source><parameters>[{"name": "config", "val": ""}, {"name": "**decoder_kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) --
  Model configuration.</paramsdesc><paramgroups>0</paramgroups></docstring>

Cross-attention based classification decoder. Light-weight wrapper of `PerceiverBasicDecoder` for logit output.
Will turn the output of the Perceiver encoder which is of shape (batch_size, num_latents, d_latents) to a tensor of
shape (batch_size, num_labels). The queries are of shape (batch_size, 1, num_labels).




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverOpticalFlowDecoder">PerceiverOpticalFlowDecoder</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverOpticalFlowDecoder</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverOpticalFlowDecoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2255</source><parameters>[{"name": "config", "val": ""}, {"name": "output_image_shape", "val": ""}, {"name": "output_num_channels", "val": " = 2"}, {"name": "rescale_factor", "val": " = 100.0"}, {"name": "**decoder_kwargs", "val": ""}]</parameters></docstring>
Cross-attention based optical flow decoder.

</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverBasicVideoAutoencodingDecoder">PerceiverBasicVideoAutoencodingDecoder</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverBasicVideoAutoencodingDecoder</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverBasicVideoAutoencodingDecoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2284</source><parameters>[{"name": "config", "val": ""}, {"name": "output_shape", "val": ""}, {"name": "position_encoding_type", "val": ""}, {"name": "**decoder_kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([*PerceiverConfig*]) --
  Model configuration.
- **output_shape** (`List[int]`) --
  Shape of the output as (batch_size, num_frames, height, width), excluding the channel dimension.
- **position_encoding_type** (`str`) --
  The type of position encoding to use. Can be either "trainable", "fourier", or "none".</paramsdesc><paramgroups>0</paramgroups></docstring>

Cross-attention based video-autoencoding decoder. Light-weight wrapper of [*PerceiverBasicDecoder*] with video
reshaping logic.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalDecoder">PerceiverMultimodalDecoder</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverMultimodalDecoder</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalDecoder</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2357</source><parameters>[{"name": "config", "val": ""}, {"name": "modalities", "val": ""}, {"name": "num_outputs", "val": ""}, {"name": "output_num_channels", "val": ""}, {"name": "min_padding_size", "val": " = 2"}, {"name": "subsampled_index_dims", "val": " = None"}, {"name": "**decoder_kwargs", "val": ""}]</parameters><paramsdesc>- **config** ([*PerceiverConfig*]) --
  Model configuration.
- **modalities** (`Dict[str, PerceiverAbstractDecoder]`) --
  Dictionary mapping modality name to the decoder of that modality.
- **num_outputs** (`int`) --
  The number of outputs of the decoder.
- **output_num_channels** (`int`) --
  The number of channels in the output.
- **min_padding_size** (`int`, *optional*, defaults to 2) --
  The minimum padding size for all modalities. The final output will have num_channels equal to the maximum
  channels across all modalities plus min_padding_size.
- **subsampled_index_dims** (`Dict[str, PerceiverAbstractDecoder]`, *optional*) --
  Dictionary mapping modality name to the subsampled index dimensions to use for the decoder query of that
  modality.</paramsdesc><paramgroups>0</paramgroups></docstring>

Multimodal decoding by composing uni-modal decoders. The *modalities* argument of the constructor is a dictionary
mapping modality name to the decoder of that modality. That decoder will be used to construct queries for that
modality. Modality-specific queries are padded with trainable modality-specific parameters, after which they are
concatenated along the time dimension.

Next, there is a shared cross attention operation across all modalities.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverProjectionPostprocessor">PerceiverProjectionPostprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverProjectionPostprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverProjectionPostprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2903</source><parameters>[{"name": "in_channels", "val": ""}, {"name": "out_channels", "val": ""}]</parameters><paramsdesc>- **in_channels** (`int`) --
  Number of channels in the input.
- **out_channels** (`int`) --
  Number of channels in the output.</paramsdesc><paramgroups>0</paramgroups></docstring>

Projection postprocessing for Perceiver. Can be used to project the channels of the decoder output to a lower
dimension.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverAudioPostprocessor">PerceiverAudioPostprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverAudioPostprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverAudioPostprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2875</source><parameters>[{"name": "config", "val": ""}, {"name": "in_channels", "val": ""}, {"name": "postproc_type", "val": ": str = 'patches'"}]</parameters><paramsdesc>- **config** ([*PerceiverConfig*]) --
  Model configuration.
- **in_channels** (`int`) --
  Number of channels in the input.
- **postproc_type** (`str`, *optional*, defaults to `"patches"`) --
  Postprocessor type to use. Currently, only "patches" is supported.</paramsdesc><paramgroups>0</paramgroups></docstring>

Audio postprocessing for Perceiver. Can be used to convert the decoder output to audio features.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverClassificationPostprocessor">PerceiverClassificationPostprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverClassificationPostprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverClassificationPostprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2855</source><parameters>[{"name": "config", "val": ""}, {"name": "in_channels", "val": ""}]</parameters><paramsdesc>- **config** ([*PerceiverConfig*]) --
  Model configuration.
- **in_channels** (`int`) --
  Number of channels in the input.</paramsdesc><paramgroups>0</paramgroups></docstring>

Classification postprocessing for Perceiver. Can be used to convert the decoder output to classification logits.




</div>

<h2 id="transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPostprocessor">PerceiverMultimodalPostprocessor</h2>

<div class="docstring">

<docstring><name>class transformers.models.perceiver.modeling\_perceiver.PerceiverMultimodalPostprocessor</name><anchor>transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPostprocessor</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L2821</source><parameters>[{"name": "modalities", "val": ": typing.Mapping[str, typing.Callable[..., typing.Any]]"}, {"name": "input_is_dict", "val": ": bool = False"}]</parameters><paramsdesc>- **modalities** (`Dict[str, PostprocessorType]`) --
  Dictionary mapping modality name to postprocessor class for that modality.
- **input_is_dict** (`bool`, *optional*, defaults to `False`) --
  If True, input is assumed to be dictionary structured, and outputs keep the same dictionary shape. If
  False, input is a tensor which is sliced up during postprocessing by *modality_sizes*.</paramsdesc><paramgroups>0</paramgroups></docstring>

Multimodal postprocessing for Perceiver. Can be used to combine modality-specific postprocessors into a single
postprocessor.




</div>

<h2 id="transformers.PerceiverModel">PerceiverModel</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverModel</name><anchor>transformers.PerceiverModel</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L721</source><parameters>[{"name": "config", "val": ""}, {"name": "decoder", "val": " = None"}, {"name": "input_preprocessor", "val": ": typing.Callable[..., typing.Tuple[torch.Tensor, typing.Optional[torch.Tensor], torch.Tensor]] = None"}, {"name": "output_postprocessor", "val": ": typing.Callable[..., typing.Any] = None"}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.
- **decoder** (*DecoderType*, *optional*) --
  Optional decoder to use to decode the latent representation of the encoder. Examples include
  *transformers.models.perceiver.modeling_perceiver.PerceiverBasicDecoder*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverClassificationDecoder*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalDecoder*.
- **input_preprocessor** (*PreprocessorType*, *optional*) --
  Optional input preprocessor to use. Examples include
  *transformers.models.perceiver.modeling_perceiver.PerceiverImagePreprocessor*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverAudioPreprocessor*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverTextPreprocessor*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPreprocessor*.
- **output_postprocessor** (*PostprocessorType*, *optional*) --
  Optional output postprocessor to use. Examples include
  *transformers.models.perceiver.modeling_perceiver.PerceiverImagePostprocessor*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverAudioPostprocessor*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverClassificationPostprocessor*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverProjectionPostprocessor*,
  *transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPostprocessor*.

- **Note** that you can define your own decoders, preprocessors and/or postprocessors to fit your use-case. --</paramsdesc><paramgroups>0</paramgroups></docstring>
The Perceiver: a scalable, fully attentional architecture.
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.PerceiverModel.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L757</source><parameters>[{"name": "inputs", "val": ""}, {"name": "attention_mask", "val": " = None"}, {"name": "subsampled_output_points", "val": " = None"}, {"name": "head_mask", "val": " = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "return_dict", "val": " = None"}]</parameters><paramsdesc>- **inputs** (`torch.FloatTensor`) --
  Inputs to the perceiver. Can be anything: images, text, audio, video, etc.
- **attention_mask** (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **head_mask** (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*) --
  Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

  - 1 indicates the head is **not masked**,
  - 0 indicates the head is **masked**.

- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.perceiver.modeling_perceiver.PerceiverModelOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverModelOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.perceiver.modeling_perceiver.PerceiverModelOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverModelOutput) or a tuple of
`torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
elements depending on the configuration ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) and inputs.

- **logits** (`torch.FloatTensor` of shape `(batch_size, num_labels)`) -- Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **last_hidden_state** (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`) -- Sequence of hidden-states at the output of the last layer of the model.
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</retdesc></docstring>
The [PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel) forward method, overrides the `__call__` special method.

<Tip>

Although the recipe for forward pass needs to be defined within this function, one should call the `Module`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.

</Tip>







Examples:

```python
>>> from transformers import PerceiverConfig, PerceiverTokenizer, PerceiverFeatureExtractor, PerceiverModel
>>> from transformers.models.perceiver.modeling_perceiver import (
...     PerceiverTextPreprocessor,
...     PerceiverImagePreprocessor,
...     PerceiverClassificationDecoder,
... )
>>> import torch
>>> import requests
>>> from PIL import Image

>>> # EXAMPLE 1: using the Perceiver to classify texts
>>> # - we define a TextPreprocessor, which can be used to embed tokens
>>> # - we define a ClassificationDecoder, which can be used to decode the
>>> # final hidden states of the latents to classification logits
>>> # using trainable position embeddings
>>> config = PerceiverConfig()
>>> preprocessor = PerceiverTextPreprocessor(config)
>>> decoder = PerceiverClassificationDecoder(
...     config,
...     num_channels=config.d_latents,
...     trainable_position_encoding_kwargs=dict(num_channels=config.d_latents, index_dims=1),
...     use_query_residual=True,
... )
>>> model = PerceiverModel(config, input_preprocessor=preprocessor, decoder=decoder)

>>> # you can then do a forward pass as follows:
>>> tokenizer = PerceiverTokenizer()
>>> text = "hello world"
>>> inputs = tokenizer(text, return_tensors="pt").input_ids

>>> with torch.no_grad():
...     outputs = model(inputs=inputs)
>>> logits = outputs.logits

>>> # to train, one can train the model using standard cross-entropy:
>>> criterion = torch.nn.CrossEntropyLoss()

>>> labels = torch.tensor([1])
>>> loss = criterion(logits, labels)

>>> # EXAMPLE 2: using the Perceiver to classify images
>>> # - we define an ImagePreprocessor, which can be used to embed images
>>> preprocessor = PerceiverImagePreprocessor(
...     config,
...     prep_type="conv1x1",
...     spatial_downsample=1,
...     out_channels=256,
...     position_encoding_type="trainable",
...     concat_or_add_pos="concat",
...     project_pos_dim=256,
...     trainable_position_encoding_kwargs=dict(
...         num_channels=256,
...         index_dims=config.image_size**2,
...     ),
... )

>>> model = PerceiverModel(
...     config,
...     input_preprocessor=preprocessor,
...     decoder=PerceiverClassificationDecoder(
...         config,
...         num_channels=config.d_latents,
...         trainable_position_encoding_kwargs=dict(num_channels=config.d_latents, index_dims=1),
...         use_query_residual=True,
...     ),
... )

>>> # you can then do a forward pass as follows:
>>> feature_extractor = PerceiverFeatureExtractor()
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> inputs = feature_extractor(image, return_tensors="pt").pixel_values

>>> with torch.no_grad():
...     outputs = model(inputs=inputs)
>>> logits = outputs.logits

>>> # to train, one can train the model using standard cross-entropy:
>>> criterion = torch.nn.CrossEntropyLoss()

>>> labels = torch.tensor([1])
>>> loss = criterion(logits, labels)
```

</div></div>

<h2 id="transformers.PerceiverForMaskedLM">PerceiverForMaskedLM</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverForMaskedLM</name><anchor>transformers.PerceiverForMaskedLM</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L954</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>
Example use of Perceiver for masked language modeling.
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.PerceiverForMaskedLM.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L985</source><parameters>[{"name": "inputs", "val": " = None"}, {"name": "attention_mask", "val": " = None"}, {"name": "head_mask", "val": " = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "labels", "val": " = None"}, {"name": "return_dict", "val": " = None"}, {"name": "input_ids", "val": " = None"}]</parameters><paramsdesc>- **inputs** (`torch.FloatTensor`) --
  Inputs to the perceiver. Can be anything: images, text, audio, video, etc.
- **attention_mask** (`torch.FloatTensor` of shape `batch_size, sequence_length`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **head_mask** (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*) --
  Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

  - 1 indicates the head is **not masked**,
  - 0 indicates the head is **masked**.

- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.

- **labels** (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*) --
  Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
  config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
  loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.perceiver.modeling_perceiver.PerceiverMaskedLMOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverMaskedLMOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.perceiver.modeling_perceiver.PerceiverMaskedLMOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverMaskedLMOutput) or a tuple of
`torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
elements depending on the configuration ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) and inputs.

- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) -- Masked language modeling (MLM) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`) -- Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, num_latents,
  num_latents)`. Attentions weights after the attention softmax, used to compute the weighted average in the
  self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</retdesc></docstring>
The [PerceiverForMaskedLM](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForMaskedLM) forward method, overrides the `__call__` special method.

<Tip>

Although the recipe for forward pass needs to be defined within this function, one should call the `Module`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.

</Tip>







Examples:

```python
>>> from transformers import PerceiverTokenizer, PerceiverForMaskedLM
>>> import torch

>>> tokenizer = PerceiverTokenizer.from_pretrained("deepmind/language-perceiver")
>>> model = PerceiverForMaskedLM.from_pretrained("deepmind/language-perceiver")

>>> # training
>>> text = "This is an incomplete sentence where some words are missing."
>>> inputs = tokenizer(text, padding="max_length", return_tensors="pt")
>>> # mask " missing."
>>> inputs["input_ids"][0, 52:61] = tokenizer.mask_token_id
>>> labels = tokenizer(text, padding="max_length", return_tensors="pt").input_ids

>>> outputs = model(**inputs, labels=labels)
>>> loss = outputs.loss
>>> logits = outputs.logits

>>> # inference
>>> text = "This is an incomplete sentence where some words are missing."
>>> encoding = tokenizer(text, padding="max_length", return_tensors="pt")

>>> # mask bytes corresponding to " missing.". Note that the model performs much better if the masked span starts with a space.
>>> encoding["input_ids"][0, 52:61] = tokenizer.mask_token_id

>>> # forward pass
>>> with torch.no_grad():
...     outputs = model(**encoding)
>>> logits = outputs.logits

>>> masked_tokens_predictions = logits[0, 52:61].argmax(dim=-1).tolist()
>>> tokenizer.decode(masked_tokens_predictions)
' missing.'
```

</div></div>

<h2 id="transformers.PerceiverForSequenceClassification">PerceiverForSequenceClassification</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverForSequenceClassification</name><anchor>transformers.PerceiverForSequenceClassification</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1081</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>
Example use of Perceiver for text classification.
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.PerceiverForSequenceClassification.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1102</source><parameters>[{"name": "inputs", "val": " = None"}, {"name": "attention_mask", "val": " = None"}, {"name": "head_mask", "val": " = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "labels", "val": " = None"}, {"name": "return_dict", "val": " = None"}, {"name": "input_ids", "val": " = None"}]</parameters><paramsdesc>- **inputs** (`torch.FloatTensor`) --
  Inputs to the perceiver. Can be anything: images, text, audio, video, etc.
- **attention_mask** (`torch.FloatTensor` of shape `batch_size, sequence_length`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **head_mask** (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*) --
  Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

  - 1 indicates the head is **not masked**,
  - 0 indicates the head is **masked**.

- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.

- **labels** (`torch.LongTensor` of shape `(batch_size,)`, *optional*) --
  Labels for computing the classification/regression loss. Indices should be in `[0, ..., config.num_labels -
  1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If `config.num_labels >
  1` a classification loss is computed (Cross-Entropy).</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or a tuple of
`torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
elements depending on the configuration ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) and inputs.

- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) -- Classification (or regression if config.num_labels==1) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`) -- Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</retdesc></docstring>
The [PerceiverForSequenceClassification](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForSequenceClassification) forward method, overrides the `__call__` special method.

<Tip>

Although the recipe for forward pass needs to be defined within this function, one should call the `Module`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.

</Tip>







Examples:

```python
>>> from transformers import PerceiverTokenizer, PerceiverForSequenceClassification

>>> tokenizer = PerceiverTokenizer.from_pretrained("deepmind/language-perceiver")
>>> model = PerceiverForSequenceClassification.from_pretrained("deepmind/language-perceiver")

>>> text = "hello world"
>>> inputs = tokenizer(text, return_tensors="pt").input_ids
>>> outputs = model(inputs=inputs)
>>> logits = outputs.logits
```

</div></div>

<h2 id="transformers.PerceiverForImageClassificationLearned">PerceiverForImageClassificationLearned</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverForImageClassificationLearned</name><anchor>transformers.PerceiverForImageClassificationLearned</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1204</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>

Example use of Perceiver for image classification, for tasks such as ImageNet.

This model uses learned position embeddings. In other words, this model is not given any privileged information about
the structure of images. As shown in the paper, this model can achieve a top-1 accuracy of 72.7 on ImageNet.

[PerceiverForImageClassificationLearned](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForImageClassificationLearned) uses [PerceiverImagePreprocessor](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverImagePreprocessor)
(with `prep_type="conv1x1"`) to preprocess the input images, and
[PerceiverClassificationDecoder](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassificationDecoder) to decode the latent representation of
[PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel) into classification logits.

This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.PerceiverForImageClassificationLearned.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1235</source><parameters>[{"name": "inputs", "val": " = None"}, {"name": "attention_mask", "val": " = None"}, {"name": "head_mask", "val": " = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "labels", "val": " = None"}, {"name": "return_dict", "val": " = None"}, {"name": "pixel_values", "val": " = None"}]</parameters><paramsdesc>- **inputs** (`torch.FloatTensor`) --
  Inputs to the perceiver. Can be anything: images, text, audio, video, etc.
- **attention_mask** (`torch.FloatTensor` of shape `batch_size, sequence_length`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **head_mask** (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*) --
  Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

  - 1 indicates the head is **not masked**,
  - 0 indicates the head is **masked**.

- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.

- **labels** (`torch.LongTensor` of shape `(batch_size,)`, *optional*) --
  Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
  config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
  `config.num_labels > 1` a classification loss is computed (Cross-Entropy).</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or a tuple of
`torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
elements depending on the configuration ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) and inputs.

- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) -- Classification (or regression if config.num_labels==1) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`) -- Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</retdesc></docstring>
The [PerceiverForImageClassificationLearned](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForImageClassificationLearned) forward method, overrides the `__call__` special method.

<Tip>

Although the recipe for forward pass needs to be defined within this function, one should call the `Module`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.

</Tip>







Examples:

```python
>>> from transformers import PerceiverFeatureExtractor, PerceiverForImageClassificationLearned
>>> from PIL import Image
>>> import requests

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)

>>> feature_extractor = PerceiverFeatureExtractor.from_pretrained("deepmind/vision-perceiver-learned")
>>> model = PerceiverForImageClassificationLearned.from_pretrained("deepmind/vision-perceiver-learned")

>>> inputs = feature_extractor(images=image, return_tensors="pt").pixel_values
>>> outputs = model(inputs=inputs)
>>> logits = outputs.logits
>>> # model predicts one of the 1000 ImageNet classes
>>> predicted_class_idx = logits.argmax(-1).item()
>>> print("Predicted class:", model.config.id2label[predicted_class_idx])
```

</div></div>

<h2 id="transformers.PerceiverForImageClassificationFourier">PerceiverForImageClassificationFourier</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverForImageClassificationFourier</name><anchor>transformers.PerceiverForImageClassificationFourier</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1343</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>

Example use of Perceiver for image classification, for tasks such as ImageNet.

This model uses fixed 2D Fourier position embeddings. As shown in the paper, this model can achieve a top-1 accuracy of
79.0 on ImageNet, and 84.5 when pre-trained on a large-scale dataset (i.e. JFT).

[PerceiverForImageClassificationLearned](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForImageClassificationLearned) uses [PerceiverImagePreprocessor](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverImagePreprocessor)
(with `prep_type="pixels"`) to preprocess the input images, and
[PerceiverClassificationDecoder](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassificationDecoder) to decode the latent representation of
[PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel) into classification logits.

This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.PerceiverForImageClassificationFourier.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1372</source><parameters>[{"name": "inputs", "val": " = None"}, {"name": "attention_mask", "val": " = None"}, {"name": "head_mask", "val": " = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "labels", "val": " = None"}, {"name": "return_dict", "val": " = None"}, {"name": "pixel_values", "val": " = None"}]</parameters><paramsdesc>- **inputs** (`torch.FloatTensor`) --
  Inputs to the perceiver. Can be anything: images, text, audio, video, etc.
- **attention_mask** (`torch.FloatTensor` of shape `batch_size, sequence_length`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **head_mask** (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*) --
  Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

  - 1 indicates the head is **not masked**,
  - 0 indicates the head is **masked**.

- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.

- **labels** (`torch.LongTensor` of shape `(batch_size,)`, *optional*) --
  Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
  config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
  `config.num_labels > 1` a classification loss is computed (Cross-Entropy).</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or a tuple of
`torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
elements depending on the configuration ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) and inputs.

- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) -- Classification (or regression if config.num_labels==1) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`) -- Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</retdesc></docstring>
The [PerceiverForImageClassificationFourier](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForImageClassificationFourier) forward method, overrides the `__call__` special method.

<Tip>

Although the recipe for forward pass needs to be defined within this function, one should call the `Module`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.

</Tip>







Examples:

```python
>>> from transformers import PerceiverFeatureExtractor, PerceiverForImageClassificationFourier
>>> from PIL import Image
>>> import requests

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)

>>> feature_extractor = PerceiverFeatureExtractor.from_pretrained("deepmind/vision-perceiver-fourier")
>>> model = PerceiverForImageClassificationFourier.from_pretrained("deepmind/vision-perceiver-fourier")

>>> inputs = feature_extractor(images=image, return_tensors="pt").pixel_values
>>> outputs = model(inputs=inputs)
>>> logits = outputs.logits
>>> # model predicts one of the 1000 ImageNet classes
>>> predicted_class_idx = logits.argmax(-1).item()
>>> print("Predicted class:", model.config.id2label[predicted_class_idx])
```

</div></div>

<h2 id="transformers.PerceiverForImageClassificationConvProcessing">PerceiverForImageClassificationConvProcessing</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverForImageClassificationConvProcessing</name><anchor>transformers.PerceiverForImageClassificationConvProcessing</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1479</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>

Example use of Perceiver for image classification, for tasks such as ImageNet.

This model uses a 2D conv+maxpool preprocessing network. As shown in the paper, this model can achieve a top-1 accuracy
of 82.1 on ImageNet.

[PerceiverForImageClassificationLearned](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForImageClassificationLearned) uses [PerceiverImagePreprocessor](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverImagePreprocessor)
(with `prep_type="conv"`) to preprocess the input images, and
[PerceiverClassificationDecoder](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassificationDecoder) to decode the latent representation of
[PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel) into classification logits.

This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.PerceiverForImageClassificationConvProcessing.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1509</source><parameters>[{"name": "inputs", "val": " = None"}, {"name": "attention_mask", "val": " = None"}, {"name": "head_mask", "val": " = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "labels", "val": " = None"}, {"name": "return_dict", "val": " = None"}, {"name": "pixel_values", "val": " = None"}]</parameters><paramsdesc>- **inputs** (`torch.FloatTensor`) --
  Inputs to the perceiver. Can be anything: images, text, audio, video, etc.
- **attention_mask** (`torch.FloatTensor` of shape `batch_size, sequence_length`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **head_mask** (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*) --
  Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

  - 1 indicates the head is **not masked**,
  - 0 indicates the head is **masked**.

- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.

- **labels** (`torch.LongTensor` of shape `(batch_size,)`, *optional*) --
  Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
  config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
  `config.num_labels > 1` a classification loss is computed (Cross-Entropy).</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or a tuple of
`torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
elements depending on the configuration ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) and inputs.

- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) -- Classification (or regression if config.num_labels==1) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`) -- Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</retdesc></docstring>
The [PerceiverForImageClassificationConvProcessing](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForImageClassificationConvProcessing) forward method, overrides the `__call__` special method.

<Tip>

Although the recipe for forward pass needs to be defined within this function, one should call the `Module`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.

</Tip>







Examples:

```python
>>> from transformers import PerceiverFeatureExtractor, PerceiverForImageClassificationConvProcessing
>>> from PIL import Image
>>> import requests

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)

>>> feature_extractor = PerceiverFeatureExtractor.from_pretrained("deepmind/vision-perceiver-conv")
>>> model = PerceiverForImageClassificationConvProcessing.from_pretrained("deepmind/vision-perceiver-conv")

>>> inputs = feature_extractor(images=image, return_tensors="pt").pixel_values
>>> outputs = model(inputs=inputs)
>>> logits = outputs.logits
>>> # model predicts one of the 1000 ImageNet classes
>>> predicted_class_idx = logits.argmax(-1).item()
>>> print("Predicted class:", model.config.id2label[predicted_class_idx])
```

</div></div>

<h2 id="transformers.PerceiverForOpticalFlow">PerceiverForOpticalFlow</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverForOpticalFlow</name><anchor>transformers.PerceiverForOpticalFlow</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1616</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>

Example use of Perceiver for optical flow, for tasks such as Sintel and KITTI. [PerceiverForOpticalFlow](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForOpticalFlow) uses
[PerceiverImagePreprocessor](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverImagePreprocessor) (with *prep_type="patches"*) to preprocess the
input images, and [PerceiverOpticalFlowDecoder](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverOpticalFlowDecoder) to decode the latent
representation of [PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel).

As input, one concatenates 2 subsequent frames along the channel dimension and extract a 3 x 3 patch around each pixel
(leading to 3 x 3 x 3 x 2 = 54 values for each pixel). Fixed Fourier position encodings are used to encode the position
of each pixel in the patch. Next, one applies the Perceiver encoder. To decode, one queries the latent representation
using the same encoding used for the input.

This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.PerceiverForOpticalFlow.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1663</source><parameters>[{"name": "inputs", "val": " = None"}, {"name": "attention_mask", "val": " = None"}, {"name": "head_mask", "val": " = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "labels", "val": " = None"}, {"name": "return_dict", "val": " = None"}]</parameters><paramsdesc>- **inputs** (`torch.FloatTensor`) --
  Inputs to the perceiver. Can be anything: images, text, audio, video, etc.
- **attention_mask** (`torch.FloatTensor` of shape `batch_size, sequence_length`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **head_mask** (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*) --
  Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

  - 1 indicates the head is **not masked**,
  - 0 indicates the head is **masked**.

- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.

- **labels** (`torch.LongTensor` of shape `(batch_size,)`, *optional*) --
  Labels for computing the optical flow loss. Indices should be in `[0, ..., config.num_labels - 1]`.</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or a tuple of
`torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
elements depending on the configuration ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) and inputs.

- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) -- Classification (or regression if config.num_labels==1) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`) -- Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</retdesc></docstring>
The [PerceiverForOpticalFlow](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForOpticalFlow) forward method, overrides the `__call__` special method.

<Tip>

Although the recipe for forward pass needs to be defined within this function, one should call the `Module`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.

</Tip>







Examples:

```python
>>> from transformers import PerceiverForOpticalFlow
>>> import torch

>>> model = PerceiverForOpticalFlow.from_pretrained("deepmind/optical-flow-perceiver")

>>> # in the Perceiver IO paper, the authors extract a 3 x 3 patch around each pixel,
>>> # leading to 3 x 3 x 3 = 27 values for each pixel (as each pixel also has 3 color channels)
>>> # patches have shape (batch_size, num_frames, num_channels, height, width)
>>> # the authors train on resolutions of 368 x 496
>>> patches = torch.randn(1, 2, 27, 368, 496)
>>> outputs = model(inputs=patches)
>>> logits = outputs.logits
```

</div></div>

<h2 id="transformers.PerceiverForMultimodalAutoencoding">PerceiverForMultimodalAutoencoding</h2>

<div class="docstring">

<docstring><name>class transformers.PerceiverForMultimodalAutoencoding</name><anchor>transformers.PerceiverForMultimodalAutoencoding</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1756</source><parameters>[{"name": "config", "val": ""}]</parameters><paramsdesc>- **config** ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) -- Model configuration class with all the parameters of the model.
  Initializing with a config file does not load the weights associated with the model, only the
  configuration. Check out the [from_pretrained()](/docs/transformers/pr_15592/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.</paramsdesc><paramgroups>0</paramgroups></docstring>

Example use of Perceiver for multimodal (video) autoencoding, for tasks such as Kinetics-700.

[PerceiverForMultimodalAutoencoding](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForMultimodalAutoencoding) uses [PerceiverMultimodalPreprocessor](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalPreprocessor) to
preprocess the 3 modalities: images, audio and class labels. This preprocessor uses modality-specific preprocessors to
preprocess every modality separately, after which they are concatenated. Trainable position embeddings are used to pad
each modality to the same number of channels to make concatenation along the time dimension possible. Next, one applies
the Perceiver encoder.

[PerceiverMultimodalDecoder](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalDecoder) is used to decode the latent representation of
[PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel). This decoder uses each modality-specific decoder to construct queries. The decoder queries are
created based on the inputs after preprocessing. However, autoencoding an entire video in a single forward pass is
computationally infeasible, hence one only uses parts of the decoder queries to do cross-attention with the latent
representation. This is determined by the subsampled indices for each modality, which can be provided as additional
input to the forward pass of [PerceiverForMultimodalAutoencoding](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForMultimodalAutoencoding).

[PerceiverMultimodalDecoder](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverMultimodalDecoder) also pads the decoder queries of the different
modalities to the same number of channels, in order to concatenate them along the time dimension. Next, cross-attention
is performed with the latent representation of [PerceiverModel](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverModel).

Finally, `PerceiverMultiModalPostprocessor` is used to turn this tensor into an
actual video. It first splits up the output into the different modalities, and then applies the respective
postprocessor for each modality.

Note that, by masking the classification label during evaluation (i.e. simply providing a tensor of zeros for the
"label" modality), this auto-encoding model becomes a Kinetics 700 video classifier.

This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.





<div class="docstring">
<docstring><name>forward</name><anchor>transformers.PerceiverForMultimodalAutoencoding.forward</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/models/perceiver/modeling_perceiver.py#L1872</source><parameters>[{"name": "inputs", "val": " = None"}, {"name": "attention_mask", "val": " = None"}, {"name": "subsampled_output_points", "val": " = None"}, {"name": "head_mask", "val": " = None"}, {"name": "output_attentions", "val": " = None"}, {"name": "output_hidden_states", "val": " = None"}, {"name": "labels", "val": " = None"}, {"name": "return_dict", "val": " = None"}]</parameters><paramsdesc>- **inputs** (`torch.FloatTensor`) --
  Inputs to the perceiver. Can be anything: images, text, audio, video, etc.
- **attention_mask** (`torch.FloatTensor` of shape `batch_size, sequence_length`, *optional*) --
  Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

  - 1 for tokens that are **not masked**,
  - 0 for tokens that are **masked**.

  [What are attention masks?](../glossary#attention-mask)
- **head_mask** (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*) --
  Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

  - 1 indicates the head is **not masked**,
  - 0 indicates the head is **masked**.

- **output_attentions** (`bool`, *optional*) --
  Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
  tensors for more detail.
- **output_hidden_states** (`bool`, *optional*) --
  Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
  more detail.
- **return_dict** (`bool`, *optional*) --
  Whether or not to return a [ModelOutput](/docs/transformers/pr_15592/en/main_classes/output#transformers.file_utils.ModelOutput) instead of a plain tuple.

- **labels** (`torch.LongTensor` of shape `(batch_size,)`, *optional*) --
  Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
  config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
  `config.num_labels > 1` a classification loss is computed (Cross-Entropy).</paramsdesc><paramgroups>0</paramgroups><rettype>[transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or `tuple(torch.FloatTensor)`</rettype><retdesc>A [transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.models.perceiver.modeling_perceiver.PerceiverClassifierOutput) or a tuple of
`torch.FloatTensor` (if `return_dict=False` is passed or when `config.return_dict=False`) comprising various
elements depending on the configuration ([PerceiverConfig](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverConfig)) and inputs.

- **loss** (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) -- Classification (or regression if config.num_labels==1) loss.
- **logits** (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`) -- Classification (or regression if config.num_labels==1) scores (before SoftMax).
- **hidden_states** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`) -- Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
  shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
  plus the initial embedding outputs.
- **attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
  the self-attention heads.
- **cross_attentions** (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`) -- Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
  sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
  used to compute the weighted average in the cross-attention heads.</retdesc></docstring>
The [PerceiverForMultimodalAutoencoding](/docs/transformers/pr_15592/en/model_doc/perceiver#transformers.PerceiverForMultimodalAutoencoding) forward method, overrides the `__call__` special method.

<Tip>

Although the recipe for forward pass needs to be defined within this function, one should call the `Module`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.

</Tip>







Examples:

```python
>>> from transformers import PerceiverForMultimodalAutoencoding
>>> import torch
>>> import numpy as np

>>> # create multimodal inputs
>>> images = torch.randn((1, 16, 3, 224, 224))
>>> audio = torch.randn((1, 30720, 1))
>>> inputs = dict(image=images, audio=audio, label=torch.zeros((images.shape[0], 700)))

>>> model = PerceiverForMultimodalAutoencoding.from_pretrained("deepmind/multimodal-perceiver")

>>> # in the Perceiver IO paper, videos are auto-encoded in chunks
>>> # each chunk subsamples different index dimensions of the image and audio modality decoder queries
>>> nchunks = 128
>>> image_chunk_size = np.prod((16, 224, 224)) // nchunks
>>> audio_chunk_size = audio.shape[1] // model.config.samples_per_patch // nchunks
>>> # process the first chunk
>>> chunk_idx = 0
>>> subsampling = &amp;lcub;
...     "image": torch.arange(image_chunk_size * chunk_idx, image_chunk_size * (chunk_idx + 1)),
...     "audio": torch.arange(audio_chunk_size * chunk_idx, audio_chunk_size * (chunk_idx + 1)),
...     "label": None,
... }

>>> outputs = model(inputs=inputs, subsampled_output_points=subsampling)
>>> logits = outputs.logits
```

</div></div>
