Spaces:
Running
Running
Upload ai/overnight_evolution.py with huggingface_hub
Browse files- ai/overnight_evolution.py +58 -0
ai/overnight_evolution.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def run_step(name, cmd):
|
| 7 |
+
print(f"\n>>> Starting {name}...")
|
| 8 |
+
start = time.time()
|
| 9 |
+
try:
|
| 10 |
+
subprocess.check_call(cmd, shell=True)
|
| 11 |
+
print(f">>> {name} completed in {time.time() - start:.1f}s")
|
| 12 |
+
except subprocess.CalledProcessError as e:
|
| 13 |
+
print(f"!!! Error in {name}: {e}")
|
| 14 |
+
return False
|
| 15 |
+
return True
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def main():
|
| 19 |
+
print("=== LOVE-CA ALPHA ZERO OVERNIGHT EVOLUTION ===")
|
| 20 |
+
|
| 21 |
+
# 1. Ensure model is exported
|
| 22 |
+
if not os.path.exists("ai/models/alphanet.onnx"):
|
| 23 |
+
run_step("Model Export", "uv run python ai/utils/export_onnx.py")
|
| 24 |
+
|
| 25 |
+
generation = 0
|
| 26 |
+
while True:
|
| 27 |
+
print(f"\n--- GENERATION {generation} ---")
|
| 28 |
+
|
| 29 |
+
# 1. Generate Data (Self-Play)
|
| 30 |
+
# Using 800 sims for high quality, 1000 games per batch
|
| 31 |
+
if not run_step(
|
| 32 |
+
"Data Generation",
|
| 33 |
+
"uv run python ai/data_generation/generate_data.py --num-games 1000 --sims 800 --output-file ai/data/overnight_batch.npz",
|
| 34 |
+
):
|
| 35 |
+
break
|
| 36 |
+
|
| 37 |
+
# 2. Train Model
|
| 38 |
+
# Training for a few epochs on the new data
|
| 39 |
+
if not run_step(
|
| 40 |
+
"Model Training", "uv run python ai/training/train.py --data-path ai/data/overnight_batch.npz --epochs 5"
|
| 41 |
+
):
|
| 42 |
+
break
|
| 43 |
+
|
| 44 |
+
# 3. Export New Model
|
| 45 |
+
run_step("Model Update", "uv run python ai/utils/export_onnx.py")
|
| 46 |
+
|
| 47 |
+
# 4. Evaluation (Optional, simple score)
|
| 48 |
+
print(f"Generation {generation} completed.")
|
| 49 |
+
|
| 50 |
+
generation += 1
|
| 51 |
+
|
| 52 |
+
# Limit or break? User said overnight, so loop forever until stopped.
|
| 53 |
+
# But maybe sleep a bit to avoid CPU melt
|
| 54 |
+
time.sleep(10)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
main()
|