Question 41 · Transformer Architecture: Positional Encoding · hard
In sinusoidal positional encoding, PE(t, i) = sin(t / 10000^{2i/d}) is used for even i. For i = 128 and d_model = 512, what is the wavelength term 10000^{2i/d}?
Wavelength = 10000^{2×128/512} = 10000^{0.5} ≈ 100. Different positions have different patterns depending on wavelength, encoding both absolute and relative position information.
Wavelength = 10000^128 which is astronomically large, making the PE function approach zero for practical values.
Wavelength = 128 directly from the dimension index, independent of 10000 or d.
Wavelength = 2i / d_model = 256/512 = 0.5, meaning PE changes by factor of e^0.5 per step.
Answer: A. Wavelength = 10000^{2×128/512} = 10000^{0.5} ≈ 100. Different positions have different patterns depending on wavelength, encoding both absolute and relative position information.
ExplanationThe exponent is 2i/d = 2×128/512 = 256/512 = 0.5, so the wavelength term is 10000^0.5 = 100 (the square root of 10000). Since i ranges from 0 to d/2, this exponent scales from 0 (wavelength 1) to 1 (wavelength 10000) as i increases, giving the sinusoidal encoding a geometric progression of wavelengths across dimensions — small wavelengths at low-index dimensions capture fine-grained differences between nearby positions, while large wavelengths at high-index dimensions capture coarse-grained differences between distant positions, letting the model represent both absolute and relative position information.
Question 42 · Transformer Architecture: Group Query Attention · hard
Given the transformer architecture with d_model=512, n_heads=8, d_k=64, seq_len=2048, requiring O(N^2*d) = O(268M) attention computations per layer — Group Query Attention (GQA) reduces the number of key/value heads from 8 to 2 while keeping query heads at 8. Calculate the KV-cache size reduction for seq_len=2048, batch=16, d_k=64 across 80 layers?
KV-cache size is identical in both because K and V must represent all tokens regardless of head count.
GQA does not reduce KV-cache size because the 2 shared KV heads must be broadcast to match all 8 query heads before storage, so the cache still holds 8 head-equivalents of data.
KV-cache reduction is negligible (less than 10%) because K and V are tiny compared to activations.
Answer: A. Standard: 2×2048×16×8×64×4bytes per layer = 128MB × 80 = 10GB. GQA: 2×2048×16×2×64×4bytes = 32MB × 80 = 2.5GB. Reduction = 10GB / 2.5GB = 4x, matching the head reduction factor 8/2=4.
ExplanationKV-cache size is determined by the number of key/value heads, not query heads, since only K and V are cached during autoregressive decoding: cache_size = 2 (for K and V) × seq_len × batch × num_kv_heads × d_k × bytes_per_value, summed across layers. With standard multi-head attention, num_kv_heads equals n_heads = 8, giving 2×2048×16×8×64×4 = 134,217,728 bytes = 128MB per layer, and 128MB × 80 layers = 10GB total. GQA groups the 8 query heads to share just 2 KV heads, so num_kv_heads drops to 2: 2×2048×16×2×64×4 = 33,554,432 bytes = 32MB per layer, and 32MB × 80 layers = 2.5GB total. The reduction is 10GB / 2.5GB = 4x, exactly matching the KV-head reduction factor of 8/2 = 4. This 4x smaller cache directly speeds up autoregressive decoding, since the entire KV-cache must be streamed from HBM at every generation step.
Question 43 · Inference Optimization: Memory Bottleneck · hard
During autoregressive inference, a 13B-parameter model quantized to INT8 (1 byte per parameter) requires loading 13 GB of weights from HBM for every generated token, on a GPU with 2000 GB/s memory bandwidth and 500 TFLOP/s peak INT8 compute throughput. Generating one token performs 26 GFLOPs of computation. Calculate the per-token latency and determine whether decoding is memory-bound or compute-bound?
Arithmetic intensity = 26 GFLOPs / 13 GB = 2 FLOP/byte, far below the GPU's balance (ridge) point of 500 TFLOP/s ÷ 2000 GB/s = 250 FLOP/byte, so achieved throughput is capped at bandwidth × intensity = 2000 GB/s × 2 FLOP/byte = 4000 GFLOP/s — just 0.8% of peak compute. Per-token latency = 26 GFLOPs / 4000 GFLOP/s = 6.5 ms (about 154 tokens/sec), so decoding is memory-bound: the GPU sits roughly 99% compute-idle while it waits on the weight load.
Comparing the two workload totals directly — 26 GFLOPs of compute against 13 GB of memory traffic — shows compute is the larger quantity, so decoding must be compute-bound; latency is then 26 GFLOPs / 500 TFLOP/s = 52 microseconds, or about 19,231 tokens per second.
Because the compute engines and HBM controller execute as sequential stages for each token, per-token latency is the sum of compute time (26 GFLOPs / 500 TFLOP/s = 52 microseconds) and memory time (13 GB / 2000 GB/s = 6.5 milliseconds), giving approximately 6.55 milliseconds, or about 153 tokens per second.
Since the measured arithmetic intensity of 2 FLOP/byte falls between the compute and memory extremes, the workload is treated as balanced, and throughput is estimated as the geometric mean of the compute time (52 microseconds) and memory time (6.5 milliseconds), roughly 0.58 milliseconds per token, or about 1,720 tokens per second.
Answer: A. Arithmetic intensity = 26 GFLOPs / 13 GB = 2 FLOP/byte, far below the GPU's balance (ridge) point of 500 TFLOP/s ÷ 2000 GB/s = 250 FLOP/byte, so achieved throughput is capped at bandwidth × intensity = 2000 GB/s × 2 FLOP/byte = 4000 GFLOP/s — just 0.8% of peak compute. Per-token latency = 26 GFLOPs / 4000 GFLOP/s = 6.5 ms (about 154 tokens/sec), so decoding is memory-bound: the GPU sits roughly 99% compute-idle while it waits on the weight load.
ExplanationThe roofline model gives achieved throughput as min(peak_compute, bandwidth × arithmetic_intensity). Arithmetic intensity here is 26 GFLOPs ÷ 13 GB = 2 FLOP per byte moved. The GPU's balance point — the intensity at which compute time and memory time are equal — is peak_compute ÷ bandwidth = 500 TFLOP/s ÷ 2000 GB/s = 250 FLOP/byte. Because 2 FLOP/byte is far below the 250 FLOP/byte balance point, the workload sits deep in the memory-bound region of the roofline curve: achieved throughput is capped at bandwidth × intensity = 2000 GB/s × 2 = 4000 GFLOP/s, only 0.8% of the 500,000 GFLOP/s peak. Per-token latency is therefore 26 GFLOPs ÷ 4000 GFLOP/s = 6.5 milliseconds (about 154 tokens/sec) — identical to simply computing weight-load time (13 GB ÷ 2000 GB/s = 6.5 ms), since the compute itself finishes in a mere 52 microseconds and is fully hidden behind the memory transfer, not added to it. The practical fix for this bottleneck is the same as for any memory-bound decode step: shrink the bytes moved per token (more aggressive quantization, smaller KV cache) or amortize the weight load across more tokens per pass (speculative decoding, larger batch sizes).
Question 44 · RLHF & Alignment: KL Penalty · hard
In RLHF fine-tuning, the policy optimization objective subtracts a KL penalty term β·KL(π_θ‖π_ref) to keep the trained policy π_θ close to the frozen reference (SFT) policy π_ref. Suppose for one generated token the trained policy assigns probability π_θ(token) = 0.6, the reference policy assigns π_ref(token) = 0.3, and the KL coefficient is β = 0.1. Using the forward-KL term p·ln(p/q) for this token, what is its contribution to β·KL(π_θ‖π_ref)?
Approximately 0.0416, found by computing 0.6 × ln(0.6/0.3) ≈ 0.4159 nats and then scaling by the KL coefficient β = 0.1.
Around −0.0208, found by computing 0.3 × ln(0.3/0.6) and scaling by β = 0.1, treating the reference policy's probability as the term that should be weighted.
Close to 0.4159, since β rescales only the total training loss and should not be applied when computing an individual token's divergence contribution.
Near 0.06, found by using log base 2 instead of the natural logarithm, since information-theoretic probabilities are conventionally measured in bits.
Answer: A. Approximately 0.0416, found by computing 0.6 × ln(0.6/0.3) ≈ 0.4159 nats and then scaling by the KL coefficient β = 0.1.
ExplanationThe per-token contribution to β·KL(π_θ‖π_ref) is β · p · ln(p/q), where p = π_θ(token) is the probability under the policy being trained and q = π_ref(token) is the probability under the fixed reference policy — the current policy's probability must weight the log-ratio, since KL(π_θ‖π_ref) is defined as an expectation taken over π_θ, not π_ref. Here p = 0.6 and q = 0.3, so ln(p/q) = ln(2) ≈ 0.6931, giving p·ln(p/q) = 0.6 × 0.6931 ≈ 0.4159 nats. Multiplying by the KL coefficient β = 0.1 scales this raw divergence term down to its actual weight inside the training objective: 0.1 × 0.4159 ≈ 0.0416. Weighting the log-ratio by q instead of p computes the reverse-KL term instead, which has the wrong sign and magnitude here; reporting 0.4159 skips the β scaling entirely, giving the unweighted divergence rather than its contribution to the penalty; and using log base 2 conflates the natural-log (nats) convention required for KL divergence with the bits convention used in entropy coding, which is why that path lands on 0.06 instead of 0.0416.
Question 45 · Inference Optimization: Quantization Error · hard
A neural network layer stores its weights, uniformly distributed over [-1, 1], as INT8 values with 256 quantization levels, giving a step size Δ = 2/256 = 0.0078125. Modeling the rounding error as uniform over [-Δ/2, Δ/2], the mean squared quantization error is Δ²/12. For a typical weight magnitude of 0.5, what is the resulting relative RMS quantization error, to two significant figures?
The relative RMS quantization error works out to about 0.45%, since RMS error equals the square root of Δ²/12 divided by the typical weight magnitude of 0.5.
Skipping the divide by 12 and using the raw step size Δ as the RMS error gives a relative error of about 1.6%, which overstates the true noise level.
Treating half the step size, Δ/2, as if it were the RMS error yields a relative error of about 0.78%, roughly double the correct value.
Mistaking INT8 for a 4-bit, 16-level scheme when computing the step size inflates the relative error to roughly 7.2%, about sixteen times too large.
Answer: A. The relative RMS quantization error works out to about 0.45%, since RMS error equals the square root of Δ²/12 divided by the typical weight magnitude of 0.5.
ExplanationWith 256 levels spanning [-1, 1], the quantization step is Δ = 2/256 = 0.0078125. Modeling the rounding error as uniform over [-Δ/2, Δ/2] gives a mean squared error of Δ²/12 ≈ 5.09×10⁻⁶, so the RMS error is √(Δ²/12) ≈ 0.00226. Dividing by the typical weight magnitude of 0.5 gives a relative RMS error of about 0.45%. Using the step size itself as the error, which skips the divide-by-12 that converts a uniform distribution's range into its RMS, overstates the noise by a factor of √12 ≈ 3.46, landing near 1.6%. Using half the step size as if it were the RMS, rather than computing the RMS of a uniform distribution over that half-range, doubles the true figure to about 0.78%. Assuming a 4-bit, 16-level scheme instead of 8-bit, 256-level quantization inflates the step size by 16×, which inflates the relative error by the same factor, to roughly 7.2%.
Question 46 · Flash Attention tiling · hard
Flash Attention processes a sequence of length N = 8192 using block size B = 256 for both the query row-blocks and the key/value column-blocks. For each of the Tr = N/B query row-blocks, the algorithm initializes a running output accumulator O_i, running max m_i, and running sum l_i, then loops over each of the Tc = N/B key/value column-blocks — computing block scores and updating m_i, l_i, and O_i using online-softmax rescaling entirely within on-chip SRAM. Only after all Tc inner iterations for a given row-block finish does it normalize O_i and write it back to HBM. Given these parameters, how many total block-pair score computations does the full double loop perform, and how many separate HBM writes of output blocks does the algorithm make in total?
This double loop performs 1024 total block-pair computations (32 row-blocks × 32 column-blocks), but only 32 HBM writes of output blocks occur in total, because each row-block's output accumulator is kept in SRAM across its entire inner loop and flushed to HBM just once after that loop finishes.
Every one of the 1024 block-pair computations (32 row-blocks × 32 column-blocks) also triggers its own HBM write, giving 1024 total writes, since the running softmax statistics must be persisted to HBM after each inner-loop update to avoid being lost.
Only 32 block-pair computations occur in total, one per row-block, and 32 HBM writes happen as well, because Flash Attention restricts computation to the diagonal block pairs where the row-block index equals the column-block index.
The double loop still performs 1024 block-pair computations, yet the algorithm needs just a single HBM write overall, since the complete N×N output matrix is assembled and held in on-chip SRAM before being flushed to HBM all at once.
Answer: A. This double loop performs 1024 total block-pair computations (32 row-blocks × 32 column-blocks), but only 32 HBM writes of output blocks occur in total, because each row-block's output accumulator is kept in SRAM across its entire inner loop and flushed to HBM just once after that loop finishes.
ExplanationThe outer loop runs over Tr = N/B = 8192/256 = 32 row-blocks, and for each row-block the inner loop runs over Tc = N/B = 32 column-blocks, so the double loop performs Tr × Tc = 32 × 32 = 1024 block-pair score computations in total. The key IO-saving trick, though, is that the running accumulator O_i, along with the running softmax statistics m_i and l_i, live entirely in on-chip SRAM for the full duration of the inner loop over j = 1...Tc — every rescaling and update to O_i during those 32 inner steps costs no HBM traffic at all. Only once the inner loop finishes for a given row-block i does the algorithm normalize O_i and write it back to HBM, so there are exactly Tr = 32 HBM writes of output blocks, not 1024. Persisting statistics after every inner update (as one wrong option claims) would erase the entire IO advantage, restricting computation to diagonal blocks only (as another claims) describes local attention, not Flash Attention, and assuming the full N×N output fits in SRAM at once (as another claims) ignores why block size B is needed in the first place — SRAM cannot hold the whole matrix. This gap between 1024 compute steps and 32 HBM writes is precisely why IO complexity drops from O(N^2·d) in standard attention to O(N^2·d/B): B determines how many block-pair computations are amortized against a single HBM write.
Question 47 · LoRA decomposition · hard
A transformer layer's attention weight matrices Q, K, V, and O are each 4096×4096 (16,777,216 parameters each, so 67,108,864 total across the four). LoRA fine-tuning replaces each frozen matrix W with W + BA, using B (4096×16) and A (16×4096) per matrix, giving rank r=16. Given this setup, which statement correctly describes the trainable parameter count and the effect of merging BA back into W at inference time?
Across all four attention projections, LoRA trains 524,288 parameters total — about 0.78% of the 67,108,864 full-rank parameters — and merging W_merged = W + BA preserves the original 4096×4096 shape, adding no inference-time latency.
Because the LoRA rank is r=16, only 16 parameters are trained per projection matrix, so the four attention projections together update just 64 parameters.
Merging produces W_merged with shape 4096×16 rather than 4096×4096, so each attention projection must be re-architected before the model can run inference.
The 524,288 trainable parameters make up roughly 7.8% of the 67,108,864 original parameters, meaning LoRA still fine-tunes a fairly large slice of the attention weights.
Answer: A. Across all four attention projections, LoRA trains 524,288 parameters total — about 0.78% of the 67,108,864 full-rank parameters — and merging W_merged = W + BA preserves the original 4096×4096 shape, adding no inference-time latency.
ExplanationEach LoRA matrix pair contributes 4096×16 + 16×4096 = 65,536 + 65,536 = 131,072 trainable parameters per projection. Across the four attention projections (Q, K, V, O) that totals 4 × 131,072 = 524,288 trainable parameters, versus 4 × (4096×4096) = 67,108,864 parameters in the original full-rank matrices — a ratio of 524,288 / 67,108,864 ≈ 0.78%. At inference, B and A are multiplied and added directly into W: the product BA has shape (4096×16)·(16×4096) = 4096×4096, exactly matching W, so W_merged = W + BA can replace W in place with no shape change and no added inference latency. The claim that only 16 parameters are trained per matrix confuses the rank r — the shared inner dimension of B and A — with the actual parameter count, which depends on both the rank and the full 4096 dimension, not the rank alone. The claim that the merged matrix has shape 4096×16 misreads the matrix product BA, which takes on the shape of W (4096×4096), not the shape of a single factor like B. The claim that LoRA trains roughly 7.8% of the original parameters is off by a factor of ten from the correct 0.78% figure.
Question 48 · Mixture of Experts routing · hard
In a Mixture-of-Experts (MoE) layer with 4 experts and top-k=2 routing, a token produces gating logits z = [1.2, 0.3, 2.1, -0.5] for Experts 1 through 4 respectively. The router applies softmax to these logits, selects the two experts with the highest softmax probability, and renormalizes their probabilities to sum to 1 before combining their outputs — what are the two experts selected and their renormalized combination weights (rounded to two decimal places)?
Expert 3 and Expert 1 are the two activated experts, combining outputs with renormalized weights of approximately 0.71 and 0.29 respectively.
The softmax weights before renormalization, roughly 0.61 and 0.25 for Expert 3 and Expert 1, are used directly as the final combination weights.
Normalizing the raw gating logits of the top two experts directly, without exponentiating them through softmax, yields combination weights of about 0.64 and 0.36.
Since top-k routing only reweights outputs rather than restricting computation, all four experts contribute equally with a weight of 0.25 each.
Answer: A. Expert 3 and Expert 1 are the two activated experts, combining outputs with renormalized weights of approximately 0.71 and 0.29 respectively.
ExplanationApplying softmax to z = [1.2, 0.3, 2.1, -0.5] gives probabilities of approximately 0.247, 0.100, 0.607, and 0.045 for Experts 1 through 4 (the exponentials are about 3.32, 1.35, 8.17, and 0.61, summing to roughly 13.44). The two largest probabilities belong to Expert 3 (0.607) and Expert 1 (0.247), so these are the experts the token gets routed to. Because the combination weights of a top-k MoE layer must sum to 1, the selected probabilities are renormalized by dividing each by their sum (0.607 + 0.247 = 0.854): Expert 3 gets 0.607/0.854 ≈ 0.71 and Expert 1 gets 0.247/0.854 ≈ 0.29. Skipping this renormalization step and using the raw softmax outputs directly would leave weights of about 0.61 and 0.25, which do not sum to 1 and therefore cannot correctly scale the combined output — that is the flaw in using pre-renormalization values as the final weights. Normalizing the raw logits (2.1 and 1.2) instead of their softmax values confuses linear scaling with the exponential weighting softmax actually performs, producing the incorrect pair of about 0.64 and 0.36. Treating all four experts as equally weighted ignores the entire point of top-k routing, which is to activate only a sparse subset of experts per token — with top-k=2 out of 4 experts, only half the expert parameters are active for this token, not all of them at equal weight.
Question 49 · nucleus sampling · hard
In top-p (nucleus) sampling with p = 0.85, a language model's next-token probabilities, sorted in descending order, are [0.42, 0.28, 0.15, 0.08, 0.04, 0.02, 0.01]. Their cumulative sums are [0.42, 0.70, 0.85, 0.93, 0.97, 0.99, 1.00]. Which statement correctly describes the resulting nucleus and the renormalized sampling probability of the most likely token?
The nucleus consists of exactly the top 3 tokens (probabilities 0.42, 0.28, 0.15) because their cumulative sum first reaches p at 0.85, and dividing each kept probability by 0.85 raises the top token's sampling probability to about 0.494
Because the third token's cumulative sum lands exactly on p rather than exceeding it, standard nucleus sampling excludes that token, leaving only a 2-token nucleus with cumulative probability 0.70
Top-p sampling with p = 0.85 always outputs the single highest-probability token deterministically, functioning identically to greedy decoding regardless of how the remaining probabilities are distributed
Renormalization is unnecessary here because the three retained tokens' original probabilities of 0.42, 0.28, and 0.15 already sum to 1.0 before any lower-probability tokens are discarded
Answer: A. The nucleus consists of exactly the top 3 tokens (probabilities 0.42, 0.28, 0.15) because their cumulative sum first reaches p at 0.85, and dividing each kept probability by 0.85 raises the top token's sampling probability to about 0.494
ExplanationNucleus sampling keeps the smallest prefix of sorted tokens whose cumulative probability is at least p, then samples from that truncated, renormalized distribution — it never picks the argmax deterministically. Walking the cumulative sums [0.42, 0.70, 0.85, 0.93, ...], the running total first meets p = 0.85 at the third token, so the nucleus is {0.42, 0.28, 0.15}, three tokens whose probabilities sum to 0.85. Dividing each by that sum renormalizes them to roughly [0.494, 0.329, 0.176], so the top token's sampling probability rises from 0.42 to about 0.494 rather than staying fixed. The claim that reaching p exactly should exclude the crossing token misapplies the threshold rule: the standard "cumulative >= p" condition includes the token that first satisfies it, so trimming to a 2-token, 0.70 nucleus is wrong. The claim of deterministic single-token output confuses nucleus sampling with greedy decoding; nucleus sampling still draws stochastically from several candidates whenever more than one survives truncation. And the retained probabilities 0.42 + 0.28 + 0.15 sum to 0.85, not 1.0 — the full vocabulary's probabilities sum to 1.0 before truncation, but once the tail is discarded, renormalization is required so the kept tokens form a valid probability distribution again.
Question 50 · Flash Attention tiling · hard
A Flash Attention kernel processes one query row against 4 key/value pairs split into two tiles of size 2, using the online-softmax algorithm (never materializing the full 4-element score row). Tile 1 has raw scores [2, 4] with values [10, 20]; tile 2 has raw scores [1, 5] with values [1, 2]. After processing tile 1, the running max is m=4, the running denominator is l≈1.1353, and the running numerator is ≈21.3534. When tile 2 arrives its local max is 5, so the global running max updates to 5 before tile 2's contribution is folded in. What is the correctly rounded final output after both tiles are processed, and what operation on the tile-1 accumulators makes this result exactly equal to standard (non-tiled) softmax attention over all 4 scores?
The final output is approximately 6.88, produced by rescaling the tile-1 numerator and denominator by exp(4 − 5) = exp(−1) before adding tile 2's contributions, which is the online-softmax correction that keeps the running sum algebraically identical to summing over all 4 scores at once regardless of how the tiles are sized.
Summing the value-weighted exponentials from both tiles without ever dividing by the combined denominator yields approximately 9.87 as the final output, since the running numerator already reflects every key's contribution once the second tile has been folded in.
Rescaling the tile-1 accumulators by exp(5 − 4) = exp(1) instead of exp(4 − 5) before merging in tile 2 is the correct direction for the online-softmax update, giving a final output of approximately 14.63.
Because tile 1 and tile 2 both contain exactly 2 keys, this 6.88 result only holds when tile sizes divide the sequence length evenly; if the final tile had an odd number of keys, the exp(old_max − new_max) rescaling would no longer reproduce the exact global softmax output.
Answer: A. The final output is approximately 6.88, produced by rescaling the tile-1 numerator and denominator by exp(4 − 5) = exp(−1) before adding tile 2's contributions, which is the online-softmax correction that keeps the running sum algebraically identical to summing over all 4 scores at once regardless of how the tiles are sized.
ExplanationFlash Attention's online-softmax recurrence keeps a running max m, running denominator l, and running unnormalized numerator, updating them one tile at a time so the full score row is never stored. After tile 1 ([2,4], values [10,20]): m=4, l = e^(2-4)+e^(4-4) = 0.1353+1 = 1.1353, numerator = 10(0.1353)+20(1) = 21.3534. Tile 2 ([1,5], values [1,2]) has local max 5, so the running max updates to 5. Before adding tile 2, the tile-1 accumulators must be rescaled by exp(m_old − m_new) = exp(4−5) = exp(−1) ≈ 0.3679, giving a rescaled numerator ≈ 7.8555 and rescaled denominator ≈ 0.4177. Tile 2's own contribution relative to m=5 is numerator = 1·e^(1-5) + 2·e^(5-5) = 0.0183+2 = 2.0183, denominator = 0.0183+1 = 1.0183. Totals: numerator ≈ 9.8738, denominator ≈ 1.4360, so output = 9.8738/1.4360 ≈ 6.876, rounding to 6.88 — the same value a direct one-shot softmax over all four scores [2,4,1,5] produces. Stopping at the raw weighted-value sum of 9.87 skips the mandatory division by the running denominator, so that path reports an unnormalized numerator rather than an attention output. Flipping the rescale exponent to exp(new_max − old_max) = exp(1) instead of exp(old_max − new_max) inflates the stale tile-1 term rather than discounting it, landing near 14.63 — a genuine bug pattern seen in naive implementations. Finally, the exact equivalence to global softmax does not depend on tile sizes dividing the sequence length evenly: the same max-rescaling algebra holds for a ragged final tile of any size, so tying correctness to even divisibility misstates the algorithm's actual guarantee.
Question 51 · Mixture of Experts routing · hard
A Mixture-of-Experts (MoE) layer has 8 experts, each a feed-forward network (FFN) with 200 million parameters, and uses top-k=2 learned softmax routing. For a specific token, the router selects the two experts with the highest gate scores and renormalizes just those two scores so they sum to 1. Suppose the higher-scoring expert (expert 5) ends up with a renormalized gate weight of 0.65. What is the total number of active FFN parameters used to process this single token, and what renormalized gate weight does the other selected expert receive?
Processing this token activates 400 million FFN parameters in total, and the second selected expert receives a renormalized weight of 0.35.
All eight experts fire for this token, activating 1.6 billion FFN parameters in total, while the second expert still receives a weight of 0.35.
Only 400 million FFN parameters activate, but the second selected expert also receives a renormalized weight of 0.65, matching expert 5.
Because top-k=2 only re-ranks scores without changing computation, just 200 million FFN parameters activate, leaving the second expert at a weight of 0.35.
Answer: A. Processing this token activates 400 million FFN parameters in total, and the second selected expert receives a renormalized weight of 0.35.
ExplanationTop-k=2 routing means exactly two of the eight experts run a full forward pass for each token, not all eight and not just one — so active parameters equal 2 x 200 million = 400 million, while the other six experts (and their 1.2 billion parameters) are skipped entirely for this token. This is the core efficiency property of MoE: total model capacity (8 x 200M = 1.6 billion parameters) is far larger than the compute actually spent per token. Separately, after the router picks the top-2 experts by raw softmax score, those two scores are renormalized (divided by their own sum) so the token's output is a proper convex combination of only the chosen experts' outputs — the two renormalized weights must add to exactly 1. Since expert 5's renormalized weight is given as 0.65, the other selected expert must take the remainder, 1 - 0.65 = 0.35; it cannot also be 0.65, since that would sum to 1.30 and violate the renormalization constraint.
Question 52 · pipeline parallelism · hard
A model is split across a pipeline of P = 8 GPUs, and a mini-batch of 128 training examples is divided into M = 32 micro-batches of 4 examples each. Under GPipe's schedule, every micro-batch completes its forward pass before any backward pass begins, so a GPU must retain activations for all micro-batches still awaiting backward computation. Under the 1F1B (one-forward-one-backward) schedule, each GPU interleaves forward and backward passes so that no more than one micro-batch's activations per pipeline stage need be held in flight at once, capping the count at P. Using the standard pipeline-bubble formula, bubble fraction = (P − 1)/M, expressed as idle time relative to the ideal bubble-free execution time, what are the resulting bubble fraction and the factor by which 1F1B reduces peak per-GPU activation memory compared to GPipe?
With P=8 stages and M=32 micro-batches, the bubble fraction is 21.875% (7/32), and 1F1B cuts peak per-GPU activation storage from O(M)=32 down to O(P)=8 — a 4x reduction — because GPipe keeps every micro-batch's activations queued until all forward passes finish, while 1F1B frees each micro-batch's activations once its own backward pass runs, capping the in-flight count at P.
The bubble fraction equals P/M, giving 25% idle time, and 1F1B reduces peak activation storage to exactly P−1=7 sets because the final pipeline stage completes its backward pass without ever needing to buffer intermediate activations.
Inverting the ratio to (M−1)/P yields a bubble fraction of 387.5%, and 1F1B eliminates activation memory entirely because each micro-batch's backward pass is scheduled immediately after its own forward pass with no others left pending.
Although the bubble fraction works out to 21.875% (7/32), 1F1B lowers peak activation storage by that same factor of 4 only because it trains on 8 of the 32 micro-batches per optimizer step and discards the rest to save memory.
Answer: A. With P=8 stages and M=32 micro-batches, the bubble fraction is 21.875% (7/32), and 1F1B cuts peak per-GPU activation storage from O(M)=32 down to O(P)=8 — a 4x reduction — because GPipe keeps every micro-batch's activations queued until all forward passes finish, while 1F1B frees each micro-batch's activations once its own backward pass runs, capping the in-flight count at P.
ExplanationWith P=8 stages and M=32 micro-batches, the bubble fraction is (P−1)/M = 7/32 = 0.21875 = 21.875%. GPipe's all-forward-then-all-backward schedule forces a GPU to hold activations for every micro-batch that has completed its forward pass but not yet its backward pass — in the worst case all 32 of them — giving peak memory of order O(M). 1F1B interleaves forward and backward passes so that each pipeline stage never has more than P=8 micro-batches' activations in flight simultaneously, giving O(P) peak memory. The reduction factor is therefore M/P = 32/8 = 4. One incorrect approach drops the (P−1) term and computes P/M = 25%, then wrongly claims memory falls to exactly P−1=7 sets by reasoning that the last stage "never buffers" anything — but every stage, including the last, still holds up to P in-flight activation sets under 1F1B, and dropping the −1 term also produces the wrong bubble value. Another approach inverts the ratio to (M−1)/P = 31/8 = 387.5%, an impossible idle-time value since a fraction of time cannot exceed 100%, paired with the false claim that 1F1B needs zero activation memory — in reality 1F1B still buffers each stage's own P in-flight micro-batches, it just avoids GPipe's much larger backlog. A third approach lands on the correct bubble (21.875%) and the correct factor of 4, but for the wrong reason: 1F1B does not skip 24 of the 32 micro-batches — it still processes all 32, just staggered so that no more than P are in flight at once, which is what actually bounds memory at O(P) rather than O(M).
Question 53 · nucleus sampling · hard
A language model's vocabulary has been sorted by probability in descending order, giving pre-truncation token probabilities [0.32, 0.28, 0.18, 0.12, 0.06, 0.04]. Nucleus (top-p) sampling with p = 0.75 is implemented as follows:
```python
sorted_probs = [0.32, 0.28, 0.18, 0.12, 0.06, 0.04]
cumulative = []
running_sum = 0
for prob in sorted_probs:
running_sum += prob
cumulative.append(running_sum)
# cumulative = [0.32, 0.60, 0.78, 0.90, 0.96, 1.00]
nucleus = []
for i, c in enumerate(cumulative):
nucleus.append(sorted_probs[i])
if c >= p:
break
```
Running this with p = 0.75 stops the loop as soon as the cumulative sum first reaches or exceeds 0.75, which happens at the third token (cumulative 0.78), so the nucleus is {0.32, 0.28, 0.18}. These three probabilities are then renormalized by dividing each by their own sum, 0.78, so the retained distribution again sums to 1. What is the renormalized probability of the token whose original probability was 0.18?
The renormalized probability is about 0.231, because dividing 0.18 by the nucleus's total probability mass of 0.78 rescales the three retained probabilities so they sum exactly to 1.
No renormalization is needed here, so the probability remains 0.180, since a token already inside the nucleus keeps its original probability and only excluded tokens get redistributed.
Dividing by the six-token cumulative value of 0.90 instead of the nucleus total gives approximately 0.200, since the denominator should reflect the first cumulative sum that exceeds p.
Normalizing 0.18 only against the two higher-ranked tokens' combined 0.60 yields approximately 0.300, treating those two probabilities as the appropriate reference set.
Answer: A. The renormalized probability is about 0.231, because dividing 0.18 by the nucleus's total probability mass of 0.78 rescales the three retained probabilities so they sum exactly to 1.
ExplanationWorking through the loop by hand: the cumulative sums are 0.32, 0.60, 0.78, 0.90, 0.96, 1.00, and the break condition c >= 0.75 first triggers at the third entry (0.78), so the nucleus consists of exactly the three highest-probability tokens {0.32, 0.28, 0.18}, whose combined mass is 0.78 — not the six-token total of 1.00. Renormalizing means every probability that survived truncation is divided by that nucleus total of 0.78 so the retained distribution sums to 1 again; nucleus membership does not exempt a token from this step, so 0.18 must still be rescaled rather than left unchanged. Carrying out the division: 0.18 / 0.78 ≈ 0.231. Using 0.90 as the denominator instead — the cumulative sum one step past the actual cutoff — would incorrectly give 0.200, mistaking where the loop's break condition fires. Normalizing 0.18 against only the two higher-ranked tokens' combined 0.60, as if a token's renormalization reference set excluded itself, would incorrectly give 0.300. The correctly computed renormalized probability is approximately 0.231.
Question 54 · Flash Attention tiling · hard
In a Flash Attention forward pass, a query block Q_i is compared against two key/value blocks processed in sequence. After processing the first key/value block (K_1, V_1), the running row-max is m_1 = 4 and the algorithm has accumulated an unnormalized output vector O_1 and running sum l_1, both computed using exp(score − m_1) terms. The second key/value block (K_2, V_2) is then processed, and its local row-max turns out to be m_2 = 7, which becomes the new running max. Before block 2's contribution can be added to the running totals, what correction must be applied to the block-1 accumulators (O_1 and l_1), and why is it needed?
Rescale the block-1 accumulators — both the running output and running sum — by multiplying them by exp(m1 - m2) = exp(4-7) = e^-3 ≈ 0.0498, because those totals were built from exp(score - m1) terms and must be re-expressed relative to the new running max m2 so every term shares one common reference point
Inflate the block-1 accumulators by multiplying them by exp(m2 - m1) = exp(7-4) = e^3 ≈ 20.09, on the reasoning that raising the running max should proportionally increase every earlier term rather than shrink it
Skip rescaling entirely, since Flash Attention sums the raw values exp(score − 0) for every block without ever subtracting a running max, so blocks combine correctly no matter which one holds the larger scores
Apply the exp(m1 − m2) correction to block 2's freshly computed contribution instead of block 1's accumulator, leaving the earlier running output and sum completely untouched
Answer: A. Rescale the block-1 accumulators — both the running output and running sum — by multiplying them by exp(m1 - m2) = exp(4-7) = e^-3 ≈ 0.0498, because those totals were built from exp(score - m1) terms and must be re-expressed relative to the new running max m2 so every term shares one common reference point
ExplanationFlash Attention never materializes the full N×N score matrix; instead it processes key/value blocks one at a time and keeps a running (unnormalized) output accumulator O, running sum l, and running max m in fast SRAM. Because every accumulated exponential term is only meaningful relative to the max value it was computed against, whenever a later block introduces a larger row-max, all previously accumulated terms must be re-expressed relative to that new max before anything more is added — otherwise the running sum and output would mix exponentials taken relative to two different reference points and the result would no longer equal a valid softmax. Concretely, since exp(score − m1) = exp(score − m2) · exp(m2 − m1), multiplying the old accumulators by exp(m1 − m2) converts every term from being relative to m1 into being relative to m2. Here m1 = 4 and m2 = 7, so the correction factor is exp(4 − 7) = exp(−3) ≈ 0.0498: both O_1 and l_1 are scaled down by this factor before block 2's exp(score − m2) contributions are added in. This online rescaling — the "running softmax" trick — is exactly what lets Flash Attention produce results mathematically identical to standard attention while touching HBM only O(N) times instead of O(N^2), since it never needs to revisit block 1's raw scores once they have been folded into the accumulators.
Question 55 · Mixture of Experts routing · hard
A Mixture-of-Experts (MoE) layer has 6 experts and uses top-k=2 sparse routing. For a token x, the router produces gating logits z = [2.0, 0.5, -1.0, 3.0, 0.0, 1.0] for experts 0 through 5 respectively. The full 6-way softmax over these logits gives expert 3 the highest probability and expert 0 the second-highest; the router keeps only these two experts and renormalizes their probabilities to sum to 1 before combining outputs as y = w3·E3(x) + w0·E0(x). What are the correctly renormalized gating weights w3 and w0?
Using the unrenormalized full-softmax values directly yields w3 ≈ 0.60 and w0 ≈ 0.22, leaving the two gating weights summing to less than 1.
Top-k routing with k=2 assigns equal weight to every selected expert, so w3 = 0.50 and w0 = 0.50 regardless of their logits.
Renormalizing only the top-2 raw softmax probabilities gives w3 ≈ 0.73 and w0 ≈ 0.27, computed by dividing each expert's exponentiated logit by the sum of the exponentiated logits of just the two selected experts.
Because expert 0 was selected second, it should receive the larger renormalized share, giving w3 ≈ 0.27 and w0 ≈ 0.73.
Answer: C. Renormalizing only the top-2 raw softmax probabilities gives w3 ≈ 0.73 and w0 ≈ 0.27, computed by dividing each expert's exponentiated logit by the sum of the exponentiated logits of just the two selected experts.
ExplanationFor token x, the raw gating logits are z = [2.0, 0.5, -1.0, 3.0, 0.0, 1.0], so the full 6-way softmax gives expert 3 (logit 3.0) the highest probability and expert 0 (logit 2.0) the second-highest, since softmax is monotonic in its inputs. Top-k=2 routing keeps only these two experts and discards the other four; because the original softmax probabilities were normalized against a denominator that included those discarded experts, the two kept weights no longer sum to 1 and must be renormalized against each other. Renormalizing means dividing each selected expert's exponentiated logit by the sum of just the exponentiated logits of the two selected experts: exp(3.0) ≈ 20.086 and exp(2.0) ≈ 7.389, which sum to ≈ 27.475. This gives w3 = 20.086 / 27.475 ≈ 0.73 and w0 = 7.389 / 27.475 ≈ 0.27, values that correctly sum to 1 and preserve the ranking that the expert with the larger logit (expert 3) receives the larger share of the combination. Skipping renormalization leaves the weights at their raw full-softmax values (≈ 0.60 and ≈ 0.22), which understate each expert's true contribution and fail to sum to 1. Treating top-k selection as an equal split discards the router's learned confidence entirely, collapsing MoE's weighted combination into plain averaging. Swapping which expert gets the larger share would invert the router's signal, handing more influence to the expert it was actually less confident about.
Question 56 · nucleus sampling · hard
A language model's next-token probability distribution, already sorted in descending order, is [0.40, 0.20, 0.15, 0.12, 0.08, 0.05]. Nucleus (top-p) sampling is applied with p = 0.75, using the standard rule of retaining the smallest prefix of tokens whose cumulative probability first reaches or exceeds p, then renormalizing only the retained probabilities so they sum to 1. Under this rule, how many tokens are retained in the nucleus, and what is the renormalized probability of the third-ranked token?
Exactly 3 tokens are kept in the nucleus (cumulative probability reaches 0.75 precisely at the third token), and after renormalizing by dividing each retained probability by 0.75, the third token's probability becomes 0.20.
Four tokens are kept in the nucleus because the cumulative probability must strictly exceed 0.75 rather than merely reach it, and the third token's renormalized probability becomes approximately 0.172.
Only two tokens are kept in the nucleus, since a combined probability of 0.60 is the closest cumulative value to 0.75, leaving the third-ranked token discarded with an effective renormalized probability of 0.
Three tokens are kept in the nucleus, but since top-p sampling merely filters which tokens are eligible, the third token retains its original probability of 0.15 without any renormalization.
Answer: A. Exactly 3 tokens are kept in the nucleus (cumulative probability reaches 0.75 precisely at the third token), and after renormalizing by dividing each retained probability by 0.75, the third token's probability becomes 0.20.
ExplanationCumulative sums of the sorted distribution are 0.40, 0.60, 0.75, 0.87, 0.95, 1.00. Because the third partial sum already equals 0.75, the nucleus rule (retain the smallest prefix whose cumulative probability reaches or exceeds p) stops right there and keeps exactly the top 3 tokens, whose combined probability is 0.75. Renormalizing divides each retained probability by this 0.75: 0.40/0.75 ≈ 0.533, 0.20/0.75 ≈ 0.267, and 0.15/0.75 = 0.20 for the third-ranked token. Requiring the cumulative sum to strictly exceed p instead of merely reaching it is a common implementation slip that would incorrectly pull in a fourth token, changing the renormalized value to about 0.172 instead. Picking whichever prefix's cumulative sum lies numerically closest to p, or truncating the distribution without renormalizing the survivors afterward, are both misreadings of the algorithm — nucleus sampling filters by a fixed threshold rule, not by proximity, and always renormalizes the surviving probability mass so it remains a valid distribution.
Question 57 · Flash Attention tiling · hard
A transformer processes a sequence of length N = 4096 with head dimension d = 64. Standard attention materializes the full N×N score matrix in HBM (high-bandwidth memory) before applying softmax and multiplying by V. Flash Attention instead partitions Q and K into blocks of size B = 256 along the sequence dimension, streams each block pair into fast on-chip SRAM, and combines the partial results across blocks using an online (running-max, running-sum) softmax that never writes the full score matrix to HBM. Given N = 4096, d = 64, and B = 256, which statement about how Flash Attention behaves under these parameters is correct?
Splitting Q and K into 4096/256 = 16 blocks each means the algorithm still processes all 16 × 16 = 256 block pairs, so the total floating-point operations remain O(N²d), exactly as in standard attention — the savings come from never storing the N×N score matrix, which drops peak memory from O(N²) to O(N) since only the current tile plus a running max and running sum per row are kept.
Because the inner loop only touches 256 block pairs rather than the full N² grid of scores, Flash Attention performs asymptotically fewer floating-point operations than standard attention, roughly O(N²d/B) instead of O(N²d).
The running-max, running-sum rescaling used to merge softmax results across blocks is an approximation, so Flash Attention's output differs numerically from standard attention by an error that grows with the number of blocks processed.
Limiting each step to a single 256×256 block means Flash Attention never combines information from other blocks, so each query's output only reflects the keys in its own block rather than the full sequence.
Answer: A. Splitting Q and K into 4096/256 = 16 blocks each means the algorithm still processes all 16 × 16 = 256 block pairs, so the total floating-point operations remain O(N²d), exactly as in standard attention — the savings come from never storing the N×N score matrix, which drops peak memory from O(N²) to O(N) since only the current tile plus a running max and running sum per row are kept.
ExplanationWith N = 4096 and B = 256, Q and K each split into N/B = 16 blocks, so the nested loop visits 16 × 16 = 256 block pairs in total — every pair of blocks is still compared, so the dot-product and weighted-sum work performed is the same O(N²d) as standard attention; Flash Attention does not skip any query-key interaction. What changes is memory: instead of allocating the full 4096×4096 score matrix, the kernel keeps only the current B×B tile in SRAM together with a running maximum and running sum of exponentials per query row, updating the output accumulator incrementally as each new block arrives. This running-statistics trick (the "online softmax") is mathematically exact — rescaling previously accumulated sums whenever a new, larger max is found reproduces precisely the same softmax weights as computing over the whole row at once, so no approximation error is introduced regardless of how many blocks are processed. The claim of O(N²d/B) floating-point operations confuses the IO/data-movement formula — which genuinely does shrink with block size because fewer bytes move between HBM and SRAM — with the compute formula, which does not shrink. And because every one of the 256 block pairs is visited exactly once, no query ever loses visibility into keys sitting in other blocks; the full sequence is still attended to.
Question 58 · Mixture of Experts routing · hard
A Mixture-of-Experts layer has 6 experts and uses top-2 routing. For a given token, the router's softmax output over the 6 experts is g(x) = [0.05, 0.10, 0.35, 0.05, 0.30, 0.15] (indices 0 through 5). The routing algorithm selects the 2 experts with the highest gate values, renormalizes only their weights so they sum to 1, and computes the output as a weighted sum of just those two experts' outputs. To three decimal places, what renormalized weight does the router assign to expert 4 in the final output?
0.462, since the router divides expert 4's gate value (0.30) by the sum of only the two selected experts' gate values, 0.35 + 0.30 = 0.65.
0.300, since expert 4's original softmax gate value already represents its final contribution and needs no further renormalization.
0.538, since the router assigns expert 4 the larger of the two renormalized weights because it appears later in the gate vector.
0.375, since the router renormalizes over the three highest gate values (0.35, 0.30, and 0.15) before assigning expert 4 its share.
Answer: A. 0.462, since the router divides expert 4's gate value (0.30) by the sum of only the two selected experts' gate values, 0.35 + 0.30 = 0.65.
ExplanationWorking through the routing computation step by step: the softmax gate vector is g(x) = [0.05, 0.10, 0.35, 0.05, 0.30, 0.15], indexed 0 through 5. Top-2 routing keeps only the two largest gate values, which belong to expert 2 (0.35) and expert 4 (0.30); every other expert is dropped entirely for this token. The router then renormalizes just these two surviving weights so they sum to 1: it divides each by their combined total, 0.35 + 0.30 = 0.65. Expert 4's renormalized weight is therefore 0.30 / 0.65 ≈ 0.462, and expert 2's is 0.35 / 0.65 ≈ 0.538 — together they still sum to 1, confirming the renormalization is consistent. The claim that expert 4 keeps its raw softmax value of 0.300 unchanged ignores that top-k gating always renormalizes over the surviving subset, since the original 6-way softmax was calibrated to sum to 1 across all six experts, not just the two chosen ones. The claim of 0.538 mistakenly assigns expert 4 the weight that actually belongs to expert 2, confusing which of the two selected experts gets the larger share. The claim of 0.375 comes from mistakenly including a third expert (expert 5, gate value 0.15) in the renormalization pool, which violates the top-2 constraint specified by the algorithm — only the two highest-scoring experts should ever be renormalized and combined.
Question 59 · pipeline parallelism · hard
A GPipe-style training run splits a mini-batch across P = 4 pipeline stages (one GPU per stage) into M = 8 micro-batches. Using the bubble-fraction approximation bubble = (P − 1) / M, and given that 1F1B (one-forward-one-backward) scheduling interleaves forward and backward passes instead of running all forward passes before any backward pass, which statement correctly gives both the bubble fraction and how 1F1B changes peak activation memory compared to GPipe?
With P = 4 and M = 8, the bubble fraction (P−1)/M works out to 3/8 = 37.5%, and 1F1B keeps peak activation memory at O(P) instead of GPipe's O(M) by ensuring at most about P micro-batches' activations are ever held simultaneously.
Because all four stages are idle during each micro-batch's startup, the bubble fraction equals P/M = 4/8 = 50%, though 1F1B still bounds peak activation memory to O(P) the same way GPipe does not.
Applying (P−1)/M gives a bubble fraction of 3/8 = 37.5%, but 1F1B actually pushes peak activation memory up to O(M) since every micro-batch's forward activations must be buffered before any backward pass can start.
Since only the pipeline's very first micro-batch ever experiences fill latency, the bubble fraction is 1/8 = 12.5%, and 1F1B reduces peak activation memory to O(1) by discarding each micro-batch's forward activations immediately once computed.
Answer: A. With P = 4 and M = 8, the bubble fraction (P−1)/M works out to 3/8 = 37.5%, and 1F1B keeps peak activation memory at O(P) instead of GPipe's O(M) by ensuring at most about P micro-batches' activations are ever held simultaneously.
ExplanationWith P = 4 pipeline stages and the batch split into M = 8 micro-batches, the bubble fraction is (P−1)/M = 3/8 = 37.5%: three of the four stages sit idle while the pipeline fills (waiting for the first micro-batch to arrive) and drains (waiting for the last micro-batch to finish), and that fixed idle cost is amortized over all M micro-batches processed. On the memory side, GPipe runs every micro-batch's forward pass before starting any backward pass, so it must hold activations for all M micro-batches simultaneously — O(M) memory. 1F1B instead starts the backward pass for an early micro-batch as soon as its gradient is needed rather than waiting for every micro-batch to finish forward propagation, which caps the number of micro-batches with live, un-backpropagated activations at roughly P, giving O(P) memory — a real reduction versus GPipe. A claim that substitutes P/M for (P−1)/M overstates the idle fraction as 50% instead of 37.5%, since it double-counts stage 4's own processing time as idle time. A claim that 1F1B raises memory to O(M) has the comparison backwards — O(M) buffering is what GPipe does, not what 1F1B avoids. And a claim that activations can shrink to O(1) right after the forward pass ignores that the backward pass still needs those stored activations to compute gradients; eliminating them entirely requires a separate technique, activation checkpointing with recomputation, not 1F1B scheduling by itself.
Question 60 · nucleus sampling · hard
A language model's next-token distribution, already sorted in descending order of probability, is [0.40, 0.25, 0.15, 0.10, 0.06, 0.04]. Applying nucleus (top-p) sampling with p = 0.75, which tokens make up the nucleus, and what is the renormalized sampling probability of the third-ranked token?
The nucleus consists of the top three tokens (0.40, 0.25, 0.15), since their cumulative probability of 0.80 is the first prefix sum to reach or exceed p = 0.75, making the third-ranked token's renormalized probability 0.15 / 0.80 = 0.1875
Only the top two tokens (0.40 and 0.25) belong to the nucleus, because their cumulative probability of 0.65 is the closest sum to p = 0.75 without exceeding it, leaving the second-ranked token with a renormalized probability of about 0.385
Top-p = 0.75 means the smallest number of tokens making up 75% of the vocabulary size, not probability mass, is kept; with six tokens in the distribution the top four (0.40, 0.25, 0.15, 0.10) are retained, giving the third-ranked token a renormalized probability of 0.15 / 0.90 ≈ 0.167
Nucleus sampling always keeps only the single highest-probability token, exactly as greedy decoding does, so the third-ranked token is excluded from the sampling pool entirely and effectively has a renormalized probability of 0
Answer: A. The nucleus consists of the top three tokens (0.40, 0.25, 0.15), since their cumulative probability of 0.80 is the first prefix sum to reach or exceed p = 0.75, making the third-ranked token's renormalized probability 0.15 / 0.80 = 0.1875
ExplanationNucleus (top-p) sampling keeps the smallest prefix of the sorted probability list whose cumulative sum is at least p, then renormalizes only the kept probabilities so they sum to 1. Here the prefix sums are 0.40, 0.65, 0.80, 0.90, 0.96, and 1.00. The first prefix sum that reaches or exceeds p = 0.75 is 0.80, reached once the third token is included, so the nucleus is the set {0.40, 0.25, 0.15} — not just the first two tokens, and not the first four. Dividing each of these three probabilities by the nucleus's total mass (0.80) renormalizes them to 0.5, 0.3125, and 0.1875, so the third-ranked token's renormalized probability is 0.15 / 0.80 = 0.1875. Stopping at the top two tokens is invalid because their cumulative sum of 0.65 is still below p = 0.75 — nucleus sampling requires the cumulative mass to reach or exceed p, not merely come close to it, so a partial prefix that hasn't accumulated enough mass is never a valid cutoff. Treating p as a fraction of the vocabulary's token count confuses top-p with top-k: top-p thresholds cumulative probability mass, while top-k thresholds a fixed number of tokens, and the number of tokens top-p retains varies with how peaked or flat the distribution is rather than tracking a fixed percentage of the vocabulary. Nucleus sampling is also not deterministic like greedy decoding — it samples from the renormalized distribution over all retained tokens, so the third-ranked token stays eligible for selection with probability 0.1875 rather than being excluded.