Stable softmax
Support arbitrary dimension, preserve shape, and explain max subtraction.
Module 14
A focused prompt bank inspired by common LLM and PyTorch hand-coding interviews.
Answer Template
Math And Losses
Support arbitrary dimension, preserve shape, and explain max subtraction.
Use logsumexp and gather. Explain why direct softmax then log is less stable.
Implement the stable binary loss without separately applying sigmoid first.
Normalize query/docs, compute scores, return top-k IDs, and handle zero vectors.
Transformer Blocks
Implement forward pass and explain what dimensions are normalized.
Implement masks, softmax, and value mixing for batched multi-head tensors.
Project Q/K/V, reshape heads, apply attention, merge heads, and project out.
Implement gate/up/down projections and explain why gated FFNs help capacity.
Rotate Q/K pairs, preserve shape, and test even head dimensions.
LLM Systems
Sort probabilities, keep the nucleus, sample in sorted space, and map back to original token IDs.
Show prefill/decode split and estimate cache memory from model dimensions.
Sketch request states, memory admission, token budget, and fairness rules.
Freeze base weights, add low-rank adapters, count trainable parameters, and discuss merge-at-inference.
Count adjacent pairs, merge the best pair, repeat, then encode with learned merges.