feat(PPO_Bot): persist Adam optimizer state and round counter across restarts (#35)

Save ACAdamStates (m/v tensors + t counters) as .npy files alongside
network weights in latest/ and checkpoint dirs; save round counter to
round_counter.txt. loadBestAvailable restores both on startup; fresh
start works unchanged when files are absent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-08-18 15:40:54 +02:00
parent cdde60d79f
commit 0b17430735
4 changed files with 118 additions and 19 deletions
+7 -3
View File
@@ -4,6 +4,7 @@
import std/[os, math]
import arraymancer
import "../network"
import "../training"
import "../weights"
template check(cond: bool, msg: string) =
@@ -67,18 +68,21 @@ block testLoadBest:
# Try with no weights — should return false
var acEmpty = initActorCritic()
check not loadBestAvailable(acEmpty, root), "should return false with no weights"
var adamEmpty: ACAdamStates
check not loadBestAvailable(acEmpty, adamEmpty, root).loaded, "should return false with no weights"
# Save to latest/; should load
saveWeights(ac0, root / "latest")
var ac1 = initActorCritic()
check loadBestAvailable(ac1, root), "should load from latest/"
var adam1: ACAdamStates
check loadBestAvailable(ac1, adam1, root).loaded, "should load from latest/"
# Remove latest/, save to checkpoint_1/ — should fall back
removeDir(root / "latest")
saveWeights(ac0, root / "checkpoint_1")
var ac2 = initActorCritic()
check loadBestAvailable(ac2, root), "should load from checkpoint_1/"
var adam2: ACAdamStates
check loadBestAvailable(ac2, adam2, root).loaded, "should load from checkpoint_1/"
removeDir(root)