Perceiver AR is a simple extension of a plain decoder-only transformer such as GPT-2, for example. A core building block
of both is the decoder layer consisting of a self-attention layer followed by a position-wise MLP. Self-attention uses
a causal attention mask.
Perceiver AR additionally cross-attends to a longer prefix of the input sequence in its first attention layer. This layer
is a hybrid self- and cross-attention layer. Self-attention is over the last n positions of the input sequence, with a
causal attention mask, cross-attention is from the last n positions to the first m positions. The length of the input
sequence is m + n. This allows a Perceiver AR to process a much larger context than decoder-only transformers which are
based on self-attention only.
Perceiver AR
Fig. 1. Attention in Perceiver AR with m=8 prefix tokens and n=3 latent tokens.
The output of the hybrid attention layer are n latent arrays corresponding to the last n tokens of the input sequence.
These are further processed by a stack of L-1 decoder layers where the total number of attention layers is L. A final
layer (not shown in Fig. 1) predicts the target token for each latent position. The weights of the final layer are
shared with the input embedding layer. Except for the initial cross-attention to the prefix sequence, a Perceiver AR
is architecturally identical to a decoder-only transformer.
Model training
The model was trained with
the task of symbolic audio modeling on the GiantMIDI-Piano dataset
for 27 epochs (157M tokens). This dataset consists of MIDI files, tokenized using the
approach from the Perceiver AR paper, which is described
in detail in Section A.2 of Huang et al (2019).
All hyperparameters are summarized in the training script.
The context length was set to 6144 tokens with 2048 latent positions, resulting in a maximal prefix length of 4096. The
actual prefix length per example was randomly chosen between 0 and 4096. Training was done with PyTorch Lightning
and the resulting checkpoint was converted to this 🤗 model with a library-specific conversion utility.
Intended use and limitations
This model can be used for audio generation with a user-defined initial number of latent tokens. It mainly exists for
demonstration purposes on how to train Perceiver AR models with the perceiver-io library.
To improve on the quality of the generated audio samples a much larger dataset than
GiantMIDI-Piano is required for training.
Usage examples
To use this model you first need to install
the perceiver-io library with extension audio.
pip install perceiver-io[audio]
Then the model can be used with PyTorch. Either use the model directly to generate MIDI files:
The following (hand-picked) audio samples were generated using various prompts from the validation subset of
the GiantMIDI-Piano dataset. The input prompts are
not included in the audio output.
Audio sample
Top-K
Top-p
Temperature
Prefix length
Latents
-
0.95
0.95
4096
1
-
0.95
1.0
4096
64
-
0.95
1.0
1024
1
15
-
1.0
4096
16
-
0.95
1.0
4096
1
Checkpoint conversion
The krasserm/perceiver-ar-sam-giant-midi model has been created from a training checkpoint with:
1@inproceedings{hawthorne2022general,
2 title={General-purpose, long-context autoregressive modeling with perceiver ar},
3 author={Hawthorne, Curtis and Jaegle, Andrew and Cangea, C{\u{a}}t{\u{a}}lina and Borgeaud, Sebastian and Nash, Charlie and Malinowski, Mateusz and Dieleman, Sander and Vinyals, Oriol and Botvinick, Matthew and Simon, Ian and others},
4 booktitle={International Conference on Machine Learning},
5 pages={8535--8558},
6 year={2022},
7 organization={PMLR}
8}