FixTheRobot Explore Robotics / LLM / LM10 / LM10-L2

This lab works on phones, but writing code is much easier on a laptop.

LLM · Modern LLM Architecture and Inference · LM10-L2 · Intermediate

Compare Attention Variants

Modern decoder-only models keep the transformer block but change its parts: keys and values are shared between query heads, the feed-forward layer is gated, and sometimes only a few of many expert feed-forward layers run for each token.

You will pick a sharing level for a cache budget, count what sharing saves, and count the difference between the parameters a model stores and the parameters it uses for one token.

Your task

    Simulation
    solution.pyLoading Python…
    Ctrl+Enter runs
    What Python can I use?

    Plain Python with math (and slamkit for small matrix helpers: matmul, transpose, solve, inverse, identity). Images, point clouds and detections arrive as lists inside the dictionary D; an image is a list of rows, each row a list of pixels. There is no NumPy or OpenCV: you write the algorithm yourself, which is the point of the lab. Print with print().

    Hints

    What this lab teaches

    Stage 1 explores the trade-off in the number of key-value heads. Stage 2 counts attention parameters and cache bytes for multi-head, grouped-query and multi-query layouts. Stage 3 counts the parameters of a gated feed-forward layer and of a mixture of experts. Only parameter and byte counts are computed; no model is run and no quality is measured. Your code is graded on hidden configurations.

    Theory for this lab

    Modern LLM Architecture and Inference labs

    1. LM10-L1: KV-Cache Memory and Behaviour
    2. LM10-L2: Compare Attention Variants: this lab.
    3. LM10-L3: Implement a KV Cache and Rotary Embeddings in PyTorch

    Educational simplification: no biases, a generic 4,096-wide layer with 32 query heads in Stage 1, a single router matrix for the mixture of experts, and counts only. Real models differ in details such as the rounding of the hidden width.

    Get the next lab

    Get notified when new robotics labs are released. One email per new lab, nothing else.