# OPAL lets a coding agent rewrite a PyTorch optimizer while the model trains

> OPAL is a PyTorch optimizer wrapper that lets a coding agent, Claude Code by default, change the update rules, learning rates and schedules of a training run while it runs.

- Project: opal by xingjian-bai
- List: Built for AI
- Kind: library
- Works with: Claude Code, Codex, Cursor
- Noticed: 485 GitHub stars (when we found it)
- Added: 2026-11-25T14:15:36+00:00
- Web page: https://ai-news.ikangai.com/built/opal/

The README describes OPAL as a wrapper around an existing PyTorch optimizer. Wrapping takes one line. Every so often, Claude Code reads the run's losses and gradient statistics and may rewrite two programs: the optimizer update and an analysis program. The author says the agent is asked not to touch the model, data, loss, batch size or evaluation. The README also says the agent's programs run inside the training process, so this is a rule rather than a sandbox. Until the agent changes something, the README says the wrapped run is bit-for-bit the same as the plain one.

The README reports one run per setting. On SiT-B/2 at ImageNet 256, FID-50K went from 35.7 with the official recipe to 23.6. On modded-nanogpt record #36, validation loss went from 3.2781 to 3.2749. The README also reports a run that ended at 3.2878, worse than the record. The waiting is a real cost. The author says an agent decision takes about 40 s on average, which came to 1.05 h of an 11.2 h SiT-B/2 run. In short runs, it dominates.

Setup needs Python 3.10 or newer and PyTorch 2.5 or newer, plus Claude Code logged in on the rank-0 machine for agent runs. A dry run with backend set to keep needs no agent and makes no model calls. Codex is an experimental backend. The package installs from PyPI as opal-optimizer and imports as opal, and it is MIT licensed. The README lists limits: multi-node, FSDP and DeepSpeed are unsupported, and the agent cannot roll back training.

## In the author's words

> A PyTorch optimizer wrapper that lets a coding agent change the optimizer while your model trains.

## When to reach for it

Someone with a long training run could use it to test whether agent-tuned optimizer changes beat a fixed recipe. Running opal estimate first shows the waiting time and cost before launch. The README's own results mix gains with one loss, so this is a measured experiment rather than a drop-in speedup.

## See it

- [opal](https://github.com/xingjian-bai/opal)
- [Website](https://xingjianbai.com/reactive-optimizers/)

---

AI wrote this entry from the project's own README or its author's post. What the project does, and that AI built it where the entry says so, are the author's statements, quoted here. Nobody at IKANGAI ran or tested it.
