File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments