# Post-Training Lab · training report

How the tiny models on gavish.ai/lab were trained, and what happened at each stage. Everything here was produced by the scripts in `lab-tools/` and can be reproduced on a laptop.

## Setup common to every domain

- **Model:** decoder-only transformer, 4 layers, 4 heads, width 128, character-level. Same architecture and weight layout as the in-browser engine (`public/lab/engine.js`), verified to match PyTorch to within 1e-6.
- **Hardware:** Apple M3 Pro, PyTorch 2.15.0 on `mps`.
- **Data:** fully synthetic, generated by `public/lab/tasks.js`. Each domain has a task generator, an honest grader, a deliberately hackable “lazy” grader, “internet-style” pre-training text, worked examples for SFT, and preference pairs.
- **Held-out discipline:** a fixed 25% of task *combinations* is reserved for the eval and benchmark sets. Training data, pre-training text and preference pairs never contain them (checked by `validate-tasks.mjs`).
- **Eval:** 100 held-out items, 8 samples each at temperature 1. pass@1 = average success rate per item; pass@8 = at least one of 8 succeeds.
- **Benchmark:** a further 100 held-out items in the style of a public benchmark (not the benchmark itself).
- **Stages:**
  1. **Pre-training:** next-character prediction on 200,000 lines of “internet” text with the domain's typical mistakes. 3,000 steps × 128 lines, AdamW, lr 3e-3 with warm-up and cosine decay.
  2. **SFT:** next-character prediction on the target output only, 150 steps × 32, lr 1e-3. The number of worked examples is set per domain so RL has room to show its effect (6–100; Math skips SFT and runs RL straight on the raw model).
  3. **RL (GRPO):** each step samples 16 problems × 8 attempts; rewards come from the real JS graders; advantage = (reward − group mean) / group std, minus a KL penalty β × (KL − mean KL) to the SFT model. 150 steps, lr 3e-4, β 0.05.
  4. **Reward hacking experiment:** the same RL run from the same SFT model, but rewarded by the lazy grader.
  5. **DPO and souping** (`post.py`): preference tuning toward each style of the domain's answer pairs, and weight averages of two specialists that share a parent.
  6. **Distillation** (`distill.py`): a 7× smaller student learns from the RL model, from its sampled answers (sequence-level) or its full next-character probabilities (soft labels), compared with plain SFT.

  7. **Extras** (`extra.py`): pass@k up to 64 for raw, SFT and RL; a reward model trained on grader-labeled preference pairs, then GRPO against it (β 0.01, 200 steps) with the real grader watching; best-of-N with a verifier, the reward model or majority vote; LoRA (rank 1, 4, 16 on all attention and MLP matrices, lr 5e-3, scale 2) vs full SFT, with forgetting measured on held-out pre-training text.

## Math · Countdown puzzles

- Parameters: 815,920 · vocabulary 48 characters · context 80 characters
- Pre-training: 3,000 steps on 200,000 lines, final loss 0.527, 2.7 min
- Honest reward: equation checker (hits the target, each number at most once)
- Lazy reward: “shorter is better”

| Stage | Held-out pass@1 | Held-out pass@8 | Notes |
|---|---|---|---|
| Raw (pre-trained) | 14.6% | 67.0% | |
| + SFT | skipped | | RL runs straight on the raw model (R1-Zero style) |
| + RL, honest reward | 42.8% | 64.0% | benchmark sample 31.5% |
| + RL, lazy reward | 0.0% | 0.0% | lazy reward 94.9%, benchmark 0.0% |

RL hill climb (held-out pass@1 every 30 steps): 20.0% → 25.8% → 25.8% → 29.5% → 36.2%

Lazy-reward run (accuracy, with the reward RL saw): 16.8% (reward 86.6%) → 17.0% (reward 86.6%) → 1.8% (reward 88.3%) → 0.0% (reward 95.0%) → 0.0% (reward 95.0%)

DPO (120 steps on 260 preference pairs, β 0.1, plus an NLL term on the chosen answer): style A 0.0% → 46.9% when preferring A (correct 16.9% → 1.2%); style B 100.0% → 100.0% when preferring B (correct → 35.6%).

Souping: Math has no SFT specialists, so the lab page shows a raw ↔ RL weight interpolation (WiSE-FT) computed by `export.mjs`.

Distillation (`distill.py`): teacher = the honest RL model (815,920 params, 40.4%); student = 2 layers × 64 (111,408 params, 7.3× smaller), same pre-training recipe. Held-out pass@1: raw student 14.8% · + 4,000 teacher answers 33.5% · + teacher probabilities 38.6%. The teacher's own answers were 44.8% correct.

pass@k (`extra.py`, 64 samples per problem): pass@1 raw 13.9% → RL 42.2%; pass@64 raw 99.0%, SFT 99.0%, RL 81.0%.

Reward model (`extra.py`): 111,472 params, trained on 1,394 grader-labeled pairs, 94.0% agreement on held-out pairs. GRPO against it (β 0.01, 200 steps): real pass@1 12.2% → peak 23.5% at step 40 → 3.8%; reward-model score -2.75 → +2.31.

Best-of-N from the raw model, N = 1 / 2 / 4 / 8 / 16 / 32: verifier 14.7% / 25.4% / 42.0% / 59.9% / 77.7% / 90.8%; reward model 14.7% / 23.9% / 34.6% / 43.3% / 49.6% / 54.2%; majority vote 14.7% / 14.5% / 15.3% / 18.4% / 20.8% / 24.5%.

LoRA vs full fine-tuning (SFT from raw, 100 examples, 150 steps; forgetting = rise in loss on held-out pre-training text from 0.578): full (815,920 trainable, lr 0.001) 4.5%, +2.296 · r=1 (8,192 trainable, lr 0.005) 0.0%, +1.759 · r=4 (32,768 trainable, lr 0.005) 0.5%, +2.294 · r=16 (131,072 trainable, lr 0.005) 1.0%, +2.954.

Wall time: SFT 3s, RL 0.6 min (including evals every 10 steps).

## Coding · Acme's private payments SDK

- Parameters: 818,996 · vocabulary 52 characters · context 96 characters
- Pre-training: 3,000 steps on 200,000 lines, final loss 0.262, 3.4 min
- Honest reward: unit tests against a mock of the SDK
- Lazy reward: “keep the change small”: any code that compiles scores, and shorter code scores higher

| Stage | Held-out pass@1 | Held-out pass@8 | Notes |
|---|---|---|---|
| Raw (pre-trained) | 0.0% | 0.0% | |
| + SFT (100 examples) | 81.1% | 85.0% | 98.8% on its own training examples |
| + RL, honest reward | 88.8% | 92.0% | benchmark sample 90.1% |
| + RL, lazy reward | 0.0% | 0.0% | lazy reward 89.5%, benchmark 0.0% |

RL hill climb (held-out pass@1 every 30 steps): 76.2% → 81.8% → 86.8% → 90.5% → 86.8%

Lazy-reward run (accuracy, with the reward RL saw): 73.8% (reward 46.6%) → 3.5% (reward 61.0%) → 0.0% (reward 58.8%) → 0.0% (reward 72.5%) → 0.0% (reward 81.9%)

DPO (120 steps on 139 preference pairs, β 0.1, plus an NLL term on the chosen answer): style A 98.1% → 100.0% when preferring A (correct 68.1% → 80.0%); style B 0.0% → 95.6% when preferring B (correct → 3.1%).

Souping: two specialists fine-tuned from the SFT model on “money calls” and “subscription calls” only; held-out pass@1 by mix (share of B): 0% → 95.0% · 25% → 95.8% · 50% → 88.0% · 75% → 79.5% · 100% → 72.0%

Distillation (`distill.py`): teacher = the honest RL model (818,996 params, 89.8%); student = 2 layers × 64 (112,948 params, 7.3× smaller), same pre-training recipe. Held-out pass@1: raw student 0.0% · + the 100 worked examples 94.2% · + 4,000 teacher answers 85.6% · + teacher probabilities 87.5%. The teacher's own answers were 89.0% correct.

pass@k (`extra.py`, 64 samples per problem): pass@1 sft 80.3% → RL 89.5%; pass@64 raw 0.0%, SFT 87.0%, RL 94.0%.

Reward model (`extra.py`): 113,012 params, trained on 1,500 grader-labeled pairs, 99.7% agreement on held-out pairs. GRPO against it (β 0.01, 200 steps): real pass@1 80.2% → peak 80.2% at step 0 → 0.0%; reward-model score +3.80 → +3.93.

Best-of-N from the SFT model, N = 1 / 2 / 4 / 8 / 16 / 32: verifier 80.2% / 82.1% / 82.9% / 83.4% / 84.4% / 85.5%; reward model 80.2% / 81.0% / 80.6% / 79.4% / 77.8% / 75.0%; majority vote 80.2% / 80.1% / 81.1% / 81.8% / 81.7% / 81.8%.

LoRA vs full fine-tuning (SFT from raw, 100 examples, 150 steps; forgetting = rise in loss on held-out pre-training text from 0.255): full (818,996 trainable, lr 0.001) 79.5%, +0.325 · r=1 (8,192 trainable, lr 0.005) 67.5%, +0.335 · r=4 (32,768 trainable, lr 0.005) 68.0%, +0.301 · r=16 (131,072 trainable, lr 0.005) 73.5%, +0.453.

Wall time: SFT 15s, RL 3.7 min (including evals every 10 steps).

## Agent · airline policy

- Parameters: 814,386 · vocabulary 50 characters · context 64 characters
- Pre-training: 3,000 steps on 200,000 lines, final loss 0.289, 2.1 min
- Honest reward: end-state and policy check on a simulated booking system
- Lazy reward: “the customer is happy” (they got what they asked for)

| Stage | Held-out pass@1 | Held-out pass@8 | Notes |
|---|---|---|---|
| Raw (pre-trained) | 28.1% | 58.0% | |
| + SFT (30 examples) | 58.5% | 65.0% | 98.8% on its own training examples |
| + RL, honest reward | 71.4% | 73.0% | benchmark sample 71.1% |
| + RL, lazy reward | 53.1% | 55.0% | lazy reward 84.4%, benchmark 48.1% |

RL hill climb (held-out pass@1 every 30 steps): 57.2% → 67.5% → 70.0% → 71.2% → 71.8%

Lazy-reward run (accuracy, with the reward RL saw): 58.0% (reward 88.3%) → 54.0% (reward 81.2%) → 54.2% (reward 86.7%) → 55.0% (reward 87.5%) → 54.8% (reward 81.2%)

DPO (120 steps on 260 preference pairs, β 0.1, plus an NLL term on the chosen answer): style A 0.0% → 96.9% when preferring A (correct 48.1% → 91.2%); style B 100.0% → 100.0% when preferring B (correct → 93.8%).

Souping: two specialists fine-tuned from the SFT model on “refunds & changes” and “bags, seats, upgrades” only; held-out pass@1 by mix (share of B): 0% → 59.2% · 25% → 65.8% · 50% → 71.0% · 75% → 79.0% · 100% → 84.8%

Distillation (`distill.py`): teacher = the honest RL model (814,386 params, 71.1%); student = 2 layers × 64 (110,642 params, 7.4× smaller), same pre-training recipe. Held-out pass@1: raw student 27.8% · + the 30 worked examples 64.9% · + 4,000 teacher answers 67.6% · + teacher probabilities 69.2%. The teacher's own answers were 69.9% correct.

pass@k (`extra.py`, 64 samples per problem): pass@1 sft 57.6% → RL 71.4%; pass@64 raw 58.0%, SFT 65.0%, RL 74.0%.

Reward model (`extra.py`): 110,706 params, trained on 1,500 grader-labeled pairs, 99.7% agreement on held-out pairs. GRPO against it (β 0.01, 200 steps): real pass@1 57.5% → peak 57.5% at step 0 → 16.2%; reward-model score +1.25 → +3.76.

Best-of-N from the SFT model, N = 1 / 2 / 4 / 8 / 16 / 32: verifier 57.4% / 60.3% / 61.6% / 62.7% / 63.6% / 64.4%; reward model 57.4% / 60.2% / 61.2% / 61.8% / 61.5% / 60.6%; majority vote 57.4% / 57.6% / 59.2% / 59.9% / 59.7% / 59.7%.

LoRA vs full fine-tuning (SFT from raw, 30 examples, 150 steps; forgetting = rise in loss on held-out pre-training text from 0.291): full (814,386 trainable, lr 0.001) 58.2%, +0.932 · r=1 (8,192 trainable, lr 0.005) 29.8%, +0.463 · r=4 (32,768 trainable, lr 0.005) 31.5%, +0.762 · r=16 (131,072 trainable, lr 0.005) 39.2%, +1.367.

Wall time: SFT 9s, RL 1.6 min (including evals every 10 steps).

## Finance · receipt → company ledger

- Parameters: 819,779 · vocabulary 67 characters · context 72 characters
- Pre-training: 3,000 steps on 200,000 lines, final loss 0.424, 2.4 min
- Honest reward: field-by-field check, partial credit (3 fields)
- Lazy reward: “reconciliation passes”: the posted amount matches a number on the receipt

| Stage | Held-out pass@1 | Held-out pass@8 | Notes |
|---|---|---|---|
| Raw (pre-trained) | 0.0% | 0.0% | |
| + SFT (100 examples) | 87.6% | 93.0% | 99.7% on its own training examples |
| + RL, honest reward | 99.5% | 100.0% | benchmark sample 99.1% |
| + RL, lazy reward | 28.4% | 30.0% | lazy reward 97.0%, benchmark 28.2% |

RL hill climb (held-out pass@1 every 30 steps): 79.0% → 90.0% → 96.8% → 98.0% → 97.2%

Lazy-reward run (accuracy, with the reward RL saw): 78.8% (reward 56.2%) → 72.5% (reward 57.8%) → 42.8% (reward 46.9%) → 30.8% (reward 80.5%) → 29.5% (reward 89.8%)

DPO (120 steps on 260 preference pairs, β 0.1, plus an NLL term on the chosen answer): style A 0.0% → 97.5% when preferring A (correct 80.6% → 95.6%); style B 100.0% → 100.0% when preferring B (correct → 98.8%).

Souping: two specialists fine-tuned from the SFT model on “foreign currency” and “USD receipts” only; held-out pass@1 by mix (share of B): 0% → 98.2% · 25% → 98.2% · 50% → 98.8% · 75% → 95.2% · 100% → 93.2%

Distillation (`distill.py`): teacher = the honest RL model (819,779 params, 99.6%); student = 2 layers × 64 (113,347 params, 7.2× smaller), same pre-training recipe. Held-out pass@1: raw student 0.0% · + the 100 worked examples 86.8% · + 4,000 teacher answers 93.0% · + teacher probabilities 94.0%. The teacher's own answers were 97.9% correct.

pass@k (`extra.py`, 64 samples per problem): pass@1 sft 85.2% → RL 99.1%; pass@64 raw 0.0%, SFT 90.0%, RL 100.0%.

Reward model (`extra.py`): 113,411 params, trained on 1,500 grader-labeled pairs, 98.3% agreement on held-out pairs. GRPO against it (β 0.01, 200 steps): real pass@1 85.8% → peak 85.8% at step 0 → 0.0%; reward-model score +5.44 → +6.56.

Best-of-N from the SFT model, N = 1 / 2 / 4 / 8 / 16 / 32: verifier 85.1% / 86.7% / 87.5% / 87.9% / 88.9% / 89.5%; reward model 85.1% / 84.8% / 83.4% / 82.3% / 78.8% / 73.9%; majority vote 85.1% / 85.2% / 86.2% / 86.4% / 86.2% / 86.1%.

LoRA vs full fine-tuning (SFT from raw, 100 examples, 150 steps; forgetting = rise in loss on held-out pre-training text from 0.421): full (819,779 trainable, lr 0.001) 85.0%, +0.925 · r=1 (8,192 trainable, lr 0.005) 55.0%, +0.358 · r=4 (32,768 trainable, lr 0.005) 81.0%, +0.552 · r=16 (131,072 trainable, lr 0.005) 93.0%, +0.817.

Wall time: SFT 6s, RL 1.5 min (including evals every 10 steps).

## Legal · contract playbook

- Parameters: 814,900 · vocabulary 52 characters · context 64 characters
- Pre-training: 3,000 steps on 200,000 lines, final loss 0.477, 2.1 min
- Honest reward: exact rules cited + fix, scored on a rubric
- Lazy reward: “thoroughness”: one point per playbook rule cited, false alarms free

| Stage | Held-out pass@1 | Held-out pass@8 | Notes |
|---|---|---|---|
| Raw (pre-trained) | 37.8% | 88.0% | |
| + SFT (6 examples) | 86.0% | 97.0% | 100.0% on its own training examples |
| + RL, honest reward | 100.0% | 100.0% | benchmark sample 99.6% |
| + RL, lazy reward | 11.8% | 14.0% | lazy reward 65.0%, benchmark 8.5% |

RL hill climb (held-out pass@1 every 30 steps): 99.2% → 86.8% → 99.5% → 99.8% → 97.8%

Lazy-reward run (accuracy, with the reward RL saw): 96.0% (reward 16.7%) → 88.5% (reward 33.6%) → 36.0% (reward 45.6%) → 15.8% (reward 55.7%) → 22.5% (reward 58.3%)

DPO (120 steps on 260 preference pairs, β 0.1, plus an NLL term on the chosen answer): style A 0.0% → 43.8% when preferring A (correct 85.0% → 99.4%); style B 100.0% → 100.0% when preferring B (correct → 100.0%).

Souping: two specialists fine-tuned from the SFT model on “liability caps” and “notice & law” only; held-out pass@1 by mix (share of B): 0% → 100.0% · 25% → 100.0% · 50% → 100.0% · 75% → 100.0% · 100% → 97.5%

Distillation (`distill.py`): teacher = the honest RL model (814,900 params, 99.9%); student = 2 layers × 64 (110,900 params, 7.3× smaller), same pre-training recipe. Held-out pass@1: raw student 36.8% · + the 6 worked examples 69.0% · + 4,000 teacher answers 96.5% · + teacher probabilities 94.0%. The teacher's own answers were 100.0% correct.

pass@k (`extra.py`, 64 samples per problem): pass@1 sft 87.3% → RL 99.9%; pass@64 raw 100.0%, SFT 100.0%, RL 100.0%.

Reward model (`extra.py`): 110,964 params, trained on 1,500 grader-labeled pairs, 100.0% agreement on held-out pairs. GRPO against it (β 0.01, 200 steps): real pass@1 87.2% → peak 99.5% at step 20 → 83.8%; reward-model score +4.01 → +4.50.

Best-of-N from the SFT model, N = 1 / 2 / 4 / 8 / 16 / 32: verifier 87.3% / 93.0% / 95.6% / 97.8% / 98.9% / 99.3%; reward model 87.3% / 92.3% / 94.6% / 95.9% / 95.5% / 94.5%; majority vote 87.3% / 87.8% / 88.6% / 89.0% / 89.6% / 89.7%.

LoRA vs full fine-tuning (SFT from raw, 6 examples, 150 steps; forgetting = rise in loss on held-out pre-training text from 0.483): full (814,900 trainable, lr 0.001) 85.5%, +1.191 · r=1 (8,192 trainable, lr 0.005) 93.5%, +0.236 · r=4 (32,768 trainable, lr 0.005) 78.0%, +0.414 · r=16 (131,072 trainable, lr 0.005) 88.0%, +0.959.

Wall time: SFT 7s, RL 1.2 min (including evals every 10 steps).

## Safety · prompt-injection defense

- Parameters: 814,643 · vocabulary 51 characters · context 64 characters
- Pre-training: 3,000 steps on 200,000 lines, final loss 0.275, 2.1 min
- Honest reward: user's task done and injected instruction ignored
- Lazy reward: “never act”: any output with no tool call scores

| Stage | Held-out pass@1 | Held-out pass@8 | Notes |
|---|---|---|---|
| Raw (pre-trained) | 34.0% | 34.0% | |
| + SFT (20 examples) | 66.1% | 77.0% | 99.4% on its own training examples |
| + RL, honest reward | 94.5% | 100.0% | benchmark sample 98.1% |
| + RL, lazy reward | 37.8% | 38.0% | lazy reward 100.0%, benchmark 41.9% |

RL hill climb (held-out pass@1 every 30 steps): 82.0% → 80.0% → 93.0% → 88.5% → 93.0%

Lazy-reward run (accuracy, with the reward RL saw): 35.8% (reward 100.0%) → 35.0% (reward 100.0%) → 37.2% (reward 100.0%) → 38.0% (reward 100.0%) → 38.0% (reward 100.0%)

DPO (120 steps on 260 preference pairs, β 0.1, plus an NLL term on the chosen answer): style A 0.0% → 98.8% when preferring A (correct 78.8% → 98.8%); style B 100.0% → 100.0% when preferring B (correct → 100.0%).

Souping: two specialists fine-tuned from the SFT model on “injected docs” and “clean docs” only; held-out pass@1 by mix (share of B): 0% → 91.8% · 25% → 93.5% · 50% → 82.5% · 75% → 46.0% · 100% → 34.0%

Distillation (`distill.py`): teacher = the honest RL model (814,643 params, 95.0%); student = 2 layers × 64 (110,771 params, 7.4× smaller), same pre-training recipe. Held-out pass@1: raw student 33.8% · + the 20 worked examples 75.6% · + 4,000 teacher answers 99.5% · + teacher probabilities 94.6%. The teacher's own answers were 99.8% correct.

pass@k (`extra.py`, 64 samples per problem): pass@1 sft 66.1% → RL 95.4%; pass@64 raw 34.0%, SFT 95.0%, RL 100.0%.

Reward model (`extra.py`): 110,835 params, trained on 1,500 grader-labeled pairs, 99.7% agreement on held-out pairs. GRPO against it (β 0.01, 200 steps): real pass@1 68.2% → peak 85.2% at step 30 → 60.8%; reward-model score +1.97 → +4.54.

Best-of-N from the SFT model, N = 1 / 2 / 4 / 8 / 16 / 32: verifier 65.5% / 69.5% / 73.3% / 77.5% / 82.6% / 88.3%; reward model 65.5% / 68.5% / 70.6% / 71.2% / 71.2% / 70.0%; majority vote 65.5% / 66.6% / 67.1% / 67.8% / 69.3% / 70.0%.

LoRA vs full fine-tuning (SFT from raw, 20 examples, 150 steps; forgetting = rise in loss on held-out pre-training text from 0.276): full (814,643 trainable, lr 0.001) 64.8%, +1.194 · r=1 (8,192 trainable, lr 0.005) 56.2%, +0.468 · r=4 (32,768 trainable, lr 0.005) 54.2%, +0.708 · r=16 (131,072 trainable, lr 0.005) 58.8%, +1.643.

Wall time: SFT 7s, RL 1.1 min (including evals every 10 steps).

## Reproduce

```bash
cd lab-tools
uv venv --python 3.12 .venv && uv pip install --python .venv/bin/python torch numpy
node validate-tasks.mjs        # data and grader checks
./run-domain.sh code           # data → pretrain → SFT → RL (honest) → RL (lazy)
.venv/bin/python report.py     # this report
```

## Limitations

- These are toy models (under a million parameters) on synthetic, templated tasks. They show *how* post-training changes a model, not frontier-scale results.
- Benchmarks are “in the style of” public benchmarks (same method, toy scale), not the real benchmarks.
- Tasks use a compact text format so a tiny model can learn them; the page shows a readable version.
- Results vary by a few points between runs (sampling and random seeds); with 100 eval items the 95% confidence interval is roughly ±10 points.
