Skip to content

Commit 95b3153

Browse files
[BugFix] loguru coverage
1 parent 4614a3d commit 95b3153

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

stable_pretraining/utils/distributed.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111

1212
import functools
13-
import logging
1413
import os
1514
import random
1615
import warnings
@@ -19,8 +18,7 @@
1918
import torch
2019
import torch.distributed as dist
2120
import torch.distributed.nn
22-
23-
log = logging.getLogger(__name__)
21+
from loguru import logger
2422

2523
# Same precedence Lightning uses (see ``lightning.fabric.utilities.rank_zero``):
2624
# LOCAL_RANK before SLURM_PROCID because SLURM_PROCID can be set even when SLURM
@@ -116,10 +114,9 @@ def rank_zero_warn(message: Union[str, Warning], stacklevel: int = 4, **kwargs)
116114

117115

118116
@rank_zero_only
119-
def rank_zero_info(*args, stacklevel: int = 4, **kwargs) -> None:
117+
def rank_zero_info(message, *args, **kwargs) -> None:
120118
"""Emit an info-level log message only on global rank 0."""
121-
kwargs["stacklevel"] = stacklevel
122-
log.info(*args, **kwargs)
119+
logger.info(message, *args, **kwargs)
123120

124121

125122
class _DummyExperiment:
@@ -217,7 +214,7 @@ def seed_everything(
217214
)
218215

219216
if verbose:
220-
log.info(f"Seed set to {seed}")
217+
logger.info(f"Seed set to {seed}")
221218

222219
os.environ["PL_GLOBAL_SEED"] = str(seed)
223220
random.seed(seed)

stable_pretraining/utils/log_reader.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Unified log reader for local and wandb logs."""
22

3-
import logging
43
import re
54
from abc import ABC, abstractmethod
65
from multiprocessing import Pool
@@ -9,25 +8,26 @@
98

109
import numpy as np
1110
import pandas as pd
11+
from loguru import logger
1212
from tqdm import tqdm
1313

1414
try:
1515
import jsonlines
1616
except ModuleNotFoundError:
17-
logging.warning(
17+
logger.warning(
1818
"jsonlines module is not installed, local log reading will not work."
1919
)
2020

2121
try:
2222
import omegaconf
2323
except 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

2626
try:
2727
import wandb as wandbapi
2828
from tqdm.contrib.logging import logging_redirect_tqdm
2929
except 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

Comments
 (0)