Exercises
Practice greedy decoding, temperature, prefill and decode, cache shapes, attention scores, positions, numerical tolerance, memory, batched stopping, and cache-failure diagnosis.
Use the frozen model with , , , , and unless an exercise gives other values.
Q1. Trace a greedy generation step
Prompt IDs are [0,1]. The final logits row is [0,1,4,2,3,-1,0,0]. Which ID
is appended by greedy decoding, and what is the extended input?
Answer it first, then check.
Hint
Solution
[0,1,2].Q2. Apply temperature
Scale logits [2,0,-2] with temperature 0.5.
Compute it first, then check your number.
Hint
Solution
[4,0,-4].Q3. Distinguish prefill and decode
Which operation belongs to one-token decode after a prompt has already filled the cache?
Select one choice, then check.
Hint
Solution
Q4. Calculate cache shape and count
For the frozen model at and , give each layer's K tensor shape and the total K/V scalar count across both layers.
Answer it first, then check.
Hint
Solution
Q5. Calculate one attention score
For , query , and key , calculate the scaled dot-product score.
Compute it first, then check your number.
Hint
Solution
Q6. Continue the position index
A prompt of length 2 is cached. Two generated tokens have since been consumed as inputs. What position index would the next input require, and is it valid for ?
Answer it first, then check.
Hint
Solution
Q7. Interpret logit error
Cached and full logits differ by under tolerance for one float32 run. What is the appropriate conclusion?
Select one choice, then check.
Hint
Solution
Q8. Calculate float32 cache bytes
For , calculate K/V scalar count and float32 payload bytes.
Answer it first, then check.
Hint
Solution
Q9. Choose batched stopping behavior
Row A reaches <eos>. Row B has not stopped but already has cache length .
What stopping reasons should be reported?
Answer it first, then check.
Hint
Solution
eos for A and context for B.Q10. Diagnose a cache trace
The cache length grows from 2 to 4 after one consumed token, layer 2's cached values exactly equal layer 1's, and a different request changes the logits. Name the three failures.
Select one choice, then check.