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 V=8V=8, C=4C=4, L=2L=2, h=2h=2, and dh=2d_h=2 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
Greedy decoding uses argmax.
Solution
Append ID 2, giving [0,1,2].
Not attempted
Review

Not marked done.

Q2. Apply temperature

Scale logits [2,0,-2] with temperature 0.5.

Compute it first, then check your number.

Hint
Temperature acts before softmax.
Solution
The scaled row is [4,0,-4].
Not attempted
Review

Not marked done.

Q3. Distinguish prefill and decode

Which operation belongs to one-token decode after a prompt has already filled the cache?

Choose one

Select one choice, then check.

Hint
The prompt is already represented in the cache.
Solution
Decode projects the current token, appends its K/V per layer, and calculates its logits row against the cached prefix.
Not attempted
Review

Not marked done.

Q4. Calculate cache shape and count

For the frozen model at B=1B=1 and T=3T=3, give each layer's K tensor shape and the total K/V scalar count across both layers.

Answer it first, then check.

Hint
Use 2(2)(1)(2)(3)(2)2(2)(1)(2)(3)(2) for total K and V.
Solution
Each K has shape (1,2,3,2)(1,2,3,2); all K/V tensors contain 48 scalars.
Not attempted
Review

Not marked done.

Q5. Calculate one attention score

For dh=2d_h=2, query [2,1][2,1], and key [1,1][1,-1], calculate the scaled dot-product score.

Compute it first, then check your number.

Hint
2(1)+1(1)=12(1)+1(-1)=1.
Solution
1/20.7071071/\sqrt2\approx0.707107.
Not attempted
Review

Not marked done.

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 C=4C=4?

Answer it first, then check.

Hint
Add consumed prompt and generated-input counts.
Solution
The next index is 4, which is outside the valid range [0,4)[0,4).
Not attempted
Review

Not marked done.

Q7. Interpret logit error

Cached and full logits differ by 3×1063\times10^{-6} under tolerance 10510^{-5} for one float32 run. What is the appropriate conclusion?

Choose one

Select one choice, then check.

Hint
Compare the measured error with the acceptance threshold.
Solution
The row passes this regression check, but the conclusion is bounded to the tested prefix, model, dtype, environment, and tolerance.
Not attempted
Review

Not marked done.

Q8. Calculate float32 cache bytes

For B=2,L=4,h=8,T=16,dh=32B=2,L=4,h=8,T=16,d_h=32, calculate K/V scalar count and float32 payload bytes.

Answer it first, then check.

Hint
Calculate 2LBhTdh2LBhTd_h.
Solution
2(4)(2)(8)(16)(32)=65,5362(4)(2)(8)(16)(32)=65,536 scalars and 262,144 bytes.
Not attempted
Review

Not marked done.

Q9. Choose batched stopping behavior

Row A reaches <eos>. Row B has not stopped but already has cache length CC. What stopping reasons should be reported?

Answer it first, then check.

Hint
Do not call a context limit an EOS prediction.
Solution
Report eos for A and context for B.
Not attempted
Review

Not marked done.

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.

Choose the three failures

Select one choice, then check.

Hint
Audit how often, where, and for whom cache state is written.
Solution
The token was appended twice, layer 2 reused layer 1 state, and cache storage is incorrectly shared across requests.
Not attempted
Review

Not marked done.

Pause and reflect

Which exercises were difficult, what mistake pattern did you notice, and what should you practice again? The note stays with this exercise set.

0 of 10 exercises marked done

Review

Not marked done.