Efficient architectures practice problems
23 problems · 0 solved
Standard attention gets expensive as sequences grow, and dense models get expensive as they grow wider. Efficient architectures cut that cost by sharing work, skipping work or doing work only where it is needed. A mixture of experts, for example, is like a hospital that sends each patient to the right specialist instead of having every doctor see everyone. These problems cover the main tricks used in current LLMs. You will compare KV cache size for multi-head, grouped-query and latent attention, share keys and values with grouped-query attention, limit attention to a sliding window and decode with a ring-buffer KV cache, write causal linear attention with a running state, count total and active parameters in an MoE layer, route tokens to their top two experts, enforce expert capacity, compute the Switch load-balancing loss, route tokens with Mixture-of-Depths, and merge similar tokens. Start with the Easy problems on KV cache size and parameter counts. Then do grouped-query attention and expert routing, and finish with the ring buffer, load balancing and token merging. These designs decide serving cost in production, and interviewers ask about them often.
Easy 9
- Limit attention to a sliding window of recent tokens
- Compare KV cache size for multi-head, grouped-query and latent attention
- Count total and active parameters of an MoE layer
- Compute model FLOPs utilization (MFU) for a training run
- Estimate KV cache memory with cross-layer KV sharing
- Choose which positions stay in an attention-sink streaming cache
- Build a local plus global attention mask
- Prune weights to 2:4 structured sparsity
- Compute savings from confidence-based early exit
Medium 8
- Share keys and values across heads with grouped-query attentionPro
- Route each token to its top 2 experts in a mixture of expertsPro
- Causal linear attention with a running statePro
- Route tokens with expert capacity and drop the overflowPro
- Route tokens with Mixture-of-DepthsPro
- Implement top-k sparse attention per queryPro
- Evict KV cache entries while keeping heavy hitters and recent tokensPro
- Pick the rank that keeps a target energy in a low-rank factorizationPro
Hard 6
- Compute the Switch Transformer load-balancing lossPro
- Decode with a sliding-window KV cache stored as a ring bufferPro
- Merge similar tokens with bipartite matchingPro
- Select key blocks by compressed scores, then attend inside themPro
- Compute multi-head latent attention scores from the latent cachePro
- Run the gated delta rule for linear attentionPro