11"""Unified log reader for local and wandb logs."""
22
3- import logging
43import re
54from abc import ABC , abstractmethod
65from multiprocessing import Pool
98
109import numpy as np
1110import pandas as pd
11+ from loguru import logger
1212from tqdm import tqdm
1313
1414try :
1515 import jsonlines
1616except ModuleNotFoundError :
17- logging .warning (
17+ logger .warning (
1818 "jsonlines module is not installed, local log reading will not work."
1919 )
2020
2121try :
2222 import omegaconf
2323except ModuleNotFoundError :
24- logging .warning ("omegaconf module is not installed, config loading will not work." )
24+ logger .warning ("omegaconf module is not installed, config loading will not work." )
2525
2626try :
2727 import wandb as wandbapi
2828 from tqdm .contrib .logging import logging_redirect_tqdm
2929except ModuleNotFoundError :
30- logging .warning (
30+ logger .warning (
3131 "Wandb module is not installed, make sure to not use wandb for logging "
3232 "or an error will be thrown."
3333 )
@@ -113,16 +113,16 @@ def read(self, path: Union[str, Path]) -> List[Dict[str, Any]]:
113113
114114 values = []
115115 logs_files = list (_path .glob ("logs_rank_*.jsonl" ))
116- logging .info (f"Reading .jsonl files from { _path } " )
117- logging .info (f"\t => { len (logs_files )} ranks detected" )
116+ logger .info (f"Reading .jsonl files from { _path } " )
117+ logger .info (f"\t => { len (logs_files )} ranks detected" )
118118
119119 for log_file in logs_files :
120120 rank = int (log_file .stem .split ("rank_" )[1 ])
121121 for obj in jsonlines .open (log_file ).iter (type = dict , skip_invalid = True ):
122122 obj ["rank" ] = rank
123123 values .append (obj )
124124
125- logging .info (f"\t => total length of logs: { len (values )} " )
125+ logger .info (f"\t => total length of logs: { len (values )} " )
126126 return values
127127
128128 def read_project (
@@ -143,7 +143,6 @@ def read_project(
143143 configs = []
144144 values = []
145145
146- logging .basicConfig (level = logging .INFO )
147146 if logging_redirect_tqdm :
148147 with logging_redirect_tqdm ():
149148 args = [run .parent for run in runs ]
@@ -294,7 +293,7 @@ def read_project(
294293 per_page = per_page ,
295294 include_sweeps = include_sweeps ,
296295 )
297- logging .info (f"Found { len (runs )} runs for project { project } " )
296+ logger .info (f"Found { len (runs )} runs for project { project } " )
298297
299298 if return_summary :
300299 data = []
@@ -368,7 +367,7 @@ def create_table(
368367 Returns:
369368 Formatted table as DataFrame
370369 """
371- logging .info (f"Creating table from { len (configs )} runs." )
370+ logger .info (f"Creating table from { len (configs )} runs." )
372371 filters = filters or {}
373372
374373 df = pd .DataFrame (configs ).T
@@ -381,12 +380,12 @@ def create_table(
381380 v = [v ]
382381 s = df [k ].isin (v )
383382 df = df .loc [s ]
384- logging .info (f"After filtering { k } , { len (df )} runs are left." )
383+ logger .info (f"After filtering { k } , { len (df )} runs are left." )
385384
386385 rows = natural_sort (df [row ].astype (str ).unique ())
387- logging .info (f"Found rows: { rows } " )
386+ logger .info (f"Found rows: { rows } " )
388387 columns = natural_sort (df [column ].astype (str ).unique ())
389- logging .info (f"Found columns: { columns } " )
388+ logger .info (f"Found columns: { columns } " )
390389
391390 output = pd .DataFrame (columns = columns , index = rows )
392391
@@ -395,11 +394,11 @@ def create_table(
395394 cell_runs = (df [row ].astype (str ) == r ) & (df [column ].astype (str ) == c )
396395 n = np .count_nonzero (cell_runs )
397396 samples = []
398- logging .info (f"Number of runs for cell ({ r } , { c } ): { n } " )
397+ logger .info (f"Number of runs for cell ({ r } , { c } ): { n } " )
399398
400399 for id in df [cell_runs ].index .values :
401400 if value not in dfs [id ].columns :
402- logging .info (f"Run { id } missing { value } , skipping...." )
401+ logger .info (f"Run { id } missing { value } , skipping...." )
403402 continue
404403 samples .append (dfs [id ][value ].values .reshape (- 1 ))
405404
0 commit comments