malkhut(e2e): memory-efficient + crash-safe 3h run
Rolling stats (no episode accumulation), CMA-ES every 10 cycles (3 evals), gc.collect() after CMA, global try/except for crash safety. 100-opponent swarm, 9 assets, 270 scenarios.
This commit is contained in:
@@ -385,19 +385,22 @@ def main():
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
# Phase 2: CMA-ES every 5 cycles
|
# Phase 2: CMA-ES every 10 cycles (memory-heavy — keep infrequent)
|
||||||
if cycle % 5 == 0 and remaining > 600 and recent_episodes >= 20:
|
if cycle % 10 == 0 and remaining > 600 and recent_episodes >= 20:
|
||||||
phase = f"CYCLE {cycle} — CMA-ES"
|
phase = f"CYCLE {cycle} — CMA-ES"
|
||||||
cma_scenarios = rng.sample(all_scenarios, min(5, len(all_scenarios)))
|
cma_scenarios = rng.sample(all_scenarios, min(3, len(all_scenarios)))
|
||||||
try:
|
try:
|
||||||
best = run_cma_cycle(
|
best = run_cma_cycle(
|
||||||
cwm_factory, cma_scenarios, params, codec, pool,
|
cwm_factory, cma_scenarios, params, codec, pool,
|
||||||
n_evals=3,
|
n_evals=2,
|
||||||
seed=SEED + cycle * 100,
|
seed=SEED + cycle * 100,
|
||||||
)
|
)
|
||||||
cma_bests.append(best)
|
cma_bests.append(best)
|
||||||
if best.score > params.w_expected_pnl * 10:
|
if best.score > params.w_expected_pnl * 10:
|
||||||
params = best.params
|
params = best.params
|
||||||
|
# Explicitly free CMA-ES state
|
||||||
|
del best
|
||||||
|
import gc; gc.collect()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" CMA-ES error (cycle {cycle}): {e}", flush=True)
|
print(f" CMA-ES error (cycle {cycle}): {e}", flush=True)
|
||||||
|
|
||||||
@@ -496,4 +499,10 @@ def _baseline():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
try:
|
||||||
|
main()
|
||||||
|
except Exception as e:
|
||||||
|
import traceback
|
||||||
|
print(f"\nFATAL ERROR: {e}")
|
||||||
|
traceback.print_exc()
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user