# Reactive Optimizers — OPAL (OPtimizer with an Agent in the Loop)

- **ID:** 1431
- **Kind:** post
- **URL:** https://xingjianbai.com/reactive-optimizers/
- **Authors:** Xingjian Bai, Jia-Hao Liang, Jayden Teoh, Vincent Sitzmann — MIT EECS (Bai is a PhD student working with Phillip Isola and Vincent Sitzmann, previously RA at Oxford VGG)
- **Venue:** author's blog (no paper — no arXiv/OpenReview version exists; the citation block in both blog and repo is @misc, note "Blog post")
- **Source:** blog
- **Language:** en
- **Access:** free
- **Added:** 2026-10-21
- **Verified:** 2026-10-21
- **Page:** https://papers.projxon.ai/entries/1431

## Summary

Thesis: optimizers are static — hand-crafted or discovered offline, then run unchanged. A reactive optimizer instead puts a zero-shot LLM agent (Claude Opus 5.5 in all blog experiments; nothing learned or retained across runs) inside a single training run and gives it code as the entire interface. The agent iteratively rewrites two programs: `updater.py`, the optimizer itself, executed every step — the whole algorithm is up for rewriting, not just hyperparameters — and `analysis.py`, self-written probes that extract the training-dynamics statistics the agent chooses to watch (per-parameter-group gradient norms, update size relative to weights, cosine between consecutive gradients, per-tensor spike detection). One agent conversation spans the run, so it remembers what it tried and why. In the released package, checks run every 50 steps, decisions are capped (default ≤50, front-loaded into the first 5% of the run), and the agent's remit is bounded: it cannot touch model, data, loss, batch size, step count, or evaluation, and until its first edit the wrapped run is bit-for-bit identical to the plain run. Guardrails in the package: a new updater takes over on all ranks at once and runs a 20-step trial — an error reverts to the previous program; a first-step failure is undone exactly when a snapshot of parameters + optimizer state fits in `snapshot_limit_gb` (default 2 GB); a later failure is NOT undone and the agent is only told; an `eval_integrity` check flags a program that moves parameters away for an evaluation and back. Training can run asynchronously while the agent thinks (blocking=False), edits landing a median of 65 updates later on Goldfish. Headline claim (authors'): where no recipe has been tuned for the setting, OPAL — always INITIALIZED from an existing recipe — matches or beats the best recipe one could pick off the shelf one-shot. Baselines, precisely: for settings derived from modded-nanogpt Track 3 (162M GPT on FineWeb), five leaderboard records transplanted with natural adjustments (#46, #30, #21 Shampoo, #36 tuned Muon, #2 AdamW; at quarter batch, all LRs ×¼) — OPAL initialized from #36 ranked first in every new setting (quarter batch; Chinese, Thai, Kyrgyz from 1 GB Goldfish sets; Chinese/Thai bars are means of 3 runs). Goldfish Amharic (125M GPT, 1 GB, 10 epochs; metric bits/sentence on held-out FLORES-200): official recipe 83.48 → OPAL from that recipe 81.11; an LR sweep found a static recipe at 80.89 — ahead of OPAL-from-official — but OPAL initialized from the swept recipe ended ahead again at 80.73 (Swahili similar: 79.37 → 77.60). Image generation: LightningDiT-XL/1 on ImageNet, FID-50K 1.83 vs official recipe's 2.18 with guidance (4.33 vs 5.15 without); RAEv2-B (official recipe already a Muon variant, GMuon) 3.19 vs 3.39 in the blog — the repo table shows prompt sensitivity: 3.10 with an efficiency-asking prompt, 3.46 with the neutral prompt. SiT-B/2 (repo table): FID-50K 35.7 → 23.6. On the original, heavily tuned modded-nanogpt setting the gain is small (validation loss 3.2749 vs record #36's 3.2781), and the README documents a run that ended WORSE (3.2878 on OPAL 0.2.0). What the agent actually does, from the decision logs: builds intricate per-parameter-group multi-stage LR schedules (including mid-run LR increases; A/B/A tests alternating two LRs for a few hundred updates each and keeping the winner; re-planned earlier cooldowns from loss trends); migrates tensors from AdamW to Muon module-by-module (attention/MLP first, then adaLN split into chunks, timestep embedder last); on modded-nanogpt it measured that token-embedding entries are ~15 in size where adjacent bf16 values are 0.0625 apart, so as the LR decayed, rounding would discard a growing share of each update — from update 1,040 it kept that one matrix's Adam moments in float32 with compensated rounding on writeback and left everything else alone. Loss-spike defense: in a SiT run it traced 17 of 18 logged gradient spikes to the timestep embedder and wrote per-tensor clipping thresholds set from each tensor's own recent gradient norm (global threshold kept as backstop); in a controlled ResNet-18/CIFAR-10 experiment with four inserted stretches of random images and labels (agent not told), the first two stretches cost it −50.0 and −66.3 accuracy points (≈ the static baselines), but between stretches it added loss damping, replaced it with clipping, then wrote a gate that holds back batches whose loss is far above recent clean ones — the third stretch cost −12.1 and the fourth +0.7, while Muon+clip, AdamW+clip and Stable-SPAM still lost 28.5–76 points per stretch. Overfitting: ResNet-18 on CIFAR-10 with 10% wrong labels, no augmentation, agent sees train + dev metrics but is never told about the label noise — AdamW ends at test loss 2.49 / 73.5% accuracy (early-stopped 1.01 / 72.9%; weight-averaged 0.83 / 77.5%) and predicts the wrong trained label on 100% of the 4,500 mislabeled training images; OPAL ends at 0.69 / 78.6%, predicts the wrong label on only 4% (true label on 78%), via progressively higher learning rates plus a self-chosen weight average ("extended SWA") selected on the dev set. Toy control check (2D landscapes, OPAL restricted to heavy-ball with momentum resets/return-to-best): mean log10(f − f*) −11.6 vs −2.2 for the best of 12 common static recipes and −7.4 for the best of 382,080 swept recipes. Cost: ≈100 decisions on LightningDiT cost $6.42 at Opus 5.5 list price on top of ~74 H100-hours (~$510 AWS on-demand); asynchronous mode adds 1.01–1.14× wall-clock vs the static run (blocking at every decision: 1.30–4.39×). Authors' stated limits: gains shrink when a run is short AND its recipe is already fine-tuned (the two conditions coincide in the original modded-nanogpt setting; other settings train 8–120× more updates); reactive behavior is another source of nondeterminism and makes training less reproducible; most experiments run once, a few three times; the current implementation does not support sharded training or optimizer compilation. Repo README adds: v0.3.4, single GPU / single-node DDP only (no multi-node, FSDP, DeepSpeed); "the agent can make a run worse: it cannot restart or roll back training, it can only fix its programs at the next decision"; results vary run to run because the agent chooses differently. Repo ships a one-line `opal.wrap()` wrapper around any torch.optim optimizer, `opal doctor` / `opal estimate` / `opal show` / `opal report` tooling, examples, a CPU test suite, and an experimental Codex backend (gpt-6.1-sol); 34 stars, created the day of the thread.

## Research notes

- Discovery: Hudson shared @SimulatedAnneal's launch thread 2026-10-21. Claim hygiene: every number is first-party; most runs are single-seed (authors say so); "best one-shot recipe" means best off-the-shelf pick WITHOUT a sweep — on Goldfish a swept static recipe beat OPAL-from-the-official-recipe, and OPAL's win required starting from the swept point; OPAL always starts from an existing recipe, it does not replace having one. Baseline comparisons are labeled per setting above; note the RAEv2 prompt sensitivity (3.10 efficiency prompt vs 3.46 neutral) as an agent-variance warning. Relevance: (1) Optimizer cluster — queue #66 (Muon formula grid) searches optimizer variants OFFLINE and statically; #36 (Martin α=2), #68 (batch-size schedules), #102 (LR-schedule risk theory) all treat the recipe as fixed before the run; #74 OperLoop reframes the loop transition as an optimizer update. OPAL is the online, agent-driven extreme of the same direction: the optimizer as a program rewritten during the run. (2) Launch Helm: a reactive optimizer is an automated intervene-er sitting exactly on Helm's monitoring + control surface — and its risk surface is the product question: an agent with write access to the update rule mid-run needs precisely the sandboxing, trial windows, snapshot/rollback and audit trail the OPAL package bolts on (20-step trials, snapshot limits, eval-integrity flag, full program history); the failure mode it cannot fix — a bad edit discovered late is not rolled back — is the honest boundary. (3) Agents-doing-ML-research thread: #44 (Bespoke/Nemotron autonomous ML researcher), #105 (Mirendil's agent-written pretraining codebase) — OPAL narrows the same bet to the optimizer, the one component those systems still leave static. For Hudson's own stack: the bf16-moments episode is a concrete, checkable instance of the precision thread (#59/#66/#98-PULSE: bf16 rounding as a training variable) — an agent caught an update-rounding failure a static recipe would have shipped.
- License: code MIT (verified, LICENSE file present); blog text: no reuse license stated — flag at insert

## Similar entries

- [Loop Engineering: The 20-Step Roadmap From Prompter to Loop Designer](https://papers.projxon.ai/entries/647) (thread, #647)
- [Agent Memory Repo (Cognition) — open spec for persistent agent memory](https://papers.projxon.ai/entries/1269) (code, #1269)
- [One Model to Loop Them All: Elastic Latent Recurrence for Language Models](https://papers.projxon.ai/entries/1346) (paper, #1346)
- [Mixture of Self-Improving Branches For Agent Harness Optimization](https://papers.projxon.ai/entries/1193) (paper, #1193)
- [Truncate or Not? A Scaling Study of Looped Transformers with Truncated Backpropagation](https://papers.projxon.ai/entries/1434) (paper, #1434)
- [Scaling Verifiable Environments for Long-horizon Work Agents](https://papers.projxon.ai/entries/1289) (paper, #1289)
