Spaces:
Running on Zero
Running on Zero
Update game/gamemaster.py
Browse files- game/gamemaster.py +6 -2
game/gamemaster.py
CHANGED
|
@@ -25,10 +25,13 @@ import uuid
|
|
| 25 |
|
| 26 |
from game.engine import ALL_CARD_IDS, ALL_PATTERN_IDS, BLESSINGS, MINION_TYPES
|
| 27 |
from game import skills as skillmod
|
|
|
|
| 28 |
|
| 29 |
MODEL_ID = "nvidia/Nemotron-Mini-4B-Instruct"
|
| 30 |
TRACE_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "traces")
|
| 31 |
os.makedirs(TRACE_DIR, exist_ok=True)
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Lazily-initialised globals (loaded once, on first GPU call).
|
| 34 |
_tokenizer = None
|
|
@@ -482,7 +485,8 @@ def _persist(trace: dict):
|
|
| 482 |
rnd = trace.get("round")
|
| 483 |
prefix = f"round_{rnd:03d}" if isinstance(rnd, int) else "skill"
|
| 484 |
path = os.path.join(TRACE_DIR, f"{prefix}_{trace['trace_id']}.json")
|
| 485 |
-
with
|
| 486 |
-
|
|
|
|
| 487 |
except Exception as e: # pragma: no cover
|
| 488 |
print(f"[gamemaster] failed to write trace: {e}")
|
|
|
|
| 25 |
|
| 26 |
from game.engine import ALL_CARD_IDS, ALL_PATTERN_IDS, BLESSINGS, MINION_TYPES
|
| 27 |
from game import skills as skillmod
|
| 28 |
+
from game import trace_store
|
| 29 |
|
| 30 |
MODEL_ID = "nvidia/Nemotron-Mini-4B-Instruct"
|
| 31 |
TRACE_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "traces")
|
| 32 |
os.makedirs(TRACE_DIR, exist_ok=True)
|
| 33 |
+
# Background sync of every trace file to a HF dataset repo (no-op if not configured).
|
| 34 |
+
trace_store.start(TRACE_DIR)
|
| 35 |
|
| 36 |
# Lazily-initialised globals (loaded once, on first GPU call).
|
| 37 |
_tokenizer = None
|
|
|
|
| 485 |
rnd = trace.get("round")
|
| 486 |
prefix = f"round_{rnd:03d}" if isinstance(rnd, int) else "skill"
|
| 487 |
path = os.path.join(TRACE_DIR, f"{prefix}_{trace['trace_id']}.json")
|
| 488 |
+
with trace_store.lock():
|
| 489 |
+
with open(path, "w", encoding="utf-8") as f:
|
| 490 |
+
json.dump(trace, f, indent=2)
|
| 491 |
except Exception as e: # pragma: no cover
|
| 492 |
print(f"[gamemaster] failed to write trace: {e}")
|