passdrill

How LLMs Work: Transformers & Training

12 cards · AI & LLM Engineering · answer each one, then read the explanation. Your score tallies below.

0 / 12 answered · 0 correct
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 001/012 medium

In the Transformer architecture introduced by Vaswani et al. (2017) in "Attention Is All You Need," the dot products between queries and keys are divided by the square root of the key dimension before the softmax is applied. What is the primary reason for this scaling step?

  1. It converts the attention weights into a probability distribution that sums to one across the sequence
  2. It reduces the number of parameters needed in the query, key, and value projection matrices
  3. It counteracts dot products growing large in magnitude for larger key dimensions, which would push the softmax into regions with extremely small gradients
  4. It allows the same attention weights to be reused across all heads in multi-head attention
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 002/012 easy

Vaswani et al. (2017) use multi-head attention instead of a single attention function operating on the full-dimensional queries, keys, and values. What was the main motivation for splitting attention into multiple heads?

  1. It lets the model jointly attend to information from different representation subspaces at different positions, since a single attention head would average this into one weighted combination
  2. It doubles the effective context window length by processing two halves of the input sequence in parallel
  3. It removes the need for positional encoding, because each head learns to represent a different position offset
  4. It ensures that every attention head produces an identical set of attention weights, providing an ensembling effect through redundancy
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 003/012 easy

The original Transformer architecture adds sinusoidal positional encodings to the input token embeddings before the first attention layer. Why is this necessary given how self-attention itself processes a sequence?

  1. Because the feed-forward sublayers in each block are recurrent and require explicit position indices to update their hidden state between positions
  2. Because self-attention computes a weighted sum over all positions regardless of order, so without added positional information the model would treat the input as an unordered set of tokens
  3. Because the token embedding layer cannot represent more than a fixed vocabulary size unless positional offsets are added to each embedding
  4. Because positional encodings replace the residual connections that would otherwise be required around each sublayer
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 004/012 medium

Sennrich et al. (2016), "Neural Machine Translation of Rare Words with Subword Units," introduced byte-pair encoding (BPE) as a tokenization method for handling rare and out-of-vocabulary words. How does the BPE algorithm build its subword vocabulary?

  1. It assigns a fixed-length numeric code to each whole word in a predetermined dictionary, discarding any word not already present in that dictionary
  2. It randomly samples character sequences of varying length from the training corpus until a target vocabulary size is reached
  3. It splits text purely along whitespace and punctuation boundaries, performing no further segmentation within a word
  4. It starts from individual characters and repeatedly merges the most frequent adjacent pair of symbols into a new symbol, learning a fixed number of merge operations to build a subword vocabulary
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 005/012 medium

Decoder-only autoregressive language models such as GPT (Radford et al., 2018) use masked self-attention during training. What does this masking do, and why is it necessary?

  1. It prevents the model from attending to tokens more than a fixed window size away, purely to reduce the compute cost of attention
  2. It forces every attention head to attend only to the current token itself, ignoring the representations at all other positions
  3. It sets the attention scores for future positions to negative infinity before the softmax, so a token's representation depends only on itself and earlier tokens, matching the left-to-right generation process
  4. It removes the value projection for positions beyond the current one, while still letting their key vectors influence the attention weights
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 006/012 hard

Hoffmann et al. (2022), "Training Compute-Optimal Large Language Models" (the Chinchilla paper), trained over 400 models to study how model size and training data should be allocated for a fixed compute budget. What was their central finding?

  1. For a fixed training compute budget, model parameters and training tokens should be scaled at roughly the same rate, implying substantially larger training datasets relative to model size than many earlier large models had used
  2. Model performance becomes essentially independent of the number of training tokens once the parameter count exceeds a few billion
  3. Compute-optimal training requires increasing model size much faster than training data, since parameter count is the dominant driver of capability
  4. The optimal ratio of training tokens to parameters decreases as total training compute increases, so very large models need proportionally less data
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 007/012 medium

Ouyang et al. (2022), "Training Language Models to Follow Instructions with Human Feedback" (the InstructGPT paper), describes a three-stage pipeline for aligning a pretrained language model with human preferences. What are the three stages, in order?

  1. Pretrain on a labeled classification dataset, then deploy directly without further tuning, since pretraining alone is assumed to capture human preferences
  2. Supervised fine-tuning on human-written demonstrations, followed by training a reward model on human rankings of sampled model outputs, followed by reinforcement learning (PPO) that optimizes the policy against that reward model
  3. Train a reward model on raw internet text first, then use it to filter the pretraining corpus before any supervised fine-tuning occurs
  4. Fine-tune the model using only reinforcement learning against a fixed rule-based reward function, without using any human-labeled data at any stage
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 008/012 easy

Each sublayer in the Transformer encoder and decoder (Vaswani et al., 2017) is wrapped with a residual connection before layer normalization is applied. What role do these residual connections play in training deep stacks of transformer blocks?

  1. They reduce the total number of attention heads needed by allowing heads to share weights across different layers
  2. They eliminate the need for a softmax normalization step within the self-attention mechanism
  3. They replace the position-wise feed-forward sublayer with a simple identity function during inference, to speed up generation
  4. They add each sublayer's input directly to its output before normalization, giving gradients a direct path backward through the addition and easing optimization of many stacked layers
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 009/012 easy

Ba, Kiros and Hinton (2016), "Layer Normalization," introduced a normalization technique widely used in transformer blocks. How does layer normalization compute its statistics, and how does this differ from batch normalization?

  1. It normalizes each feature by computing statistics across every example in the mini-batch, exactly as batch normalization does, but applies the result at a different point in the network
  2. It normalizes activations using running statistics collected only during a separate calibration pass performed after training has finished
  3. It computes the mean and variance across the feature dimension for each individual training example, making it independent of batch size, whereas batch normalization computes statistics across the batch for each feature
  4. It normalizes only the query and key projections used in self-attention, leaving the value projection and feed-forward outputs unnormalized
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 010/012 easy

In addition to the self-attention sublayer, each Transformer block (Vaswani et al., 2017) contains a position-wise feed-forward network. How is this feed-forward network applied across the sequence?

  1. It is applied identically and independently to each position in the sequence, typically expanding to a larger inner dimension through a nonlinearity before projecting back down
  2. It combines information across all positions simultaneously in the same way self-attention does, making it functionally redundant with the attention sublayer
  3. It only operates on the final position of the sequence, producing a single pooled representation for the entire input
  4. It shares its weights with the token embedding layer so that no additional parameters are introduced by including it
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 011/012 hard

Shazeer et al. (2017), "Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer," introduced a technique now used in some large language models to scale model capacity without a proportional increase in per-token compute. How does a sparsely-gated mixture-of-experts (MoE) layer achieve this?

  1. A gating network activates every expert sub-network for every input and averages their outputs, providing an ensembling effect at the cost of proportionally higher compute
  2. A trainable gating network routes each input to a sparse subset of expert feed-forward sub-networks, letting total parameter count scale far beyond what would be affordable if every expert were computed for every input
  3. Each expert is a full independent copy of the entire transformer stack, and the gating network selects which single copy runs the whole forward pass for a given input
  4. The gating network is fixed at random initialization and never trained, relying purely on random routing to balance load across experts
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 012/012 easy

Extending a transformer-based language model's context window to accept much longer input sequences is architecturally expensive without further modifications to the standard attention mechanism. What property of self-attention, as defined by Vaswani et al. (2017), causes this?

  1. Compute and memory for self-attention scale linearly with sequence length, so extending the context window costs proportionally the same amount regardless of length
  2. The context window is limited only by the size of the token vocabulary, not by any property of the attention computation itself
  3. Self-attention's cost depends solely on the number of stacked layers in the model and is unaffected by how many tokens are in the input sequence
  4. Self-attention computes a pairwise compatibility score between every two positions in the sequence, so both compute and memory scale quadratically with sequence length, making much longer context windows substantially more expensive