Attention and transformers practice problems

21 problems · 0 solved

Attention lets every token in a sequence look at every other token and decide which ones matter for it. It works like a lookup: each token sends a query, compares it with the keys of other tokens, and takes a weighted mix of their values. The transformer stacks this with feed-forward layers and normalization, and it is the core of every modern LLM. In these problems you will write scaled dot-product attention with a causal mask, apply key padding masks in a batch, split and merge attention heads, generate sinusoidal position encodings, rotate vectors with RoPE and scale it with NTK-aware interpolation, build ALiBi biases and T5 relative position buckets, count attention FLOPs, backpropagate through attention, and run a full pre-norm transformer block. Start with the Easy problems on sinusoidal encodings and attention entropy. Then write masked attention and head splitting, and finish with RoPE, attention backward and the full block. Writing attention from scratch is one of the most common LLM interview questions, and knowing the shapes and masks well saves hours when you debug real model code.

Easy 5

Medium 11

Hard 5

Related topics

All practice problems