Exercises

Practice residual traces, normalization statistics, norm ordering, MLP shapes, position independence, GELU, gated parameter counts, dropout modes, and silent block failures.

Use the stated convention in each problem. Show intermediate values when a problem asks for a calculation.

Q1. Trace both residual additions

For one token, x=[1,2]x=[1,2], attention returns [0.5,1][-0.5,1], and the MLP returns [2,1][2,-1]. Calculate uu and yy.

Answer it first, then check.

Hint
First use u=x+au=x+a, then y=u+my=u+m.
Solution
u=[0.5,3]u=[0.5,3] and y=[2.5,2]y=[2.5,2].
Not attempted
Review

Not marked done.

Q2. Calculate LayerNorm statistics

Ignoring epsilon, calculate the mean and population variance of [2,4,6][2,4,6].

Answer it first, then check.

Hint
Divide the squared-deviation sum by 3.
Solution
The mean is 44 and the variance is (4+0+4)/3=8/3(4+0+4)/3=8/3.
Not attempted
Review

Not marked done.

Q3. Separate LayerNorm from RMSNorm

Which operation is unchanged before learned affine parameters when the same constant is added to every coordinate: LayerNorm or RMSNorm?

Answer it first, then check.

Hint
Only one operation subtracts a mean.
Solution
LayerNorm. RMSNorm retains the shifted direction.
Not attempted
Review

Not marked done.

Q4. Order a pre-norm block

Put these operations in order: MLP normalization, attention residual addition, MLP residual addition, attention normalization.

Choose the correct order

Select one choice, then check.

Hint
Use u=x+A(N1(x))u=x+A(N_1(x)) before y=u+M(N2(u))y=u+M(N_2(u)).
Solution
Attention normalization; attention residual addition; MLP normalization; MLP residual addition.
Not attempted
Review

Not marked done.

Q5. Derive MLP shapes

For dmodel=6d_{model}=6 and dff=24d_{ff}=24, give the shapes of WupW_{up} and WdownW_{down}.

Answer it first, then check.

Hint
Follow model width to hidden width and back.
Solution
Wup:(6,24)W_{up}:(6,24) and Wdown:(24,6)W_{down}:(24,6).
Not attempted
Review

Not marked done.

Q6. Test position-wise independence

An MLP receives four token records. You alter only record 3. Which output records may change in a correct position-wise implementation?

Answer it first, then check.

Hint
The MLP is applied independently at each position.
Solution
Only output record 3 may change.
Not attempted
Review

Not marked done.

Q7. Calculate a GELU value

Using GELU(x)=xΦ(x)\operatorname{GELU}(x)=x\Phi(x) and Φ(1)0.841345\Phi(1)\approx0.841345, calculate GELU(1)(1).

Compute it first, then check your number.

Hint
Substitute x=1x=1 directly.
Solution
1×0.841345=0.8413451\times0.841345=0.841345.
Not attempted
Review

Not marked done.

Q8. Count a gated MLP

Ignoring all biases, a gated MLP has two (dmodel,dff)(d_{model},d_{ff}) input projections and one (dff,dmodel)(d_{ff},d_{model}) output projection. How many parameters does it have for dmodel=4d_{model}=4, dff=6d_{ff}=6?

Compute it first, then check your number.

Hint
Count both gate/value projections and the down projection.
Solution
2(4)(6)+(6)(4)=722(4)(6)+(6)(4)=72.
Not attempted
Review

Not marked done.

Q9. Compare dropout modes

With inverted dropout, p=0.5p=0.5, z=6z=6, and a retained mask entry, give the training value and evaluation value.

Answer it first, then check.

Hint
Training divides by 1p1-p.
Solution
Training returns 6/0.5=126/0.5=12; evaluation returns 66.
Not attempted
Review

Not marked done.

Q10. Design a block audit

A block has the correct final shape but changing token 2 changes token 1 during the MLP-only stage. Name the violated contract and the first implementation axis or operation to inspect.

Choose the contract and first inspection

Select one choice, then check.

Hint
Ask which axis an MLP is allowed to mix.
Solution
The position-wise independence contract is violated. Inspect whether an MLP projection, reshape, or reduction treats the sequence axis as a feature axis.
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.