Persist Adam optimizer state and round counter across restarts #35

Closed
opened 2026-08-17 19:49:02 +02:00 by SirStone · 1 comment
Owner

Parent: #29

Question

PPO_Bot currently loses Adam optimizer momentum (m, v, t vectors) and round counter on crash/restart. This means:

  • Optimizer restarts cold after every crash — training slows until momentum rebuilds
  • Round counter resets to 0 — stats lose continuity

Fix: Save Adam state (ACAdamStates) alongside network weights in weights/latest/ and checkpoint dirs. Save round counter to a simple file. Load both in loadBestAvailable.

Independent of other tickets — improves crash recovery quality regardless of runner design.

Parent: #29 ## Question PPO_Bot currently loses Adam optimizer momentum (m, v, t vectors) and round counter on crash/restart. This means: - Optimizer restarts cold after every crash — training slows until momentum rebuilds - Round counter resets to 0 — stats lose continuity **Fix:** Save Adam state (`ACAdamStates`) alongside network weights in `weights/latest/` and checkpoint dirs. Save round counter to a simple file. Load both in `loadBestAvailable`. **Independent of other tickets** — improves crash recovery quality regardless of runner design.
SirStone added the wayfinder:task label 2026-08-17 19:49:02 +02:00
Author
Owner

Resolved in commit 0b17430 on branch research/goto-controller.

What was done:

  • Exported AdamState type and its m, v, t fields, plus all ACAdamStates fields, from training.nim so weights.nim can access them.
  • Added saveAdamStates / loadAdamStates procs in weights.nim: each Adam state's m and v tensors are written as .npy files (same format as weights), t counters go to adam_t.txt (one int per line).
  • Updated saveCheckpoint signature to (ac, adam, weightsRoot, roundNum) — saves Adam state alongside weights in latest/ and checkpoint dirs; writes round_counter.txt to weightsRoot/.
  • Updated loadBestAvailable signature to (ac, adam, weightsRoot) → (loaded, roundNum) — loads Adam state if files are present, cold-starts if absent (backward compatible).
  • Updated PPO_Bot.nim call sites accordingly; roundCounter is now seeded from the persisted value on startup.
  • All existing tests pass; no new dependencies added.
Resolved in commit `0b17430` on branch `research/goto-controller`. **What was done:** - Exported `AdamState` type and its `m`, `v`, `t` fields, plus all `ACAdamStates` fields, from `training.nim` so `weights.nim` can access them. - Added `saveAdamStates` / `loadAdamStates` procs in `weights.nim`: each Adam state's `m` and `v` tensors are written as `.npy` files (same format as weights), `t` counters go to `adam_t.txt` (one int per line). - Updated `saveCheckpoint` signature to `(ac, adam, weightsRoot, roundNum)` — saves Adam state alongside weights in `latest/` and checkpoint dirs; writes `round_counter.txt` to `weightsRoot/`. - Updated `loadBestAvailable` signature to `(ac, adam, weightsRoot) → (loaded, roundNum)` — loads Adam state if files are present, cold-starts if absent (backward compatible). - Updated `PPO_Bot.nim` call sites accordingly; `roundCounter` is now seeded from the persisted value on startup. - All existing tests pass; no new dependencies added.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SirStone/SirRoboGarage#35