Transformer (deep learning architecture) explained

A transformer is a deep learning architecture developed by researchers at Google and based on the multi-head attention mechanism, proposed in a 2017 paper "Attention Is All You Need".[1] Text is converted to numerical representations called tokens, and each token is converted into a vector via looking up from a word embedding table. At each layer, each token is then contextualized within the scope of the context window with other (unmasked) tokens via a parallel multi-head attention mechanism allowing the signal for key tokens to be amplified and less important tokens to be diminished.

Transformers have the advantage of having no recurrent units, and therefore require less training time than earlier recurrent neural architectures (RNNs) such as long short-term memory (LSTM).[2] Later variations have been widely adopted for training large language models (LLM) on large (language) datasets, such as the Wikipedia corpus and Common Crawl.[3]

Transformers were first developed as an improvement over previous architectures for machine translation,[4] [5] but have found many applications since then. They are used in large-scale natural language processing, computer vision (vision transformers), reinforcement learning,[6] audio,[7] multi-modal processing, robotics,[8] and even playing chess.[9] It has also led to the development of pre-trained systems, such as generative pre-trained transformers (GPTs)[10] and BERT[11] (Bidirectional Encoder Representations from Transformers).

History

See also: Timeline of machine learning.

Predecessors

For many years, sequence modelling and generation was done by using plain recurrent neural networks (RNNs). A well-cited early example was the Elman network (1990). In theory, the information from one token can propagate arbitrarily far down the sequence, but in practice the vanishing-gradient problem leaves the model's state at the end of a long sentence without precise, extractable information about preceding tokens.

A key breakthrough was LSTM (1995), a RNN which used various innovations to overcome the vanishing gradient problem, allowing efficient learning of long-sequence modelling. One key innovation was the use of an attention mechanism which used neurons that multiply the outputs of other neurons, so-called multiplicative units.[12] Neural networks using multiplicative units were called sigma-pi networks[13] or higher-order networks,[14] but they faced high computational complexity. LSTM became the standard architecture for long sequence modelling until the 2017 publication of Transformers.

However, LSTM still used sequential processing, like most other RNNs. Specifically, RNNs operate one token at a time from first to last; they cannot operate in parallel over all tokens in a sequence. An early attempt to overcome this was the fast weight controller (1992) which computed the weight matrix for further processing depending on the input.[15] It used the fast weights architecture (1987),[16] where one neural network outputs the weights of another neural network. It was later shown to be equivalent to the linear Transformer without normalization.[17] [18]

Attention with seq2seq

The idea of encoder-decoder sequence transduction had been developed in the early 2010s (see [19] [20] for previous papers). The papers most commonly cited as the originators that produced seq2seq are two concurrently published papers from 2014.

(Sutskever et al, 2014) was a 380M-parameter model for machine translation using two long short-term memory (LSTM). The architecture consists of two parts. The encoder is an LSTM that takes in a sequence of tokens and turns it into a vector. The decoder is another LSTM that converts the vector into a sequence of tokens. Similarly, (Cho et al, 2014) was 130M-parameter model that used gated recurrent units (GRU) instead of LSTM. Later research showed that GRUs are neither better nor worse than LSTMs for seq2seq.[21]

These early seq2seq models had no attention mechanism, and the state vector is accessible only after the last word of the source text was processed. Although in theory such a vector retains the information about the whole original sentence, in practice the information is poorly preserved, since the input is processed sequentially by one recurrent network into a fixed-size output vector, which was then processed by another recurrent network into an output. If the input is long, then the output vector would not be able to contain all relevant information, and the output quality degrades. As evidence, reversing the input sentence improved seq2seq translation.[22]

(Bahdanau et al, 2014) introduced an attention mechanism to seq2seq for machine translation to solve the bottleneck problem, allowing the model to process long-distance dependencies more easily. They called their model RNNsearch, as it "emulates searching through a source sentence during decoding a translation".

(Luong et al, 2015)[23] compared the relative performance of global (that of (Bahdanau et al, 2014)) and local (sliding window) attention model architectures for machine translation, and found that a mixed attention architecture had higher quality than global attention, while the use of a local attention architecture reduced translation time.

In 2016, Google Translate was revamped to Google Neural Machine Translation, which replaced the previous model based on statistical machine translation. The new model was a seq2seq model where the encoder and the decoder were both 8 layers of bidirectional LSTM.[24] It took nine months to develop, and it achieved a higher level of performance than the statistical approach, which took ten years to develop.[25]

Attention

Seq2seq models with attention still suffered from the same issue with recurrent networks, which is that they are hard to parallelize, which prevented them to be accelerated on GPUs. In 2016, decomposable attention applied attention mechanism to the feedforward network, which are easy to parallelize.[26] One of its authors, Jakob Uszkoreit, suspected that attention without recurrence is sufficient for language translation, thus the title "attention is all you need".[27]

In 2017, the original (100M-sized) encoder-decoder transformer model was proposed in the "Attention is all you need" paper. At the time, the focus of the research was on improving seq2seq for machine translation, by removing its recurrence to process all tokens in parallel, but preserving its dot-product attention mechanism to keep its text processing performance. Its parallelizability was an important factor to its widespread use in large neural networks.

AI boom era

Transformers are used in many models that contribute to the ongoing AI boom.

In language modelling, ELMo (2018) was a bi-directional LSTM that produces contextualized word embeddings, improving upon the line of research from bag of words and word2vec. It was followed by BERT (2018), an encoder-only Transformer model.[28] In 2019 October, Google started using BERT to process search queries.[29] In 2020, Google Translate replaced the previous RNN-encoder–RNN-decoder model by a Transformer-encoder–RNN-decoder model.[30]

Starting in 2018, the OpenAI GPT series of decoder-only Transformers became state of the art in natural language generation. In 2022, a chatbot based on GPT-3, ChatGPT, became unexpectedly popular,[31] triggering a boom around large language models.[32]

Since 2020, Transformers have been applied in modalities beyond text, including the vision transformer,[33] speech recognition, robotics, and multimodal. The vision transformer, in turn, stimulated new developments in convolutional neural networks.[34] Image and video generators like DALL-E (2021), Stable Diffusion 3 (2024), and Sora (2024), are based on the Transformer architecture.

Training

Methods for stabilizing training

The plain transformer architecture had difficulty converging. In the original paper the authors recommended using learning rate warmup. That is, the learning rate should linearly scale up from 0 to maximal value for the first part of the training (usually recommended to be 2% of the total number of training steps), before decaying again.

A 2020 paper found that using layer normalization before (instead of after) multiheaded attention and feedforward layers stabilizes training, not requiring learning rate warmup.[35]

Pretrain-finetune

Transformers typically are first pretrained by self-supervised learning on a large generic dataset, followed by supervised fine-tuning on a small task-specific dataset. The pretrain dataset is typically an unlabeled large corpus, such as The Pile. Tasks for pretraining and fine-tuning commonly include:

The T5 transformer report[36] documents a large number of natural language pretraining tasks. Some examples are:

Note that while each of these tasks is trivial or obvious for human native speakers of the language (or languages), they have typically proved challenging for previous generations of machine learning architecture.

Tasks

In general, there are 3 classes of language modelling tasks: "masked",[38] "autoregressive",[39] and "prefixLM". These classes are independent of a specific modeling architecture such as Transformer, but they are often discussed in the context of Transformer.

In a masked task, one or more of the tokens is masked out, and the model would produce a probability distribution predicting what the masked-out tokens are based on the context. The loss function for the task is typically sum of log-perplexities for the masked-out tokens: \text = -\sum_\ln(\textt\text) and the model is trained to minimize this loss function. The BERT series of models are trained for masked token prediction and another task.

In an autoregressive task, the entire sequence is masked at first, and the model produces a probability distribution for the first token. Then the first token is revealed and the model predicts the second token, and so on. The loss function for the task is still typically the same. The GPT series of models are trained by autoregressive tasks.

In a prefixLM task, the sequence is divided into two parts. The first part is presented as context, and the model predicts the first token of the second part. Then that would be revealed, and the model predicts the second token, and so on. The loss function for the task is still typically the same. The T5 series of models are trained by prefixLM tasks.

Note that "masked" as in "masked language modelling" is not "masked" as in "masked attention", and "prefixLM" (prefix language modeling) is not "prefixLM" (prefix language model).

Architecture

All transformers have the same primary components:

The following description follows exactly the Transformer as described in the original paper. There are variants, described in the following section.

By convention, we write all vectors as row vectors. This, for example, means that pushing a vector through a linear layer means multiplying it by a weight matrix on the right, as

xW

.

Tokenization

See main article: Tokenization and Lexical analysis.

As the Transformer architecture natively processes numerical data, not text, there must be a translation between text and tokens. A token is an integer that represents a character, or a short segment of characters. On the input side, the input text is parsed into a token sequence. Similarly, on the output side, the output tokens are parsed back to text. The module doing the conversion between token sequences and texts is a tokenizer.

The set of all tokens is the vocabulary of the tokenizer, and its size is the vocabulary size

nvocabulary

. When faced with tokens outside the vocabulary, typically a special token is used, written as "[UNK]" for "unknown".

Some commonly used tokenizers are byte pair encoding, WordPiece, and SentencePiece.

Embedding

See also: Word embedding. Each token is converted into an embedding vector via a lookup table. Equivalently stated, it multiplies a one-hot representation of the token by an embedding matrix

M

. For example, if the input token is

3

, then the one-hot representation is

[0,0,0,1,0,0,...]

, and its embedding vector is\mathrm(3) = [0, 0, 0, 1, 0, 0, \dots]MThe token embedding vectors are added to their respective positional encoding vectors (see below), producing the sequence of input vectors.

The number of dimensions in an embedding vector is called hidden size or embedding size and written as

demb

[40]

Un-embedding

An un-embedding layer is almost the reverse of an embedding layer. Whereas an embedding layer converts a token into a vector, an un-embedding layer converts a vector into a probability distribution over tokens.

The un-embedding layer is a linear-softmax layer:\mathrm(x) = \mathrm(xW + b)The matrix has shape

(demb,nvocabulary)

.

Positional encoding

A positional encoding is a fixed-size vector representation of the relative positions of tokens within a sequence: it provides the transformer model with information about where the words are in the input sequence. Without positional encoding, the model would be unable to process input sequence as more than a bag of words, as for example, both "man bites dog" and "dog bites man" would be processed exactly the same way.

The positional encoding is defined as a function of type

f:\R\to\Rd;d\inZ,d>0

, where

d

is a positive even integer. The full positional encoding defined in the original paper is:(f(t)_, f(t)_) = (\sin(\theta), \cos(\theta)) \quad \forall k \in \where

\theta=

t
rk

,r=N2/d

.

Here,

N

is a free parameter that should be significantly larger than the biggest

k

that would be input into the positional encoding function. The original paper uses

N=10000

.

The function is in a simpler form when written as a complex function of type

f:\R\toCd/2

f(t) = \left(e^\right)_where

r=N2/d

.

The main reason for using this positional encoding function is that using it, shifts are linear transformations:f(t + \Delta t) = \mathrm(f(\Delta t)) f(t)where

\Deltat\in\R

is the distance one wishes to shift. This allows the transformer to take any encoded position, and find the encoding of the position n-steps-ahead or n-steps-behind, by a matrix multiplication.

By taking a linear sum, any convolution can also be implemented as linear transformations:\sum_j c_j f(t + \Delta t_j) = \left(\sum_j c_j \,\mathrm(f(\Delta t_j))\right) f(t)for any constants

cj

. This allows the transformer to take any encoded position and find a linear sum of the encoded locations of its neighbors. This sum of encoded positions, when fed into the attention mechanism, would create attention weights on its neighbors, much like what happens in a convolutional neural network language model. In the author's words, "we hypothesized it would allow the model to easily learn to attend by relative position."

In typical implementations, all operations are done over the real numbers, not the complex numbers, but since complex multiplication can be implemented as real 2-by-2 matrix multiplication, this is a mere notational difference.

Encoder-decoder (overview)

Like earlier seq2seq models, the original transformer model used an encoder-decoder architecture. The encoder consists of encoding layers that process all the input tokens together one layer after another, while the decoder consists of decoding layers that iteratively process the encoder's output and the decoder's output tokens so far.

The purpose of each encoder layer is to create contextualized representations of the tokens, where each representation corresponds to a token that "mixes" information from other input tokens via self-attention mechanism. Each decoder layer contains two attention sublayers: (1) cross-attention for incorporating the output of encoder (contextualized input token representations), and (2) self-attention for "mixing" information among the input tokens to the decoder (i.e. the tokens generated so far during inference time).[41] [42]

Both the encoder and decoder layers have a feed-forward neural network for additional processing of their outputs and contain residual connections and layer normalization steps. These feed-forward layers contain most of the parameters in a Transformer model.

Feedforward network

The feedforward network (FFN) modules in a Transformer are 2-layered multilayer perceptrons:\mathrm(x) = \phi(xW^ + b^)W^ + b^where

\phi

is its activation function. The original Transformer used ReLU activation.

The number of neurons in the middle layer is called intermediate size (GPT),[43] filter size (BERT), or feedforward size (BERT). It is typically larger than the embedding size. For example, in both GPT-2 series and BERT series, the intermediate size of a model is 4 times its embedding size:

dffn=4demb

.

Scaled dot-product attention

Attention head

The attention mechanism used in the Transformer architecture are scaled dot-product attention units. For each unit, the transformer model learns three weight matrices: the query weights

WQ

, the key weights

WK

, and the value weights

WV

.

The module takes three sequences, a query sequence, a key sequence, and a value sequence. The query sequence is a sequence of length

\ellseq,query

, and each entry is a vector of dimension

demb,query

. Similarly for the key and value sequences.

For each vector

xi,

in the query sequence, it is multiplied by a matrix

WQ

to produce a query vector

qi=xi,WQ

. The matrix of all query vectors is the query matrix:Q = X_ W^QSimilarly, we construct the key matrix

K=XkeyWK

and the value matrix

V=XvalueWV

.

It is usually the case that all

WQ,WK,WV

are square matrices, meaning

demb,query=dquery

, etc.

Attention weights are calculated using the query and key vectors: the attention weight

aij

from token

i

to token

j

is the dot product between

qi

and

kj

. The attention weights are divided by the square root of the dimension of the key vectors,

\sqrt{dk}

, which stabilizes gradients during training, and passed through a softmax which normalizes the weights. The fact that

WQ

and

WK

are different matrices allows attention to be non-symmetric: if token

i

attends to token

j

(i.e.

qikj

is large), this does not necessarily mean that token

j

will attend to token

i

(i.e.

qjki

could be small). The output of the attention unit for token

i

is the weighted sum of the value vectors of all tokens, weighted by

aij

, the attention from token

i

to each token.

The attention calculation for all tokens can be expressed as one large matrix calculation using the softmax function, which is useful for training due to computational matrix operation optimizations that quickly compute matrix operations. The matrices

Q

,

K

and

V

are defined as the matrices where the

i

th rows are vectors

qi

,

ki

, and

vi

respectively. Then we can represent the attention as\begin\text(Q, K, V) = \text\left(\frac\right)V\end

where the softmax is applied over each of the rows of the matrix.

The number of dimensions in a query vector is query size

dquery

and similarly for the key size

dkey

and value size

dvalue

. The output dimension of an attention head is its head dimension

dhead

. The attention mechanism requires the following three equalities to hold:\ell_=\ell_, \;d_=d_, \; d_=d_but is otherwise unconstrained.

If the attention head is used in a self-attention fashion, then

Xquery=Xkey=Xvalue

. If the attention head is used in a cross-attention fashion, then usually

XqueryXkey=Xvalue

. It is theoretically possible for all three to be different, but that is rarely the case in practice.

Multiheaded attention

One set of

\left(WQ,WK,WV\right)

matrices is called an attention head, and each layer in a transformer model has multiple attention heads. While each attention head attends to the tokens that are relevant to each token, multiple attention heads allow the model to do this for different definitions of "relevance". In addition, the influence field representing relevance can become progressively dilated in successive layers. Many transformer attention heads encode relevance relations that are meaningful to humans. For example, some attention heads can attend mostly to the next word, while others mainly attend from verbs to their direct objects.[44] The computations for each attention head can be performed in parallel, which allows for fast processing. The outputs for the attention layer are concatenated to pass into the feed-forward neural network layers.

Concretely, let the multiple attention heads be indexed by

i

, then we have\text(Q, K, V) = \text_(\text(XW^Q_i, XW^K_i, XW^V_i)) W^O where the matrix

X

is the concatenation of word embeddings, and the matrices
Q
W
i,
K
W
i,
V
W
i
are "projection matrices" owned by individual attention head

i

, and

WO

is a final projection matrix owned by the whole multi-headed attention head.

It is theoretically possible for each attention head to have a different head dimension

dhead

, but that is rarely the case in practice.

As an example, in the smallest GPT-2 model, there are only self-attention mechanisms. It has the following dimensions:d_ = 768, n_ = 12, d_ = 64Since

12 x 64=768

, its projection matrix

WO\in\R(64 x

is a square matrix.

Masked attention

It may be necessary to cut out attention links between some word-pairs. For example, the decoder, when decoding for the token position

t

, should not have access to the token at position

t+1

. This may be accomplished before the softmax stage by adding a mask matrix

M

that is

-infty

at entries where the attention link must be cut, and

0

at other places:\begin\text(Q, K, V) = \text\left(M + \frac\right)V\endA non-masked attention module can be thought of as a masked attention module where the mask has all entries zero.

For example, the following matrix is commonly used in decoder self-attention modules, called "causal masking":M_ = \begin0 & -\infty & -\infty & \dots & -\infty \\0 & 0 & -\infty & \dots & -\infty \\0 & 0 & 0 & \dots & -\infty \\\vdots & \vdots & \vdots & \ddots & \vdots \\0 & 0 & 0 & \dots & 0\endIn words, it means that each token can pay attention to itself, and every token before it, but not any after it. As an example of an uncommon use of mask matrix, the XLNet considers all masks of the form

PMcausalP-1

, where

P

is a random permutation matrix.[45]

Encoder

An encoder consists of an embedding layer, followed by multiple encoder layers.

Each encoder layer consists of two major components: a self-attention mechanism and a feed-forward layer. It takes an input as a sequence of input vectors, applies the self-attention mechanism, to produce an intermediate sequence of vectors, then applies the feed-forward layer for each vector individually. Schematically, we have:

\begin{aligned} giveninputvectors&h0,h1,...\\ combinethemintoamatrixH&=\begin{bmatrix}h0\h1\\vdots\end{bmatrix}\\ EncoderLayer(H)&=\begin{bmatrix}FFN(MultiheadedAttention(H,H,H)0)\FFN(MultiheadedAttention(H,H,H)1)\\vdots\end{bmatrix}\\ \end{aligned}

where

FFN

stands for "feed-forward network". We can more succinctly write it as\text(H) = \text(\text(H, H, H))with the implicit convention that the

FFN

is applied to each row of the matrix individually.

The encoder layers are stacked. The first encoder layer takes the sequence of input vectors from the embedding layer, producing a sequence of vectors. This sequence of vectors is processed by the second encoder, and so on. The output from the final encoder layer is then used by the decoder.

As the encoder processes the entire input all at once, every token can attend to every other token (all-to-all attention), so there is no need for causal masking.

Decoder

A decoder consists of an embedding layer, followed by multiple decoder layers, followed by an un-embedding layer.

Each decoder consists of three major components: a causally masked self-attention mechanism, a cross-attention mechanism, and a feed-forward neural network. The decoder functions in a similar fashion to the encoder, but an additional attention mechanism is inserted which instead draws relevant information from the encodings generated by the encoders. This mechanism can also be called the encoder-decoder attention.

Like the first encoder, the first decoder takes positional information and embeddings of the output sequence as its input, rather than encodings. The transformer must not use the current or future output to predict an output, so the output sequence must be partially masked to prevent this reverse information flow. This allows for autoregressive text generation. For decoding, all-to-all attention is inappropriate, because a token cannot attend to tokens not yet generated. Thus, the self-attention module in the decoder is causally masked.

In contrast, the cross-attention mechanism attends to the output vectors of the encoder, which is computed before the decoder starts decoding. Consequently, there is no need for masking in the cross-attention mechanism.

Schematically, we have:\beginH' &= \text(H, H, H) \\\text(H) &=\text(\text(H', H^E, H^E))\endwhere

HE

is the matrix with rows being the output vectors from the encoder.

The last decoder is followed by a final un-embedding layer. to produce the output probabilities over the vocabulary. Then, one of the tokens is sampled according to the probability, and the decoder can be run again to produce the next token, etc, autoregressively generating output text.

Full transformer architecture

Sublayers

Each encoder layer contains 2 sublayers: the self-attention and the feedforward network. Each decoder layer contains 3 sublayers: the causally masked self-attention, the cross-attention, and the feedforward network.The final points of detail are the residual connections and layer normalization (LayerNorm, or LN), which while conceptually unnecessary, are necessary for numerical stability and convergence. Similarly to how the feedforward network modules are applied individually to each vector, the LayerNorm is also applied individually to each vector.

There are two common conventions in use: the post-LN and the pre-LN convention. In the post-LN convention, the output of each sublayer is \mathrm(x + \mathrm(x))where

Sublayer(x)

is the function implemented by the sublayer itself.

In the pre-LN convention, the output of each sublayer isx + \mathrm(\mathrm(x))The original 2017 Transformer used the post-LN convention. It was difficult to train and required careful hyperparameter tuning and a "warm-up" in learning rate, where it starts small and gradually increases. The pre-LN convention was developed in 2020, which was found to be easier to train, requiring no warm-up, leading to faster convergence.

Pseudocode

The following is the pseudocode for a standard pre-LN encoder-decoder Transformer, adapted from input: Encoder input t_e Decoder input t_d output: Array of probability distributions, with shape (decoder vocabulary size x length(decoder output sequence)) /* encoder */ z_e ← encoder.tokenizer(t_e) for each t in 1:length(z_e) do z_e[t] ← encoder.embedding(z_e[t]) + encoder.positional_embedding(t) for each l in 1:length(encoder.layers) do layer ← encoder.layers[l] /* first sublayer */ z_e_copy ← copy(z_e) for each t in 1:length(z_e) do z_e[t] ← layer.layer_norm(z_e[t]) z_e ← layer.multiheaded_attention(z_e, z_e, z_e) for each t in 1:length(z_e) do z_e[t] ← z_e[t] + z_e_copy[t] /* second sublayer */ z_e_copy ← copy(z_e) for each t in 1:length(z_e) do z_e[t] ← layer.layer_norm(z_e[t]) z_e ← layer.feedforward(z_e) for each t in 1:length(z_e) do z_e[t] ← z_e[t] + z_e_copy[t] for each t in 1:length(z_e) do z_e[t] ← encoder.final_layer_norm(z_e[t]) /* decoder */ z_d ← decoder.tokenizer(t_d) for each t in 1:length(z_d) do z_d[t] ← decoder.embedding(z_d[t]) + decoder.positional_embedding(t) for each l in 1:length(decoder.layers) do layer ← decoder.layers[l] /* first sublayer */ z_d_copy ← copy(z_d) for each t in 1:length(z_d) do z_d[t] ← layer.layer_norm(z_d[t]) z_d ← layer.masked_multiheaded_attention(z_d, z_d, z_d) for each t in 1:length(z_d) do z_d[t] ← z_d[t] + z_d_copy[t] /* second sublayer */ z_d_copy ← copy(z_d) for each t in 1:length(z_d) do z_d[t] ← layer.layer_norm(z_d[t]) z_d ← layer.multiheaded_attention(z_d, z_e, z_e) for each i in 1:length(z_d) do z_d[t] ← z_d[t] + z_d_copy[t] /* third sublayer */ z_d_copy ← copy(z_d) for each t in 1:length(z_d) do z_d[t] ← layer.layer_norm(z_d[t]) z_d ← layer.feedforward(z_d) for each t in 1:length(z_d) do z_d[t] ← z_d[t] + z_d_copy[t] z_d ← decoder.final_layer_norm(z_d) output_distributions ← [] for each t in 1:length(z_d) do output_distributions.append(decoder.unembed(z_d[t])) return output_distributions

Terminology

The Transformer architecture, being modular, allows variations. Several common variations are described here.[46]

An "encoder-only" Transformer applies the encoder to map an input text into a sequence of vectors that represent the input text. This is usually used for text embedding and representation learning for downstream applications. BERT is encoder-only. They are less often used currently, as they were found to be not significantly better than training an encoder-decoder Transformer, then taking just the encoder.

A "decoder-only" Transformer is not literally decoder-only, since without an encoder, the cross-attention mechanism has nothing to attend to. Thus, the decoder layers in a decoder-only Transformer is composed of just two sublayers: the causally masked self-attention, and the feedforward network. This is usually used for text generation and instruction following. The models in the GPT series and Chinchilla series are decoder-only.

An "encoder-decoder" Transformer is generally the same as the original Transformer, with 2 sublayers per encoder layer and 3 sublayers per decoder layer, etc. They might have minor architectural improvements, such as alternative activation functions, changing the location of normalization, etc. This is also usually used for text generation and instruction following. The models in the T5 series are encoder-decoder.

A "prefixLM" (prefix language model) is a decoder-only architecture, but with prefix masking, which is different from causal masking. Specifically, it has mask of the formM_ = \begin\mathbf & 0, -\infty \\\mathbf & M_ \endwhere the first columns correspond to the "prefix", and the subsequent columns correspond to the autoregressively generated text based on the prefix. They resemble encoder-decoder models, but has less "sparsity". Such models are rarely used, though they are cited as theoretical possibilities and benchmarked comparisons.

There are also mixed seq2seq models. For example, in 2020, Google Translate replaced the previous RNN-encoder–RNN-decoder model by a Transformer-encoder–RNN-decoder model, on the argument that an RNN-decoder runs much faster than Transformer-decoder when run autoregressively.[47]

Subsequent work

Alternative activation functions

The original transformer uses ReLU activation function. Other activation functions were developed. The Llama series used SwiGLU;[48] both GPT-1 and BERT used GELU.[49]

Alternative normalizations

The normalization used in the Transformer can be different from LayerNorm. One example is RMSNorm[50] which is used in the Llama series. Other examples include ScaleNorm,[51] or FixNorm.

Alternative positional encodings

Transformers may use other positional encoding methods than sinusoidal.[52]

The original Transformer paper reported using a learned positional encoding,[53] but finding it not superior to the sinusoidal one. Later, found that causal masking itself provides enough signal to a Transformer decoder that it can learn to implicitly perform absolute positional encoding without the positional encoding module.

RoPE

RoPE (rotary positional embedding),[54] is best explained by considering a list of 2-dimensional vectors

(1)
[(x
1,
(2)
x
1),
(1)
(x
2,
(2)
x
2),
(1)
(x
3,
(2)
x
3),

...]

. Now pick some angle

\theta

. Then RoPE encoding is\text\big(x^_m, x^_m, m\big) =\begin \cos m \theta & - \sin m \theta \\\sin m \theta & \cos m \theta \end\begin x^_m \\ x^_m \\ \end = \begin x^_m \cos m\theta - x^_m \sin m \theta \\ x^_m \cos m\theta + x^_m \sin m \theta \\ \endEquivalently, if we write the 2-dimensional vectors as complex numbers

zm:=

(1)
x
m

+i

(2)
x
m
, then RoPE encoding is just multiplication by an angle:\text\big(z_m, m\big) = e^ z_mFor a list of

2n

-dimensional vectors, a RoPE encoder is defined by a sequence of angles

\theta(1),...,\theta(n)

. Then the RoPE encoding is applied to each pair of coordinates.

The benefit of RoPE is that the dot-product between two vectors depends on their relative location only:\text\big(x, m\big)^T\text\big(y, n\big)=\text\big(x, m+k\big)^T\text\big(y, n+k\big)for any integer

k

.

ALiBi

ALiBi (Attention with Linear Biases)[55] is not a replacement for the positional encoder on the original transformer. Instead, it is an additional positional encoder that is directly plugged into the attention mechanism. Specifically, the ALiBi attention mechanism is\begin\text(Q, K, V) = \text\left(\frac + s B\right)V\endHere,

s

is a real number ("scalar"), and

B

is the linear bias matrix defined byB = \begin0 & 1 & 2 & 3 & \cdots \\-1 & 0 & 1 & 2 & \cdots \\-2 & -1 & 0 & 1 & \cdots \\-3 & -2 & -1 & 0 & \cdots \\\vdots & \vdots & \vdots & \vdots & \ddots \\\endin other words,

Bi,=j-i

. The idea being that the linear bias matrix is a softened mask. Just as

0

represent full attention paid, and

-infty

represents no attention paid, the linear bias matrix increases attention paid in one direction and decreases attention paid in the other direction.

ALiBi allows pretraining on short context windows, then finetuning on longer context windows. Since it is directly plugged into the attention mechanism, it can be combined with any positional encoder that is plugged into the "bottom" of the entire network (which is where the sinusoidal encoder on the original transformer, as well as RoPE and many others, are located).

Relative Position Encodings

Relative Position Encodings[56] is similar to ALiBi, but more generic:\begin\text(Q, K, V) = \text\left(\frac + B\right)V\endwhere

B

is a Toeplitz matrix, that is,

Bi,=Bi',

whenever

i-j=i'-j'

. This is contrasted with the original sinusoidal positional encoding, which is an "absolute positional encoding".

Efficient implementation

The transformer model has been implemented in standard deep learning frameworks such as TensorFlow and PyTorch. Transformers is a library produced by Hugging Face that supplies transformer-based architectures and pretrained models.

FlashAttention

FlashAttention[57] is an algorithm that implements the transformer attention mechanism efficiently on a GPU. It performs matrix multiplications in blocks, such that each block fits within the cache of a GPU, and by careful management of the blocks it minimizes data copying between GPU caches (as data movement is slow).

An improved version, FlashAttention-2,[58] [59] [60] was developed to cater to the rising demand for language models capable of handling longer context lengths. It offers enhancements in work partitioning and parallelism, enabling it to achieve up to 230 TFLOPs/s on A100 GPUs (FP16/BF16), a 2x speed increase over the original FlashAttention.

Key advancements in FlashAttention-2 include the reduction of non-matmul FLOPs, improved parallelism over the sequence length dimension, better work partitioning between GPU warps, and added support for head dimensions up to 256 and multi-query attention (MQA) and grouped-query attention (GQA).

Benchmarks revealed FlashAttention-2 to be up to 2x faster than FlashAttention and up to 9x faster than a standard attention implementation in PyTorch. Future developments include optimization for new hardware like H100 GPUs and new data types like FP8.

Multi-Query Attention

Multi-Query Attention changes the multiheaded attention mechanism.[61] Whereas normally,

\text(Q, K, V) = \text_\left(\text(XW^Q_i, XW^K_i, XW^V_i)\right) W^Owith Multi-Query Attention, there is just one

WK,WV

, thus:

\text(Q, K, V) = \text_\left(\text(XW^Q_i, XW^K, XW^V)\right) W^O

This has a neutral effect on model quality and training speed, but increases inference speed.

Caching

When an autoregressive transformer is used for inference, such as generating text, the query vector is different at each step, but the already-computed key and value vectors are always the same. The KV caching method saves the computed key and value vectors at each attention block, so that they are not recomputed at each new token. PagedAttention applies memory paging to KV caching.[62] [63]

If a transformer is used with a baked-in prompt, such as ["You are a customer support agent..."], then the key and value vectors can be computed for the prompt, and saved on disk. The saving in compute is significant when the model is used for many short interactions, such as in online chatbots.

Speculative decoding

Transformers are used in large language models for autoregressive sequence generation: generating a stream of text, one token at a time. However, in most settings, decoding from language models is memory-bound, meaning that we have spare compute power available. Speculative decoding[64] uses this spare compute power by computing several tokens in parallel. Similarly to speculative execution in CPUs, future tokens are computed concurrently, by speculating on the value of previous tokens, and are later discarded if it turns out the speculation was incorrect.

Specifically, consider a transformer model like GPT-3 with a context window size of 512. To generate an entire context window autoregressively with greedy decoding, it must be run for 512 times, each time generating a token

x1,x2,...,x512

. However, if we had some educated guess for the values of these tokens, we could verify all of them in parallel, in one run of the model, by checking that each

xt

is indeed the token with the largest log-likelihood in the

t

-th output.

In speculative decoding, a smaller model or some other simple heuristic is used to generate a few speculative tokens that are subsequently verified by the larger model. For example, suppose a small model generated four speculative tokens:

\tilde{x1},\tilde{x2},\tilde{x3},\tilde{x4}

. These tokens are run through the larger model, and only

\tilde{x1}

and

\tilde{x2}

are accepted. The same run of the large model already generated a new token

x3

to replace

\tilde{x3}

, and

\tilde{x4}

is completely discarded. The process then repeats (starting from the 4th token) until all tokens are generated.

For non-greedy decoding, similar ideas apply, except the speculative tokens are accepted or rejected stochastically, in a way that guarantees the final output distribution is the same as if speculative decoding was not used.

Sub-quadratic transformers

Training transformer-based architectures can be expensive, especially for long inputs.[65] Many methods have been developed to attempt to address the issue. Long Range Arena (2020)[66] is a standard benchmark for comparing the behavior of transformer architectures over long inputs.

Alternative attention graphs

The standard attention graph is either all-to-all or causal, both of which scales as

O(N2)

where

N

is the number of tokens in a sequence.

Reformer (2020)[67] reduces the computational load from

O(N2)

to

O(NlnN)

by using locality-sensitive hashing and reversible layers.[68]

Sparse attention uses attention graphs that grows slower than

O(N2)

. For example, BigBird (2020)[69] uses random small-world networks which grows as

O(N)

.

Ordinary transformers require a memory size that is quadratic in the size of the context window. Attention-free transformers[70] reduce this to a linear dependence while still retaining the advantages of a transformer by linking the key to the value.

Random Feature Attention

Random Feature Attention (2021)[71] uses Fourier random features:\varphi(x) = \frac[\cos\langle w_1, x\rangle, \sin\langle w_1, x\rangle, \cdots \cos\langle w_D, x\rangle, \sin\langle w_D, x\rangle]^Twhere

w1,...,wD

are independent samples from the normal distribution

N(0,\sigma2I)

. This choice of parameters satisfy

E[\langle\varphi(x),\varphi(y)\rangle]=

-\|x-y\|2
2\sigma2
e
, or e^ = \mathbb E[\langle e^{\|x\|^2/2\sigma^2} \varphi(x), e^{\|y\|^2/2\sigma^2}\varphi(y)\rangle] \approx \langle e^ \varphi(x), e^\varphi(y)\rangle Consequently, the one-headed attention, with one query, can be written as \text(q, K, V) = \text\left(\frac\right)V

\approx \fracwhere

\sigma=

1/4
d
K
. Similarly for multiple queries, and for multiheaded attention.

This approximation can be computed in linear time, as we can compute the matrix

\varphi(ki)

T
v
i
first, then multiply it with the query. In essence, we have managed to obtain a more precise version of \text(Q, K, V) = \text\left(\frac\right)V \approx Q(K^TV/\sqrt)Performer (2022)[72] uses the same Random Feature Attention, but

w1,...,wD

are first independently sampled from the normal distribution

N(0,\sigma2I)

, then they are Gram-Schmidt processed.

Multimodality

Transformers can also be used/adapted for modalities (input or output) beyond just text, usually by finding a way to "tokenize" the modality.

Multimodal models can either be trained from scratch, or by finetuning. A 2022 study found that Transformers pretrained only on natural language can be finetuned on only 0.03% of parameters and become competitive with LSTMs on a variety of logical and visual tasks, demonstrating transfer learning.[73] The LLaVA was a vision-language model composed of a language model (Vicuna-13B)[74] and a vision model (ViT-L/14), connected by a linear layer. Only the linear layer is finetuned.[75]

Vision transformers adapt the transformer to computer vision by breaking down input images as a series of patches, turning them into vectors, and treating them like tokens in a standard transformer.

Conformer[76] and later Whisper[77] follow the same pattern for speech recognition, first turning the speech signal into a spectrogram, which is then treated like an image, i.e. broken down into a series of patches, turned into vectors and treated like tokens in a standard transformer.

Perceivers[78] [79] are a variant of Transformers designed for multimodality.

For image generation, two notable architectures are DALL-E 1 (2021) and Parti (2022).[80] Unlike later models, DALL-E is not a diffusion model. Instead, it uses a decoder-only Transformer that autoregressively generates a text, followed by the token representation of an image, which is then converted by a variational autoencoder to an image. Parti is an encoder-decoder Transformer, where the encoder processes a text prompt, and the decoder generates a token representation of an image.

Applications

The transformer has had great success in natural language processing (NLP). Many large language models such as GPT-2, GPT-3, GPT-4, Claude, BERT, XLNet, RoBERTa and ChatGPT demonstrate the ability of transformers to perform a wide variety of NLP-related subtasks and their related real-world or practical applications, including:

Beyond traditional NLP, the transformer architecture has had success in other applications, such as:

Further reading

Notes and References

  1. Vaswani . Ashish . Ashish Vaswani . Shazeer . Noam . Parmar . Niki . Uszkoreit . Jakob . Jones . Llion . Gomez . Aidan N . Aidan Gomez . Kaiser . Łukasz . Polosukhin . Illia . 2017 . Attention is All you Need . Advances in Neural Information Processing Systems . Curran Associates, Inc. . 30.
  2. Hochreiter . Sepp . Sepp Hochreiter . Schmidhuber . Jürgen . Jürgen Schmidhuber . 1 November 1997 . Long Short-Term Memory . Neural Computation . 9 . 8 . 1735–1780 . 10.1162/neco.1997.9.8.1735 . 0899-7667 . 9377276 . 1915014.
  3. Web site: Better Language Models and Their Implications. 2019-02-14. OpenAI. 2019-08-25. 2020-12-19. https://web.archive.org/web/20201219132206/https://openai.com/blog/better-language-models/. live.
  4. 1409.0473 . cs.CL . Bahdanau . Kyunghyun . Cho . Neural Machine Translation by Jointly Learning to Align and Translate . September 1, 2014 . Bengio . Yoshua.
  5. 1508.04025 . cs.CL . Minh-Thang . Luong . Hieu . Pham . Effective Approaches to Attention-based Neural Machine Translation . August 17, 2015 . Manning . Christopher D..
  6. Parisotto . Emilio . Song . Francis . Rae . Jack . Pascanu . Razvan . Gulcehre . Caglar . Jayakumar . Siddhant . Jaderberg . Max . Kaufman . Raphaël Lopez . Clark . Aidan . Noury . Seb . Botvinick . Matthew . Heess . Nicolas . Hadsell . Raia . 2020-11-21 . Stabilizing Transformers for Reinforcement Learning . Proceedings of the 37th International Conference on Machine Learning . en . PMLR . 7487–7498.
  7. 2212.04356 . Radford . Alec . Jong Wook Kim . Xu . Tao . Brockman . Greg . McLeavey . Christine . Sutskever . Ilya . Robust Speech Recognition via Large-Scale Weak Supervision . 2022 . eess.AS .
  8. Monastirsky . Maxim . Azulay . Osher . Sintov . Avishai . February 2023 . Learning to Throw With a Handful of Samples Using Decision Transformers . IEEE Robotics and Automation Letters . 8 . 2 . 576–583 . 10.1109/LRA.2022.3229266 . 2377-3766.
  9. Ruoss . Anian . Delétang . Grégoire . Medapati . Sourabh . Grau-Moya . Jordi . Wenliang . Li . Catt . Elliot . Reid . John . Genewein . Tim . 2024-02-07 . Grandmaster-Level Chess Without Search . cs.LG . 2402.04494v1.
  10. Book: Wolf . Thomas. Debut . Lysandre. Sanh . Victor . Chaumond . Julien. Delangue . Clement. Moi . Anthony . Cistac . Pierric . Rault . Tim . Louf . Remi . Funtowicz . Morgan . Davison . Joe . Shleifer . Sam . von Platen . Patrick . Ma . Clara . Jernite . Yacine . Plu . Julien . Xu . Canwen . Le Scao . Teven . Gugger . Sylvain . Drame . Mariama . Lhoest . Quentin . Rush . Alexander . Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations . Transformers: State-of-the-Art Natural Language Processing . 2020. 38–45 . 10.18653/v1/2020.emnlp-demos.6 . 208117506.
  11. Web site: Open Sourcing BERT: State-of-the-Art Pre-training for Natural Language Processing. Google AI Blog. 2 November 2018 . 2019-08-25. 2021-01-13. https://web.archive.org/web/20210113211449/https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html. live.
  12. Feldman . J. A. . Ballard . D. H. . 1982-07-01 . Connectionist models and their properties . Cognitive Science . 6 . 3 . 205–254 . 10.1016/S0364-0213(82)80001-3 . 0364-0213.
  13. Book: Rumelhart . David E. . Parallel Distributed Processing, Volume 1: Explorations in the Microstructure of Cognition: Foundations, Chapter 2 . Mcclelland . James L. . Group . PDP Research . 1987-07-29 . Bradford Books . 978-0-262-68053-0 . Cambridge, Mass . en.
  14. Giles . C. Lee . Maxwell . Tom . 1987-12-01 . Learning, invariance, and generalization in high-order neural networks . Applied Optics . en . 26 . 23 . 4972–4978 . 10.1364/AO.26.004972 . 20523475 . 0003-6935.
  15. Schmidhuber . Jürgen . Jürgen Schmidhuber . 1992 . Learning to control fast-weight memories: an alternative to recurrent nets. . Neural Computation . 4 . 1 . 131–139 . 10.1162/neco.1992.4.1.131 . 16683347.
  16. Hinton . Geoffrey E. . Plaut . David C. . 1987 . Using Fast Weights to Deblur Old Memories . Proceedings of the Annual Meeting of the Cognitive Science Society . en . 9 .
  17. Katharopoulos . Angelos . Vyas . Apoorv . Pappas . Nikolaos . Fleuret . François . 2020 . Transformers are RNNs: Fast autoregressive Transformers with linear attention . PMLR . 5156–5165 . ICML 2020.
  18. Schlag . Imanol . Irie . Kazuki . Schmidhuber . Jürgen . Juergen Schmidhuber . 2021 . Linear Transformers Are Secretly Fast Weight Programmers . Springer . 9355–9366 . ICML 2021.
  19. Cho . Kyunghyun . van Merriënboer . Bart . Gulcehre . Caglar . Bahdanau . Dzmitry . Bougares . Fethi . Schwenk . Holger . Bengio . Yoshua . October 2014 . Moschitti . Alessandro . Pang . Bo . Daelemans . Walter . Learning Phrase Representations using RNN Encoder–Decoder for Statistical Machine Translation . Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP) . Doha, Qatar . Association for Computational Linguistics . 1724–1734 . 10.3115/v1/D14-1179. 1406.1078 .
  20. 1409.3215 . cs.CL . Ilya . Sutskever . Oriol . Vinyals . Sequence to sequence learning with neural networks . 14 Dec 2014 . Le . Quoc Viet. [first version posted to arXiv on 10 Sep 2014]
  21. 1412.3555 . cs.NE . Junyoung . Chung . Caglar . Gulcehre . Empirical Evaluation of Gated Recurrent Neural Networks on Sequence Modeling . Cho . KyungHyun . Bengio . Yoshua . 2014.
  22. Sutskever . Ilya . Vinyals . Oriol . Le . Quoc V . 2014 . Sequence to Sequence Learning with Neural Networks . Advances in Neural Information Processing Systems . Curran Associates, Inc. . 27. 1409.3215 .
  23. 1508.04025 . cs.CL . Minh-Thang . Luong . Hieu . Pham . Effective Approaches to Attention-based Neural Machine Translation . 2015 . Manning . Christopher D..
  24. 1609.08144 . cs.CL . Yonghui . Wu . Mike . Schuster . Google's Neural Machine Translation System: Bridging the Gap between Human and Machine Translation . 2016-09-01 . 1 . Chen . Zhifeng . Le . Quoc V. . Norouzi . Mohammad . Macherey . Wolfgang . Krikun . Maxim . Cao . Yuan . Gao . Qin . Macherey . Klaus . Klingner . Jeff . Shah . Apurva . Johnson . Melvin . Liu . Xiaobing . Kaiser . Łukasz.
  25. News: Lewis-Kraus . Gideon . 2016-12-14 . The Great A.I. Awakening . https://web.archive.org/web/20230524052626/https://www.nytimes.com/2016/12/14/magazine/the-great-ai-awakening.html . 24 May 2023 . 2023-06-22 . The New York Times . 0362-4331.
  26. Parikh . Ankur P. . A Decomposable Attention Model for Natural Language Inference . 2016-09-25 . 1606.01933 . Täckström . Oscar . Das . Dipanjan . Uszkoreit . Jakob. cs.CL .
  27. Levy . Steven . 8 Google Employees Invented Modern AI. Here's the Inside Story . live . https://web.archive.org/web/20240320101528/https://www.wired.com/story/eight-google-employees-invented-modern-ai-transformers-paper/ . 20 Mar 2024 . 2024-08-06 . Wired . en-US . 1059-1028.
  28. 1810.04805v2 . cs.CL . Jacob . Devlin . Ming-Wei . Chang . BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding . 11 October 2018 . Lee . Kenton . Toutanova . Kristina.
  29. Web site: 2020-10-15 . Google: BERT now used on almost every English query . 2020-11-24 . Search Engine Land.
  30. Web site: Recent Advances in Google Translate . 2024-05-08 . research.google . en.
  31. Web site: The inside story of how ChatGPT was built from the people who made it . 2024-08-06 . MIT Technology Review . en.
  32. Web site: June 11, 2018 . Improving language understanding with unsupervised learning . live . https://web.archive.org/web/20230318210736/https://openai.com/research/language-unsupervised . 2023-03-18 . 2023-03-18 . openai.com.
  33. 2010.11929 . cs.CV . Alexey . Dosovitskiy . Lucas . Beyer . An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale . 2021-06-03 . Kolesnikov . Alexander . Weissenborn . Dirk . Zhai . Xiaohua . Unterthiner . Thomas . Dehghani . Mostafa . Minderer . Matthias . Heigold . Georg . Gelly . Sylvain . Uszkoreit . Jakob.
  34. Liu . Zhuang . Mao . Hanzi . Wu . Chao-Yuan . Feichtenhofer . Christoph . Darrell . Trevor . Xie . Saining . 2022 . Conference on Computer Vision and Pattern Recognition . A ConvNet for the 2020s . en . 11976–11986.
  35. 2002.04745 . cs.LG . Ruibin . Xiong . Yunchang . Yang . On Layer Normalization in the Transformer Architecture . 2020-06-29 . He . Di . Zheng . Kai . Zheng . Shuxin . Xing . Chen . Zhang . Huishuai . Lan . Yanyan . Wang . Liwei . Liu . Tie-Yan.
  36. Raffel . Colin . Shazeer . Noam . Roberts . Adam . Lee . Katherine . Narang . Sharan . Matena . Michael . Zhou . Yanqi . Li . Wei . Liu . Peter J. . 2020-01-01 . Exploring the limits of transfer learning with a unified text-to-text transformer . The Journal of Machine Learning Research . 21 . 1 . 140:5485–140:5551 . 1910.10683 . 1532-4435.
  37. https://arxiv.org/pdf/1910.10683
  38. Web site: Masked language modeling . 2023-10-05 . huggingface.co.
  39. Web site: Causal language modeling . 2023-10-05 . huggingface.co.
  40. 1810.04805v2 . cs.CL . Jacob . Devlin . Ming-Wei . Chang . BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding . 11 October 2018 . Lee . Kenton . Toutanova . Kristina.
  41. Web site: Sequence Modeling with Neural Networks (Part 2): Attention Models. 2016-04-18. Indico. 2019-10-15. 2020-10-21. https://web.archive.org/web/20201021203352/https://indico.io/blog/sequence-modeling-neural-networks-part2-attention-models/. live.
  42. Web site: Alammar . Jay . The Illustrated Transformer . live . https://web.archive.org/web/20201018061610/https://jalammar.github.io/illustrated-transformer/ . 2020-10-18 . 2019-10-15 . jalammar.github.io.
  43. Web site: Team . Keras . Keras documentation: GPT2Backbone model . 2024-08-08 . keras.io . en.
  44. Clark. Kevin . Khandelwal. Urvashi. Levy. Omer. Manning. Christopher D.. August 2019. What Does BERT Look at? An Analysis of BERT's Attention. Proceedings of the 2019 ACL Workshop BlackboxNLP: Analyzing and Interpreting Neural Networks for NLP. Florence, Italy. Association for Computational Linguistics. 276–286. 10.18653/v1/W19-4828. free. 2020-05-20. 2020-10-21. https://web.archive.org/web/20201021211357/https://www.aclweb.org/anthology/W19-4828/. live. 1906.04341.
  45. Yang . Zhilin . Dai . Zihang . Yang . Yiming . Carbonell . Jaime . Salakhutdinov . Russ R . Le . Quoc V . 2019 . XLNet: Generalized Autoregressive Pretraining for Language Understanding . Advances in Neural Information Processing Systems . Curran Associates, Inc. . 32. 1906.08237 .
  46. Raffel . Colin . Shazeer . Noam . Roberts . Adam . Lee . Katherine . Narang . Sharan . Matena . Michael . Zhou . Yanqi . Li . Wei . Liu . Peter J. . 2020 . Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer . Journal of Machine Learning Research . 21 . 140 . 1–67 . 1910.10683 . 1533-7928.
  47. Web site: June 8, 2020 . Recent Advances in Google Translate . live . https://web.archive.org/web/20240704042433/https://research.google/blog/recent-advances-in-google-translate/ . 4 Jul 2024 . 2024-08-07 . Google Research . en.
  48. 2002.05202 . cs.LG . Noam . Shazeer . GLU Variants Improve Transformer . 2020-02-01.
  49. Hendrycks . Dan . Gimpel . Kevin . 2016-06-27 . Gaussian Error Linear Units (GELUs) . cs.LG . 1606.08415v5 . en.
  50. Zhang . Biao . Sennrich . Rico . 2019 . Root Mean Square Layer Normalization . Advances in Neural Information Processing Systems . Curran Associates, Inc. . 32. 1910.07467 .
  51. Nguyen . Toan Q. . Salazar . Julian . 2019-11-02 . Niehues . Jan . Cattoni . Rolando . Stüker . Sebastian . Negri . Matteo . Turchi . Marco . Ha . Thanh-Le . Salesky . Elizabeth . Sanabria . Ramon . Barrault . Loic . Transformers without Tears: Improving the Normalization of Self-Attention . Proceedings of the 16th International Conference on Spoken Language Translation . Hong Kong . Association for Computational Linguistics. 10.5281/zenodo.3525484 . 1910.05895 .
  52. Dufter . Philipp . Schmitt . Martin . Schütze . Hinrich . 2022-06-06 . Position Information in Transformers: An Overview . Computational Linguistics . 48 . 3 . 733–763 . 10.1162/coli_a_00445 . 0891-2017 . 231986066 . free. 2102.11090 .
  53. Gehring . Jonas . Auli . Michael . Grangier . David . Yarats . Denis . Dauphin . Yann N. . 2017-07-17 . Convolutional Sequence to Sequence Learning . Proceedings of the 34th International Conference on Machine Learning . en . PMLR . 1243–1252.
  54. Su . Jianlin . Lu . Yu . Pan . Shengfeng . Murtadha . Ahmed . Wen . Bo . Liu . Yunfeng . 2021-04-01 . RoFormer: Enhanced Transformer with Rotary Position Embedding . cs.CL . 2104.09864 .
  55. Press . Ofir . Smith . Noah A. . Lewis . Mike . 2021-08-01 . Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation . cs.CL . 2108.12409 .
  56. Shaw . Peter . Uszkoreit . Jakob . Vaswani . Ashish . 2018 . Self-Attention with Relative Position Representations . cs.CL . 1803.02155.
  57. Dao . Tri . Fu . Dan . Ermon . Stefano . Rudra . Atri . Ré . Christopher . 2022-12-06 . FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness . Advances in Neural Information Processing Systems . 35 . 16344–16359. 2205.14135.
  58. Web site: Stanford CRFM . 2023-07-18 . crfm.stanford.edu.
  59. Web site: 2023-06-17 . FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning . 2023-07-18 . Princeton NLP .
  60. Web site: Introducing Together AI Chief Scientist Tri Dao, as he releases FlashAttention-2 to speed up model training and inference . 2023-07-18 . TOGETHER .
  61. Chowdhery . Aakanksha . Narang . Sharan . Devlin . Jacob . Bosma . Maarten . Mishra . Gaurav . Roberts . Adam . Barham . Paul . Chung . Hyung Won . Sutton . Charles . Gehrmann . Sebastian . Schuh . Parker . Shi . Kensen . Tsvyashchenko . Sasha . Maynez . Joshua . Rao . Abhishek . 2022-04-01 . PaLM: Scaling Language Modeling with Pathways . cs.CL . 2204.02311 .
  62. Book: Kwon . Woosuk . Li . Zhuohan . Zhuang . Siyuan . Sheng . Ying . Zheng . Lianmin . Yu . Cody Hao . Gonzalez . Joseph . Zhang . Hao . Stoica . Ion . Efficient Memory Management for Large Language Model Serving with PagedAttention . 2023-10-23 . Proceedings of the 29th Symposium on Operating Systems Principles . https://dl.acm.org/doi/10.1145/3600006.3613165 . SOSP '23 . New York, NY, USA . Association for Computing Machinery . 611–626 . 10.1145/3600006.3613165 . 979-8-4007-0229-7. 2309.06180 .
  63. Web site: Contribution) . Woosuk Kwon*, Zhuohan Li*, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Yu, Joey Gonzalez, Hao Zhang, and Ion Stoica (* Equal . 2023-06-20 . vLLM: Easy, Fast, and Cheap LLM Serving with PagedAttention . 2024-06-20 . vLLM Blog . en.
  64. Web site: Towards 100x Speedup: Full Stack Transformer Inference Optimization. Yao. Fu. 2023-12-13.
  65. 2001.04451 . cs.LG . Nikita . Kitaev . Łukasz . Kaiser . Reformer: The Efficient Transformer . Levskaya . Anselm . 2020.
  66. 2011.04006 . cs.LG . Yi . Tay . Mostafa . Dehghani . Long Range Arena: A Benchmark for Efficient Transformers . 2020-11-08 . Abnar . Samira . Shen . Yikang . Bahri . Dara . Pham . Philip . Rao . Jinfeng . Yang . Liu . Ruder . Sebastian . Metzler . Donald.
  67. Web site: 16 January 2020 . Reformer: The Efficient Transformer . live . https://web.archive.org/web/20201022210019/https://ai.googleblog.com/2020/01/reformer-efficient-transformer.html . 2020-10-22 . 2020-10-22 . Google AI Blog.
  68. Gomez . Aidan N . Ren . Mengye . Urtasun . Raquel . Grosse . Roger B . 2017 . The Reversible Residual Network: Backpropagation Without Storing Activations . Advances in Neural Information Processing Systems . Curran Associates, Inc. . 30.
  69. Web site: 25 March 2021 . Constructing Transformers For Longer Sequences with Sparse Attention Methods . live . https://web.archive.org/web/20210918150757/https://ai.googleblog.com/2021/03/constructing-transformers-for-longer.html . 2021-09-18 . 2021-05-28 . Google AI Blog.
  70. 2105.14103 . cs.LG . Shuangfei . Zhai . Walter . Talbott . An Attention Free Transformer . 2021-09-21 . Srivastava . Nitish . Huang . Chen . Goh . Hanlin . Zhang . Ruixiang . Susskind . Josh.
  71. Peng . Hao . Pappas . Nikolaos . Yogatama . Dani . Schwartz . Roy . Smith . Noah A. . Kong . Lingpeng . 2021-03-19 . Random Feature Attention . cs.CL . 2103.02143.
  72. Choromanski . Krzysztof . Likhosherstov . Valerii . Dohan . David . Song . Xingyou . Gane . Andreea . Sarlos . Tamas . Hawkins . Peter . Davis . Jared . Belanger . David . Colwell . Lucy . Weller . Adrian . 2020-09-30 . Masked Language Modeling for Proteins via Linearly Scalable Long-Context Transformers . cs.LG . 2006.03555.
  73. Lu . Kevin . Grover . Aditya . Abbeel . Pieter . Mordatch . Igor . 2022-06-28 . Frozen Pretrained Transformers as Universal Computation Engines . Proceedings of the AAAI Conference on Artificial Intelligence . en . 36 . 7 . 7628–7636 . 10.1609/aaai.v36i7.20729 . 2374-3468. free .
  74. Web site: Vicuna: An Open-Source Chatbot Impressing GPT-4 with 90%* ChatGPT Quality LMSYS Org . 2024-08-11 . lmsys.org . en.
  75. Liu . Haotian . Li . Chunyuan . Wu . Qingyang . Lee . Yong Jae . 2023-12-15 . Visual Instruction Tuning . Advances in Neural Information Processing Systems . en . 36 . 34892–34916.
  76. 2005.08100 . Anmol . Gulati . James . Qin . Conformer: Convolution-augmented Transformer for Speech Recognition . Chiu . Chung-Cheng . Parmar . Niki . Zhang . Yu . Yu . Jiahui . Han . Wei . Wang . Shibo . Zhang . Zhengdong . Wu . Yonghui . Pang . Ruoming . 2020 . eess.AS .
  77. 2212.04356 . Alec . Radford . Jong Wook . Kim . Robust Speech Recognition via Large-Scale Weak Supervision . Xu . Tao . Brockman . Greg . McLeavey . Christine . Sutskever . Ilya . 2022 . eess.AS .
  78. 2103.03206 . cs.CV . Andrew . Jaegle . Felix . Gimeno . Perceiver: General Perception with Iterative Attention . 2021-06-22 . Brock . Andrew . Zisserman . Andrew . Vinyals . Oriol . Carreira . Joao.
  79. 2107.14795 . cs.LG . Andrew . Jaegle . Sebastian . Borgeaud . Perceiver IO: A General Architecture for Structured Inputs & Outputs . 2021-08-02 . Alayrac . Jean-Baptiste . Doersch . Carl . Ionescu . Catalin . Ding . David . Koppula . Skanda . Zoran . Daniel . Brock . Andrew . Shelhamer . Evan . Hénaff . Olivier.
  80. Web site: Parti: Pathways Autoregressive Text-to-Image Model . 2024-08-09 . sites.research.google.
  81. Kariampuzha . William . Alyea . Gioconda . Qu . Sue . Sanjak . Jaleal . Mathé . Ewy . Sid . Eric . Chatelaine . Haley . Yadaw . Arjun . Xu . Yanji . Zhu . Qian . 2023 . Precision information extraction for rare disease epidemiology at scale . Journal of Translational Medicine . 21 . 1 . 157 . 10.1186/s12967-023-04011-y . 9972634 . 36855134 . free.