Python and NumPy
LLM coding practice
50 hands-on problems covering the core algorithms behind LLM inference: numerical stability, BPE and GQA attention, sampling and speculative decoding, paged KV memory and INT8/INT4 quantization, and continuous-batching schedulers.
Read every problem statement, function signature, and worked example below without signing in. Sign in on a desktop browser (1024px or wider) to run Python and NumPy tests in your browser and track completed problems.
Sign in to solve problemsTensor and numerical foundations
10 problemsProduction inference engines depend on numerically stable reductions, normalization layers, and batched projections so mixed-precision forward passes never overflow or lose rank.
- 01 Stable Vocabulary SoftmaxEasy
- 02 Normalize Retrieval EmbeddingsEasy
- 03 Batched Linear ProjectionEasy
- 04 RMSNormMedium
- 05 LayerNormMedium
- 06 Token Cross Entropy with Ignored LabelsMedium
- 07 Project and Split Packed QKVMedium
- 08 SwiGLU Feed-Forward LayerMedium
- 09 RMSNorm Backward PassHard
- 10 Gradients for Tied Token EmbeddingsHard
Tokenization and attention
10 problemsEvery serving request begins with byte-level BPE tokenization and spends its prefill and decode compute inside causal, grouped-query, or tiled online-softmax attention kernels.
- 11 Byte Tokenization with EOSEasy
- 12 Masked Mean PoolingEasy
- 13 Causal Masks with Cached PositionsEasy
- 14 Ranked BPE MergesMedium
- 15 Incremental UTF-8 DecodingMedium
- 16 Rotary Position EmbeddingsMedium
- 17 Grouped-Query AttentionMedium
- 18 ALiBi Attention BiasMedium
- 19 Cached Transformer Decoder BlockHard
- 20 Attention with Online SoftmaxHard
Decoding and sampling
10 problemsAutoregressive servers run decoding rules on every generated token: temperature scaling, top-k and nucleus filtering, repetition penalties, grammar FSMs, and speculative draft verification.
- 21 Greedy Decoding with EOSEasy
- 22 Completed Stop SequencesEasy
- 23 Sign-Aware Repetition PenaltyEasy
- 24 Temperature and Top-K DistributionMedium
- 25 Nucleus Sampling CandidatesMedium
- 26 Contrastive Search RerankingMedium
- 27 Repeated N-Gram BlockingMedium
- 28 Finite-State Constrained DecodingMedium
- 29 Beam Search with Finished HypothesesHard
- 30 Speculative Acceptance and CorrectionHard
KV memory and quantization
10 problemsOn serving GPUs, KV-cache capacity and weight precision set maximum concurrency and decode bandwidth. Engines page KV blocks, share prefixes with copy-on-write, and quantize tensors to INT8, FP8, and INT4.
- 31 Grouped-Query KV StorageEasy
- 32 Token-to-Page Address TranslationEasy
- 33 Per-Channel INT8 DequantizationEasy
- 34 KV Append and RollbackMedium
- 35 Attention Sinks and Sliding WindowsMedium
- 36 Per-Channel INT8 QuantizationMedium
- 37 Affine-Quantized Matrix MultiplicationMedium
- 38 Signed INT4 PackingMedium
- 39 Copy-on-Write KV PagesHard
- 40 Packed Groupwise INT4 MultiplicationHard
Batching and serving algorithms
10 problemsModern LLM servers schedule work at every step: admitting requests under token budgets, chunking long prefills, reusing cached prefixes, and routing traffic to KV-warm workers.
- 41 Last Real Token LogitsEasy
- 42 TTFT and Decode LatencyEasy
- 43 Stable Length-Bucketed BatchesEasy
- 44 Deficit Round-Robin SchedulingMedium
- 45 Token-Budgeted Chunked PrefillMedium
- 46 Longest-Prefix LRU CacheMedium
- 47 KV-Aware Request RoutingMedium
- 48 Sliding Token-Budget AdmissionMedium
- 49 Paged Continuous BatchingHard
- 50 Minimum-Cost Padded Batch PartitionHard
Study the concepts alongside the code
Pair these implementations with the free Inference Engineering Foundations course, check real model configs in the compatibility directory, or size memory in the GPU memory calculator.