Deep CFR 콘솔 트래킹 출력 정리

This commit is contained in:
2026-05-07 01:47:54 +09:00
parent 1420ab76bd
commit 1645d22e87
3 changed files with 28 additions and 8 deletions
@@ -87,9 +87,7 @@ def train_command(args: argparse.Namespace) -> None:
)
if args.resume:
trainer.load_checkpoint(args.resume)
metrics = trainer.train()
for item in metrics:
print(json.dumps(item.to_dict(), sort_keys=True))
trainer.train()
def eval_command(args: argparse.Namespace) -> None:
@@ -3,6 +3,7 @@ from __future__ import annotations
import json
from datetime import datetime
from pathlib import Path
from sys import stdout
from typing import Any, Protocol
@@ -49,6 +50,17 @@ class CompositeRunTracker:
tracker.close()
class ConsoleRunTracker:
def log_event(self, message: str) -> None:
print(f"{log_timestamp()} {message}", file=stdout, flush=True)
def log_metrics(self, metrics: dict[str, Any], *, step: int) -> None:
pass
def close(self) -> None:
pass
class FileRunTracker:
def __init__(
self,
@@ -20,7 +20,12 @@ from coolrl_lost_cities.games.classic.deep_cfr.encoding import input_dim
from coolrl_lost_cities.games.classic.deep_cfr.evaluate import evaluate_strategy_network
from coolrl_lost_cities.games.classic.deep_cfr.memory import ReservoirMemory, TrainingSample
from coolrl_lost_cities.games.classic.deep_cfr.networks import DeepCFRMLP
from coolrl_lost_cities.games.classic.deep_cfr.tracking import FileRunTracker, RunTracker
from coolrl_lost_cities.games.classic.deep_cfr.tracking import (
CompositeRunTracker,
ConsoleRunTracker,
FileRunTracker,
RunTracker,
)
from coolrl_lost_cities.games.classic.deep_cfr.traverser import DeepCFRTraverser, TraversalStats
from coolrl_lost_cities.games.classic.deep_cfr.workers import (
TraversalWorkerBatch,
@@ -150,10 +155,15 @@ class DeepCFRTrainer:
self.metrics_path = self.run_dir / "metrics.jsonl"
self.progress_path = self.run_dir / "runtime_progress.json"
self.log_path = self.run_dir / "train.log"
self.tracker = tracker or FileRunTracker(
log_path=self.log_path,
metrics_path=self.metrics_path,
progress_path=self.progress_path,
self.tracker = tracker or CompositeRunTracker(
[
FileRunTracker(
log_path=self.log_path,
metrics_path=self.metrics_path,
progress_path=self.progress_path,
),
ConsoleRunTracker(),
]
)
self.self_play_league_snapshots: list[list[dict]] = []