Skip to content

Commit 08e856c

Browse files
Chamberlain0w0kilinchange
authored andcommitted
fix: add compare utils
1 parent 15bfad1 commit 08e856c

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

scripts/compare_utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from pathlib import Path
2+
import sys
3+
4+
5+
def collect_log_files(base_dir: Path):
6+
"""Collect comparable training logs keyed by basename."""
7+
files = {}
8+
duplicates = {}
9+
10+
for path in base_dir.rglob("*.log"):
11+
if path.name.startswith("build") or path.name.endswith("_profile.log"):
12+
continue
13+
14+
key = path.name
15+
if key in files:
16+
duplicates.setdefault(key, [files[key]]).append(path)
17+
continue
18+
files[key] = path
19+
20+
return files, duplicates
21+
22+
23+
def exit_if_duplicate_logs(base_dir: Path, duplicates):
24+
"""Abort when duplicate basenames make comparison ambiguous."""
25+
if not duplicates:
26+
return
27+
28+
print(f"Found duplicate log basenames in {base_dir.resolve()}, cannot compare safely:")
29+
for name, paths in sorted(duplicates.items()):
30+
print(f" {name}: {', '.join(str(p.relative_to(base_dir)) for p in paths)}")
31+
sys.exit(1)

0 commit comments

Comments
 (0)