LLM + RoboticsModule 08 · Stage 11

Paper-to-production prototyping

Read a new paper, find the small piece of code that carries its idea, drop it into a strong baseline, and measure honestly whether it helps. The last step is where most reproductions go wrong.

PrerequisitesStage 01 (PyTorch fluency), Stage 10 (evals); comfortable reading equations
Time1–3 weeks per small reproduction, part-time. It's a habit, not a stage you finish.
HardwareLaptop or one Colab GPU for the small version; the full version depends entirely on the paper
Key papersHenderson et al. 2017 · Melis et al. 2017 · Engstrom et al. 2020 · Narang et al. 2021 · Agarwal et al. 2021

Source: Suraj Sharma's roadmap post on X, stage 11

Start here (no maths needed)

Scientists write papers about new ideas. A research engineer turns the idea into working code quickly, then checks fairly whether it's really better.

Think of it like this

A famous chef publishes a new cake recipe and says it's "the fluffiest ever". You want to test it. First you find the one trick that's actually new (maybe whipping the eggs longer); the rest is a normal cake. You bake your usual cake and the new one side by side, same oven, same eggs. Then you ask several friends to taste both, without telling them which is which. If only one friend prefers the new cake, that proves nothing. If most of them do, every time you bake, the trick is real.

How it works

  1. Read the paper and find the one new idea. Most of the paper is setup and background.
  2. Write that idea as a small piece of code with an on/off switch.
  3. Start from a model that already works well (the "baseline").
  4. Train with the switch off and with it on, the same way, several times.
  5. Compare fairly: is the difference bigger than the normal wobble between runs?

Why robots care

Testing a robot is slow. If a robot picks up a cup 15 times out of 20 with a new method and 12 times out of 20 with the old one, that looks like a win. It isn't proof. A difference that small, from so few tries, happens by luck quite often. Robot teams have to know this before they switch to a new method.

Try it

Words to know

Paper
A write-up of a new idea and the tests that show it works.
Reproduce
Build the idea yourself and check you get the same result.
Baseline
The normal, well-tuned method you compare the new idea against.
Seed
The starting number for a computer's "random" choices. Different seeds give slightly different results.
Noise
Differences that come from luck, not from a real improvement.

Going deeper: everything below is the full version. On a first read, skim the headings, try the demo and read the "Why it matters for robotics" box.

1. What this stage covers

TL;DR

The post asks you to learn fast reproduction, to strip a paper down to what matters, and to find its "minimum viable kernel". Then it asks you to implement a brand-new paper's core idea in under 500 lines of PyTorch and benchmark it against a baseline. The coding part is the easy half. The hard half is the comparison: a tuned baseline, the same budget for both arms, several seeds, and an interval rather than a single number. The literature is full of "improvements" that vanished once someone did this.

2. Concepts, explained

Rapid arXiv reproduction

Reading for reproduction is different from reading to learn. You're looking for an executable spec. A workable order:

  1. Abstract, main figure, main results table. Write down the claim in one sentence, with its number: "X improves Y on benchmark Z by N points at the same compute."
  2. The method section and any algorithm box. Translate each equation into tensor shapes. If you can't say the shape of every symbol, you don't understand it yet.
  3. The appendix. Hyperparameters, initialisation, warmup, data processing and evaluation details live here. Most reproduction failures trace back to something in the appendix, or missing from it.
  4. Code, if released. Diff the code against the paper. Where they disagree, the code is what produced the numbers.

Henderson et al. (2017), Deep Reinforcement Learning that Matters, showed how fragile this is in RL. Random seeds, environment non-determinism and implementation choices moved reported results enough to change conclusions, and the authors called for significance testing and standard reporting.

Stripping academic fluff

Papers are written to be accepted, so the framing often outgrows the mechanism. Stripping means separating three things: the mechanism (the change in the computation), the scaffolding (everything else the authors changed while they were at it) and the story (why they say it works). Only the first is what you reproduce. The ablation table is your best friend: it shows which parts carry the gain.

Be careful, though. The "fluff" is sometimes load-bearing. Engstrom et al. (2020), Implementation Matters in Deep Policy Gradients, found that code-level optimisations, details found only in implementations or mentioned in passing, accounted for most of PPO's reward gain over TRPO. Strip too much and your "faithful" reproduction underperforms for reasons that have nothing to do with the idea. The cure is to keep a list of every deviation you make and test the suspicious ones.

The minimum viable kernel

The post's phrase means the smallest piece of code that, swapped into a strong baseline, carries the claimed effect. For most papers this is a function or a module: a new attention variant, a normalisation, an optimiser update, a loss term, a sampling rule. A good kernel has three properties:

class Block(nn.Module):
    def __init__(s, cfg):
        super().__init__()
        s.attn = NewAttn(cfg) if cfg.use_new else Attn(cfg)   # the only change
        ...

def test_reduces_to_baseline():
    torch.manual_seed(0); x = torch.randn(2, 16, 64)
    new = NewAttn(cfg, alpha=0.0); old = Attn(cfg)
    new.load_state_dict(old.state_dict(), strict=False)
    assert torch.allclose(new(x), old(x), atol=1e-6)

Narang et al. (2021), Do Transformer Modifications Transfer Across Implementations and Applications?, is the cautionary tale. They tested many published Transformer modifications in one shared codebase and found most didn't meaningfully improve performance. Many of those that helped were developed in that same codebase or were minor changes. A kernel that wins in its home codebase may not win in yours.

Benchmarking against a baseline honestly

This isn't on the post's Learn list, but its Practice step depends on it. Four rules:

  1. Tune the baseline as hard as the new method. Melis, Dyer and Blunsom (2017), On the State of the Art of Evaluation in Neural Language Models, re-tuned standard LSTMs with large-scale hyperparameter search and found they beat several newer architectures. Many "wins" were really tuning-budget gaps.
  2. Match the budget. Same tokens, same steps or same FLOPs, stated explicitly. A method that wins only because it ran longer hasn't won.
  3. Run several seeds. Bouthillier et al. (2021), Accounting for Variance in Machine Learning Benchmarks, show data sampling, initialisation and hyperparameter choice all move results markedly, and recommend varying them when comparing.
  4. Report intervals, not points. Agarwal et al. (2021), Deep RL at the Edge of the Statistical Precipice, found point estimates from a few runs led to conclusions that a proper statistical analysis didn't support. They recommend bootstrap confidence intervals and robust aggregates such as the interquartile mean.

When both models are scored on the same test examples, use a paired comparison. Take the per-example difference, then bootstrap over examples:

d_i  = score_B(x_i) − score_A(x_i)              for each test example i
Δ̂    = mean(d)
repeat R times: resample n indices with replacement → mean of d at those indices
95% CI = 2.5th and 97.5th percentiles of the R resampled means
"B beats A" only if the whole CI is above 0

Pairing removes the shared difficulty of each example: if both models fail the same hard questions, that doesn't add noise to the difference. Two overlapping unpaired intervals don't mean "no difference". A paired interval that crosses zero does mean you can't tell. Module 04 makes the same point about bootstrapping over clips.

Interactive: is that win real? A paired bootstrap

Model A gets 70% of test examples right. Model B's true accuracy is A's plus the True gain. Agreement sets how often the two models share the same per-example difficulty. Each test set is a random draw; the bootstrap uses 1,000 resamples. Filled bars: paired bootstrap of B − A. Outline: unpaired bootstrap (A and B resampled separately). Shaded band: paired 95% interval. Vertical line: zero.

Test set #

Observed B − A
–
Paired 95% CI
–
Unpaired 95% CI
–
Verdict
–

Try this: at the defaults (200 examples, true gain +3 points, agreement 0.5), the first test set shows B ahead by 3.5 points, but the paired interval runs from about −3.5 to +10. Over 40 simulated test sets, B came out ahead about three times in four, yet the paired interval cleared zero only about one time in twenty. Raise test examples to 2,000 and it clears zero most of the time. Raise agreement and the paired interval narrows while the unpaired one doesn't move.

3. The practice project

(a) Laptop / Colab version: one kernel, one baseline, honest numbers

  1. Baseline. Clone nanoGPT and train its character-level Shakespeare config. The README describes a GPU run of a few minutes and a smaller CPU setting. Record validation loss. Run it with three seeds to see your noise floor before you change anything.
  2. Pick a paper. Choose a recent one whose core idea is a local change: an attention or normalisation variant, an optimiser, a loss term, a positional encoding. Write the claim in one sentence, with its number.
  3. Write the kernel behind a use_new flag, with the reduction and gradient tests above. Keep a deviations list in the README.
  4. Match budgets and tune both. Same iterations, same batch, same data. Give the baseline and the new method the same small learning-rate sweep (for example three values each).
  5. Compare. At least three seeds per arm; report mean and range of validation loss, and a paired bootstrap over evaluation batches if you score both on the same batches.
  6. Write it up (that's Stage 12): claim, setup, result with intervals, deviations, and what this does not show.

What to expect: no promise. Given Narang et al.'s findings, a common honest outcome at this scale is "within seed noise". That's a valid result if your baseline was tuned and your kernel passed its tests. A tiny character model also may not show effects that only appear at scale, so say so.

import numpy as np

def paired_ci(a, b, R=2000, seed=0):
    d = np.asarray(b, float) - np.asarray(a, float)   # per-example B - A
    rng = np.random.default_rng(seed)
    idx = rng.integers(0, len(d), (R, len(d)))
    means = d[idx].mean(axis=1)
    lo, hi = np.percentile(means, [2.5, 97.5])
    return d.mean(), lo, hi

obs, lo, hi = paired_ci(scores_a, scores_b)
print(f"B-A = {obs:+.3f}  95% CI [{lo:+.3f}, {hi:+.3f}]",
      "real" if lo > 0 or hi < 0 else "can't tell")

(b) The full version from the post

Take a paper from this week, implement its core algorithm in under 500 lines of PyTorch, and benchmark it against its baseline at the scale the paper used. Cost depends entirely on the paper. An optimiser or attention tweak tested on GPT-2-small-sized models fits on a single rented GPU over days. A claim made at 7B parameters and hundreds of billions of tokens is out of reach for an individual; then reproduce the trend at small scale and say clearly that you didn't test the paper's scale. CS336's assignments are good preparation: little scaffolding, real budgets.

The 500-line target is realistic for the kernel plus a minimal training loop. It isn't realistic for data pipelines, distributed training or evaluation harnesses. Reuse those from a trusted baseline repo rather than rewriting them.

(c) Pitfalls

4. Reality check

The post's claim is that translation speed, from maths to working code, is your main value to an AI lab.

5. In this course

6. Why it matters for robotics

7. Self-check

What's a "minimum viable kernel", and what single test catches the most bugs in one?

The smallest switchable piece of code that carries a paper's idea when dropped into a strong baseline. The reduction test: with the new hyperparameter at a neutral value, it must reproduce the baseline's output exactly.

Your new method beats the baseline by 0.02 validation loss on one seed each. What do you do before claiming anything?

Check the budgets match, give both the same tuning sweep, run several seeds per arm, and report the spread or an interval. If the seed-to-seed spread is around 0.02, you can't tell them apart yet.

Why is a paired bootstrap usually tighter than comparing two separate confidence intervals?

Both models are scored on the same examples, and their errors are correlated: hard examples are hard for both. The per-example difference cancels that shared difficulty, so its variance is smaller. In the demo, raising agreement narrows the paired interval but not the unpaired one.

What did Engstrom et al. (2020) find about PPO versus TRPO?

Code-level optimisations, details found only in implementations or treated as auxiliary, were responsible for most of PPO's gain in cumulative reward over TRPO. Attribution of gains to the "core algorithm" can be wrong.

What did Melis et al. (2017) show, and what's the lesson?

Properly regularised and tuned standard LSTMs beat several newer architectures on language modelling. The lesson: tune your baseline as hard as your new method, or the comparison measures tuning effort, not ideas.

8. Courses & content

ResourceTypeUse it for
labml.ai annotated paper implementationsAnnotated code (free)Many papers implemented with side-by-side notes
Karpathy · nanoGPTCode (free)A minimal, hackable baseline to drop new ideas into
30u30 (this course's Module 06)Exercises (free)Thirty from-scratch reproductions to practise on
Stanford CS336University course (free materials)Low-scaffolding assignments: the closest thing to lab work

Start with nanoGPT: it's the baseline you'll drop kernels into for the laptop project, and it's small enough to read in an afternoon.

Full course map for all 12 stages →

9. Papers & docs