(logs: Path)
| 15 | |
| 16 | |
| 17 | def main(logs: Path): |
| 18 | model_to_arena_to_return_codes = {} |
| 19 | if not DATA_CACHE.exists(): |
| 20 | tournaments = [x.parent for x in logs.rglob("metadata.json")] |
| 21 | for game_log_folder in tqdm(tournaments): |
| 22 | arena = game_log_folder.name.split(".", 2)[1] |
| 23 | with open(game_log_folder / "metadata.json") as f: |
| 24 | metadata = json.load(f) |
| 25 | try: |
| 26 | p2m = { |
| 27 | x["name"]: x["config"]["model"]["model_name"].strip("@").split("/")[-1] |
| 28 | for x in metadata["config"]["players"] |
| 29 | } |
| 30 | for model in p2m.values(): |
| 31 | if model not in model_to_arena_to_return_codes: |
| 32 | model_to_arena_to_return_codes[model] = {} |
| 33 | if arena not in model_to_arena_to_return_codes[model]: |
| 34 | model_to_arena_to_return_codes[model][arena] = {"actions": 0, "malformed": 0} |
| 35 | except KeyError: |
| 36 | continue |
| 37 | |
| 38 | for name in p2m.keys(): |
| 39 | traj_files = (game_log_folder / "players" / name).rglob("*.traj.json") |
| 40 | for traj_file in traj_files: |
| 41 | with open(traj_file) as f: |
| 42 | traj = json.load(f) |
| 43 | msgs = traj["messages"][2:] # Skip system prompt and first user message |
| 44 | observations = [msg for msg in msgs if msg["role"] == "user"] |
| 45 | actions = len(observations) |
| 46 | malformed = 0 |
| 47 | for obs in observations: |
| 48 | if isinstance(obs["content"], str): |
| 49 | malformed += "<returncode>0</returncode>" not in obs["content"] |
| 50 | elif isinstance(obs["content"], list): |
| 51 | malformed += "<returncode>0</returncode>" not in obs["content"][0]["text"] |
| 52 | else: |
| 53 | print(f"Unknown content type: {type(obs['content'])}") |
| 54 | model_to_arena_to_return_codes[p2m[name]][arena]["actions"] += actions |
| 55 | model_to_arena_to_return_codes[p2m[name]][arena]["malformed"] += malformed |
| 56 | |
| 57 | with open(DATA_CACHE, "w") as f: |
| 58 | json.dump(model_to_arena_to_return_codes, f, indent=2) |
| 59 | |
| 60 | with open(DATA_CACHE) as f: |
| 61 | model_to_arena_to_return_codes = json.load(f) |
| 62 | |
| 63 | model_to_return_code = defaultdict(tuple) |
| 64 | for model, arena_to_return_codes in model_to_arena_to_return_codes.items(): |
| 65 | a, m = 0, 0 |
| 66 | for arena, data in arena_to_return_codes.items(): |
| 67 | malform_rate = data["malformed"] / data["actions"] * 100 |
| 68 | a += data["actions"] |
| 69 | m += data["malformed"] |
| 70 | print( |
| 71 | f"- {model} in {arena}: {data['actions']} actions; {data['malformed']} malformed ({malform_rate:.2f}%)" |
| 72 | ) |
| 73 | model_to_return_code[model] = (m, a, m / a * 100) |
| 74 | print("=" * 20) |
no test coverage detected