The Transformer Architecture
- Vaswani et al. (2017) "Attention is All You Need" introduced the Transformer architecture, replacing RNNs entirely
- Self-attention computes dependencies between all pairs of tokens simultaneously - unlike RNNs which are sequential
- BERT, GPT, T5, and all modern LLMs are Transformer-based
The Transformer processes sequences by having each token attend to every other token simultaneously via scaled dot-product attention. Multi-head attention runs several attention operations in parallel. Positional encodings add sequence order since there is no recurrence.
- Attention mechanism is the core operation - see the Attention page for deep dive
- BERT uses bidirectional encoder Transformers; GPT uses causal decoder Transformers
- Every modern LLM, vision model (ViT), and multimodal model (CLIP) uses Transformer blocks
- Diagram the Vaswani 2017 encoder block, decoder block, and full encoder-decoder, naming every sublayer and residual connection.
- Compare sinusoidal, learned, RoPE, and ALiBi positional encodings on length-extrapolation, parameter count, and inference cost.
- Explain why pre-norm trains stably at depth and post-norm needs warmup, citing Xiong 2020.
- Derive Transformer FLOPs and parameters per block in terms of d_model, d_ff, num_heads, sequence length, and depth.
- Compute KV-cache memory and prefill vs decode FLOPs for autoregressive inference, and explain the systems consequences.
TL;DR
A Transformer block is multi-head self-attention plus a token-wise feed-forward network, each wrapped in a residual + layer-norm. The encoder is a stack of these; the decoder adds masked self-attention plus encoder-decoder cross-attention. Position is injected explicitly: Vaswani 2017 used sinusoidal encodings [1], modern LLMs prefer RoPE [2] for clean rotation-based locality and ALiBi [3] for length extrapolation. Pre-norm (LayerNorm inside the residual) trains stably at 100+ layers without learning-rate warmup; post-norm needs warmup but slightly outperforms at small depth [4]. Inference splits into a one-time prefill (full pass over the prompt) and a per-token decode that reads from a KV cache of size floats. The cache is what limits practical context length, not flops. Variants: Transformer-XL [5] for segment recurrence, Sparse Transformer [6] for attention, and Mixture-of-Experts [7][8] for sparse parameter scaling.
Intuition
The Transformer is a stack of “attend, then mix” blocks. Attend lets every token gather information from every other token via scaled dot-product self-attention. Mix is a small two-layer MLP applied independently to each token’s vector, which lets the network do non-linear feature combination after the attention has gathered the relevant evidence. The Transformer is the architecture that took deep learning [10] from “wins on vision and speech” to “wins on essentially every sequence-modelling task that has data”.
Two things make the architecture practical at scale. First, every operation is fully parallel across the sequence dimension: there is no recurrence to break, so an entire sequence trains in one matmul-heavy forward and backward pass. Second, residual connections around every sublayer give gradients an unobstructed path to the embedding layer, the same idea ResNet used to make 100+ layer vision networks trainable. Stacking 96 Transformer blocks (GPT-3 scale) is no harder than stacking 6 (the original Vaswani 2017 base model), modulo positional-encoding and norm-placement choices.
Every Transformer block does the same three jobs:
- Attention is a content-based gather across positions: each token reads a weighted summary of all other tokens.
- MLP is a position-wise non-linear transform: each token vector is run through a 2-layer MLP with hidden size , in parallel across positions.
- Residual + LayerNorm keeps the signal flowing: the block computes a delta added to the residual stream, the layer-norm renormalizes for the next block.
A clean way to read a Transformer is “the residual stream is the working memory; each block reads from it (attention), processes (MLP), and writes back (residual add).” The interpretability literature has formalized this view; treat the residual stream as the bus and each block as a peripheral that reads, transforms, and writes.
The Vaswani 2017 architecture
The original paper specified three things together: an encoder block, a decoder block, and a sinusoidal positional encoding. We will walk through each.
The encoder block
Inputs: a sequence of token embeddings with positional encoding already added. One encoder block computes
where is multi-head self-attention over and is a two-layer MLP applied to each row independently:
The original used ReLU and ; modern Transformers swap to GeLU or SwiGLU and keep the rule of thumb [9]. Note that the layer-norm appears after the residual add: this is post-norm, the original choice. Most modern LLMs flip it (see Pre-norm vs post-norm below).
A full encoder is identical blocks stacked. There is no causal mask (encoders are bidirectional), so token can attend to every other token at every layer.
The decoder block
The decoder takes the previously generated tokens (during training: the gold target shifted right; during inference: its own past outputs), embeds them, adds positional encoding, then runs a stack of decoder blocks. One decoder block has three sublayers:
The first sublayer is masked self-attention: the upper-triangular mask ensures position only attends to positions on the decoder side. The second sublayer is cross-attention: queries come from the decoder, keys and values come from the encoder output. The third is the same FFN as the encoder. Decoder-only models (GPT family) drop the cross-attention and keep just (masked self-attention, FFN); encoder-only models (BERT) drop the decoder entirely. See Encoder, Decoder & Encoder-Decoder Models for the full taxonomy.
Parameter and FLOP accounting
Per encoder block, parameters are dominated by:
- projections: params total.
- Two FFN layers: params if .
- LayerNorm scales/biases: (negligible).
Total: params per block. A decoder block adds another set of for cross-attention, taking it to . For a base Transformer with , , this is about M params per encoder stack.
FLOPs per token per encoder block (forward only):
- Attention: for the four projections, for the score and value matmul. For the full sequence it is .
- FFN: .
The crossover where attention overtakes the FFN in flops is at . For (GPT-3-class) that’s . So at typical training context lengths the FFN still dominates flops; attention starts to dominate only for long-context training.
Positional encodings
Pure self-attention is permutation-equivariant (proof in Attention), so the model has no notion of order until you inject one. The four production choices:
Sinusoidal, learned, RoPE, and ALiBi: the four positional encodings
Sinusoidal (Vaswani 2017)
Add a fixed sinusoidal encoding to the input embeddings before the first block:
The encoding is deterministic (no parameters) and has an attractive property: the encoding for position is a fixed linear function of the encoding at position , so relative offsets are linearly recoverable. Empirically the model can extrapolate moderately past the training length but degrades quickly past 2x.
Learned absolute
Replace the sinusoid with a trainable lookup table . BERT and GPT-2 both used this. Pros: simple, the model can learn whatever positional structure is useful. Cons: cannot extrapolate past at all; doubling context length requires retraining.
RoPE: rotary position embedding
RoPE [2] applies a 2D rotation to query and key vectors per position, inside the attention computation rather than as an additive embedding. Pair the components of and into 2D vectors . For position , multiply each pair by the rotation matrix
with (the same frequencies as the sinusoidal encoding). The crucial identity:
The dot product depends only on the relative offset , not the absolute positions. So RoPE-attention is automatically translation-invariant in position, which matches how relative position should affect attention. RoPE is what Llama, Mistral, Qwen, and most open LLMs use.
Cost: zero parameters, but each attention call must apply the rotation to and . A few extra flops, negligible memory.
ALiBi: attention with linear biases
ALiBi [3] goes the opposite direction: leave and alone, and instead add a linear bias to the score matrix:
where is a per-head fixed slope (the paper gives a geometric schedule for head of ). Closer keys get smaller penalty; farther keys get larger penalty. This is a hard-coded “attend to nearby tokens more” prior with zero parameters.
The win that earned ALiBi its keep is length extrapolation: a model trained at generates coherent text at at inference. RoPE used to extrapolate poorly until the “RoPE scaling” tricks (NTK-aware, YaRN, dynamic) closed most of the gap. As of 2024 RoPE+scaling has won on the open-LLM side, but ALiBi remains competitive in some long-context-from-day-one regimes.
| Encoding | Parameters | Where applied | Length extrapolation | Used by |
|---|---|---|---|---|
| Sinusoidal (Vaswani) | 0 | Added to input embedding | Modest (degrades past 2x training length) | Original Transformer, T5 (relative variant) |
| Learned absolute | n_max * d | Added to input embedding | None (hard limit at n_max) | BERT, GPT-2 |
| RoPE | 0 | Multiplicative rotation on Q, K inside attention | Good with NTK/YaRN scaling tricks | Llama, Mistral, Qwen, GPT-NeoX |
| ALiBi | 0 (per-head fixed slope) | Additive bias to score matrix | Excellent out of the box | BLOOM, MPT |
| T5 relative | O(num_buckets * h) | Additive bias to score matrix indexed by relative offset bucket | Good | T5, mT5 |
Pre-norm vs post-norm
LayerNorm placement is the single most important “small” knob in the Transformer.
The original Transformer used post-norm: . The norm sits after the residual add. Xiong et al. [4] showed that for a deep stack, post-norm has gradient magnitude that depends on depth in a way that requires careful learning-rate warmup; without warmup, training diverges past about 12 layers.
Pre-norm moves the norm inside the residual: . The proof in Xiong 2020 shows the gradient at the input is bounded by instead of , so deep stacks have stable gradients without warmup. Empirically pre-norm trains 100+ layer models with no fuss; this is the architecture every modern LLM uses (Llama, GPT, Mistral).
The trade-off: pre-norm sometimes gives slightly worse final loss at small depth (12 layers and below), because the un-normalized residual stream can grow large and the model has less direct control over the sublayer input scale. For LLM scale (depth ) pre-norm is strictly better.
| Property | Post-norm (original) | Pre-norm (modern) |
|---|---|---|
| Formula | X_{l+1} = LN(X_l + Sublayer(X_l)) | X_{l+1} = X_l + Sublayer(LN(X_l)) |
| Gradient at input as a function of depth L | O(sqrt(L)) | 1 + O(1/L) |
| Warmup required at depth? | Yes (Vaswani used 4000 steps) | No |
| Trainable past 24 layers without tricks? | No | Yes |
| Final loss at small depth (6-12 layers) | Slightly better | Slightly worse |
| Final loss at LLM depth (24+ layers) | Diverges or needs careful tricks | Strictly better |
| Used by | Original Transformer, BERT, T5 | GPT-2, GPT-3, Llama, Mistral, most modern LLMs |
KV cache and inference math
Training and inference look almost identical for a Transformer, but inference has one structural difference: autoregressive decoding generates one token at a time, and naively re-running the full forward pass for each token would cost per token. The KV cache fixes this.
Prefill vs decode and KV-cache memory
Two phases of inference
Generating a response from a prompt of length followed by generated tokens splits into:
- Prefill. Run the full Transformer forward on the -token prompt in one shot. Compute the keys and values for every position at every layer and every head, and cache them in the KV cache. Cost: FLOPs. Done once.
- Decode. For each generated token : project the new token to , append to the cache, compute attention by reading the entire cache, and produce the next token. Cost per generated token: FLOPs (linear in current sequence length). Done times.
So total FLOPs are roughly , but with a very different memory access pattern. Prefill is matmul-heavy (parallel across ). Decode is memory-bandwidth-heavy: each generated token reads the entire cache, does a few small matmuls, writes one row back.
KV cache size
Per layer, per head, each token cached holds floats for the key and floats for the value. With layers, heads, , and sequence length , the cache size is
In bf16 (2 bytes), a 70B Llama-3 with , at has
per request, just for the KV cache. That is why batched inference is hard: each user gets their own cache, and aggregating ten users instantly fills an 80 GB H100. Grouped-query attention (GQA) and multi-query attention (MQA) cut this by sharing across groups of heads; Llama-3-70B uses GQA with 8 KV-heads instead of 64, cutting cache to about 2.6 GB.
Decode latency is bandwidth-bound
Generating one token reads the entire KV cache from HBM. At 21 GB cache and 1 TB/s HBM, that is 21 ms minimum per token, before any compute, just from memory transfer. This is why long-context decoding is slow per token even though compute is low: you cannot escape the bandwidth read. FlashDecoding, paged-attention (vLLM), and speculative decoding are all systems-level fixes for this fundamental constraint.
Modern variants
A small zoo of Transformer variants has appeared since 2017. The four worth knowing for interview depth:
- 2019Transformer-XLpaper
Segment-level recurrence: cache hidden states from the previous segment as additional context, with relative position encoding. Lets the model carry context across segments without retraining on longer sequences.
- 2019Sparse Transformer (Child et al.)efficient
Replace full attention with strided + local sparse patterns. Cuts attention cost from O(n^2) to O(n sqrt(n)) while retaining most quality on long-context tasks.
- 0.9980207817911925Mixture-of-Experts (Shazeer 2017, Switch Transformer 2021)architecture
Replace the FFN with a router over E expert FFNs; each token activates the top-1 or top-2 experts. Total parameters scale with E, FLOPs per token stay constant.
- 2022FlashAttentionsystem
Exact attention with O(n) memory via tiled softmax in SRAM. Drop-in replacement, ubiquitous in modern LLM training and inference. Detail: see Attention page.
Mixture-of-Experts in one paragraph
Replace the FFN sublayer with “expert” FFNs and a learned router: a small linear that produces routing logits per token. Top- routing picks the experts with the largest logits and runs only those. The output is the (renormalized) weighted sum of expert outputs. Switch Transformer [8] uses (one expert per token, simplest possible routing). The result is a model with FFN parameters but the same FLOPs per token as a dense model, since each token activates only one expert. Mixtral-8x7B is 8 experts of 7B-FFN each; total params 47B, active params 13B. The catch is load balancing: without an auxiliary loss, the router collapses to a few favorite experts and the rest go untrained.
A from-scratch encoder block
A complete encoder block in about 80 lines of PyTorch:
import torch
import torch.nn as nn
import torch.nn.functional as F
class MultiHeadSelfAttention(nn.Module):
def __init__(self, d_model: int, n_heads: int, dropout: float = 0.0):
super().__init__()
assert d_model % n_heads == 0
self.n_heads = n_heads
self.d_k = d_model // n_heads
# Fused QKV projection: one big linear instead of three.
self.qkv = nn.Linear(d_model, 3 * d_model)
self.proj = nn.Linear(d_model, d_model)
self.dropout = nn.Dropout(dropout)
def forward(self, x: torch.Tensor, mask: torch.Tensor | None = None):
B, N, D = x.shape
qkv = self.qkv(x).reshape(B, N, 3, self.n_heads, self.d_k)
q, k, v = qkv.unbind(dim=2) # each (B, N, H, d_k)
q, k, v = (t.transpose(1, 2) for t in (q, k, v)) # (B, H, N, d_k)
# PyTorch dispatches to FlashAttention on supported GPUs.
out = F.scaled_dot_product_attention(q, k, v, attn_mask=mask, dropout_p=0.0)
out = out.transpose(1, 2).reshape(B, N, D)
return self.dropout(self.proj(out))
class TransformerEncoderBlock(nn.Module):
"""Pre-norm encoder block: x + Sublayer(LN(x))."""
def __init__(self, d_model: int, n_heads: int, d_ff: int, dropout: float = 0.0):
super().__init__()
self.ln1 = nn.LayerNorm(d_model)
self.attn = MultiHeadSelfAttention(d_model, n_heads, dropout)
self.ln2 = nn.LayerNorm(d_model)
self.ffn = nn.Sequential(
nn.Linear(d_model, d_ff),
nn.GELU(),
nn.Linear(d_ff, d_model),
)
self.dropout = nn.Dropout(dropout)
def forward(self, x: torch.Tensor, mask: torch.Tensor | None = None):
x = x + self.attn(self.ln1(x), mask)
x = x + self.dropout(self.ffn(self.ln2(x)))
return x
# Sanity: forward a dummy batch through a 6-layer encoder.
torch.manual_seed(0)
x = torch.randn(4, 16, 512)
blocks = nn.Sequential(*[TransformerEncoderBlock(512, 8, 2048) for _ in range(6)])
y = blocks(x)
print(y.shape) # (4, 16, 512)Transformer vs RNN vs CNN for sequence modelling
| Property | RNN / LSTM | CNN (1D) | Transformer |
|---|---|---|---|
| Parallelism across time | No (sequential h_t depends on h_{t-1}) | Yes (each conv is parallel) | Yes (full sequence in one matmul) |
| Long-range dependency | Limited (vanishing gradient even with LSTM gating) | Receptive field grows linearly with depth | Direct any-to-any in one layer |
| Per-layer compute | O(n d^2) | O(n k d^2) | O(n^2 d) attn + O(n d^2) FFN |
| Memory at training | O(n d) activations | O(n d) activations | O(n^2) attention activations (or O(n) with FlashAttention) |
| Inductive bias | Recency, sequential dependence | Locality, translation equivariance | None (data-driven; needs positional encoding) |
| Inference autoregressive cost | O(d^2) per token (RNN state update) | O(k d^2) per token | O(n d) per token (KV cache read) |
| Parameter count for fixed budget | Smallest | Mid | Largest (FFN dominates) |
| Why it eventually won | Dominated NLP through 2016 | Dominated NLP-via-CNN through 2017 (ConvS2S, ByteNet) | Parallelism + scale wins (Vaswani 2017 onward) |
Pitfalls
A vanilla Transformer block has no notion of order. If you swap the input from sinusoidal-PE BERT to RoPE Llama by changing only the embeddings, the rest of the architecture has nothing to anchor positions. Always check that every attention call has a positional mechanism applied: either to the input embedding (sinusoidal, learned) or inside attention (RoPE, ALiBi, T5 relative). The bug is silent: training looks normal at first, then plateaus.
The original Transformer ties the input embedding matrix to the output projection (the “softmax weights”): both are . This halves the parameter count and ties the geometry of the input and output token spaces. Most modern LLMs untie them because at scale the savings are marginal but the constraint hurts (Llama 3 is untied; PaLM is untied; Gemma is tied for the 2B and untied for the 7B+). When loading a pretrained model, check the tied/untied state in the config; passing tied weights to an untied model is a silent shape mismatch.
You will hit OOM on the KV cache long before you hit OOM on weights. A 13B model in bf16 takes 26 GB for weights, and at takes another GB for the cache; at it is GB. Multiply by batch size for serving. Standard fixes: grouped-query attention (Llama-3), paged-attention (vLLM, SGLang) which fragments the cache into pages so different requests can share blocks, and quantizing the cache itself to int8 or int4. Bandwidth bound at decode time means even a “free” cache hit costs latency.
If you are training a Transformer from scratch at depth , use pre-norm and skip the warmup schedule. Pre-norm + a constant or cosine learning rate is the modern default and trains fine to hundreds of layers. Post-norm + 4000-step warmup matches the original recipe and is fine at small depth, but it is a fragile combo in production: a warmup-step misconfigure on a checkpoint resume will diverge silently [4].
Pop quiz
- 1. A Transformer encoder block has approximately how many parameters in terms of d_model, with d_ff = 4 * d_model?
- 2. Why does pre-norm train more stably than post-norm at depth above 24 layers?
- 3. What is the KV cache memory for a Transformer with L layers, d model dimension, sequence length n, in bf16?
- 4. RoPE applies position information by:
- 5. Mixture-of-Experts (Switch Transformer) replaces the FFN with E experts and top-1 routing. The effect on parameters and FLOPs per token is:
Interview Q&A
Derive Transformer FLOPs per training step in terms of d_model, d_ff, sequence length n, depth L, and batch size B.onsite
Per layer, per token, forward. Two contributions:
- Attention. Q, K, V projections: FLOPs per token (each is a matmul). Output projection: . Score matmul : FLOPs per token. Softmax: FLOPs per token (cheap). Multiply by V: per token. Total attention: FLOPs per token.
- FFN. Two matmuls: each, and a typical , so FLOPs per token.
Per token, per layer, forward: FLOPs. Backward is forward (one re-evaluate plus the gradient matmul), so per token, per layer, total: FLOPs.
Ignoring the attention-score term (which dominates only for ):
A useful approximation when scoring estimates: a rule of thumb is FLOPs per token where is total parameters (factor 6 = 2 forward + 4 backward in fused form). For a 175B model on 300B tokens, FLOPs total, matching the GPT-3 published number.
The key takeaways are: (i) FFN dominates compute at typical , (ii) attention overtakes FFN above , (iii) doubling depth doubles FLOPs at fixed , and (iv) doubling quadruples FLOPs, which is why scaling-laws fits care so much about the relative growth of and .
Derive RoPE: show that rotating Q and K by R(theta, pos) makes the attention score depend only on the relative position.onsite
Setup. Pair the components of into 2D vectors. For each pair index and each token position , define the rotation
with frequency . RoPE rotates each pair of by this matrix at its own position before computing the dot product.
Key identity. A 2D rotation is multiplicative in angle: and . So for query at position and key at position :
The right-hand side depends only on the relative offset , not on the absolute positions and separately. So translating both query and key by the same offset leaves the dot product unchanged: RoPE-attention is translation-invariant in position.
Why it generalizes. Independence of absolute position is exactly the property a model should have for natural language: “the dog ran” should look the same to attention whether it appears at position 5 or position 5000. With RoPE, any pair of tokens at offset produces the same dot product regardless of where they sit in the sequence. With absolute (sinusoidal or learned) position, translating the sentence shifts every dot product by some position-dependent amount.
Length extrapolation. RoPE’s dependence on relative offset, plus the smooth decay of high-frequency components past the training length, means a RoPE-trained model has a smooth degradation past rather than a hard cliff. Modern “RoPE scaling” tricks (NTK-aware, YaRN, dynamic) reshape the frequency spectrum so the model extrapolates 4-32x past training length with fine-tuning of just a few hundred steps [2].
Why pre-norm wins for deep nets, mathematically.research
Setup. A pre-norm Transformer applies LayerNorm inside the residual: . A post-norm Transformer applies it outside: .
Forward variance. In pre-norm, the residual stream is never re-normalized between blocks, so its variance can grow: at layer , is approximately where is the per-block sublayer-output variance (independent residual increments). The LN inside the sublayer rescales the input to to unit variance. So sublayer inputs stay normalized while the residual stream grows.
In post-norm, the residual is normalized at every layer, so . But the sublayer input is the previous post-norm output, which is unit-variance, and the residual + sublayer output then gets re-normalized.
Backward gradient. Differentiate the recurrence. In pre-norm, . The LN Jacobian shrinks the second term as , which grows like . So the Jacobian product over the full stack is , which Xiong shows is at depth . Bounded.
In post-norm, the LN is on the residual + sublayer output, and its Jacobian factor multiplies the whole residual, not just the sublayer increment. The chain ends up multiplying independent LN Jacobians of magnitude , giving a total gradient norm of order at the input layer. This is why training without warmup diverges past : the gradient at the input is too large at small step counts [4].
Practical consequence. Pre-norm trains stably out of the box at any depth; post-norm needs a warmup of steps to compensate. For depth 100+ models (modern LLMs), pre-norm is the only reasonable choice. Empirically pre-norm slightly underfits at small depth (6-12 layers), which is why some legacy NMT and BERT-style models still use post-norm [1].
Compute the KV-cache memory and decode latency for a 70B Llama-3-class model at n = 8192 in bf16. How does grouped-query attention change it?staff
Llama-3-70B params. , , , . With multi-head attention, each layer caches and for every head, so per token, per layer the cache is floats. Times 80 layers, 8192 tokens, 2 bytes (bf16):
That is bigger than half the model weights (140 GB in bf16) per request. At batch size 4, GB, which already exceeds an 80 GB H100.
With grouped-query attention. Llama-3-70B uses GQA with KV heads (the 64 query heads are grouped into 8 groups of 8 that share K, V). Cache per layer per token: floats. Total at :
A 8x reduction, with negligible quality loss. This is what makes serving 70B-class models with multi-thousand-token context realistic on a single 80 GB GPU.
Decode latency. Generating one token reads the entire cache from HBM. With TB/s effective bandwidth, the floor is
just from KV-cache memory transfer, before any compute. At 21.5 GB without GQA, the floor is 21 ms / token. This is why bandwidth, not flops, dominates LLM decode latency, and why systems work (vLLM paged-attention, FlashDecoding, speculative decoding) targets the read pattern rather than the compute.
A useful cross-check: dense compute per generated token at is FLOPs, which an H100 (about 800 TFLOPs effective at bf16) does in ms. So compute is 10x faster than memory bandwidth at the relevant scale, confirming the bound is bandwidth.
A weekend-scale project that takes the Transformer from formulas to a working tiny LM:
- Implement the from-scratch encoder block above. Verify forward shapes match
nn.TransformerEncoderLayeron a fixed seed. - Add a learned absolute positional embedding and train a tiny BERT (4 layers, , 2 heads) on Wikipedia sentences with masked-language modelling. Get the training loss curve and confirm it goes below .
- Swap to RoPE, retrain, and read the loss differential. RoPE typically wins by a small but consistent margin.
- Build a 12-layer decoder-only model with KV cache and confirm that adding
model.eval()plus the cache cuts per-token decode latency by roughly vs naive recompute-everything decoding. - Stretch: replace the FFN with a 4-expert MoE, train, and observe the parameter / flop trade-off in practice.
References
- Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, L., and Polosukhin, I. (2017). Attention Is All You Need. NeurIPS 2017. arXiv:1706.03762
- Su, J., Lu, Y., Pan, S., Murtadha, A., Wen, B., and Liu, Y. (2021). RoFormer: Enhanced Transformer with Rotary Position Embedding. arXiv preprint. arXiv:2104.09864
- Press, O., Smith, N. A., and Lewis, M. (2021). Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation. ICLR 2022 (arXiv preprint 2021). arXiv:2108.12409
- Xiong, R., Yang, Y., He, D., Zheng, K., Zheng, S., Xing, C., Zhang, H., Lan, Y., Wang, L., and Liu, T.-Y. (2020). On Layer Normalization in the Transformer Architecture. ICML 2020. arXiv:2002.04745
- Dai, Z., Yang, Z., Yang, Y., Carbonell, J., Le, Q. V., and Salakhutdinov, R. (2019). Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context. ACL 2019. arXiv:1901.02860
- Child, R., Gray, S., Radford, A., and Sutskever, I. (2019). Generating Long Sequences with Sparse Transformers. arXiv preprint. arXiv:1904.10509
- Shazeer, N., Mirhoseini, A., Maziarz, K., Davis, A., Le, Q., Hinton, G., and Dean, J. (2017). Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer. ICLR 2017. arXiv:1701.06538
- Fedus, W., Zoph, B., and Shazeer, N. (2021). Switch Transformer: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity. JMLR 2022 (arXiv preprint 2021). arXiv:2101.03961
- Goodfellow, I., Bengio, Y., and Courville, A. (2016). Deep Learning. MIT Press. https://www.deeplearningbook.org
- LeCun, Y., Bengio, Y., and Hinton, G. (2015). Deep learning. Nature 521, 436-444. doi:10.1038/nature14539