Quazim0t0 commited on
Commit
7f5d4f2
·
verified ·
1 Parent(s): a08410f

Update game/gamemaster.py

Browse files
Files changed (1) hide show
  1. 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 open(path, "w", encoding="utf-8") as f:
486
- json.dump(trace, f, indent=2)
 
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}")