Skip to content

Commit a0adf83

Browse files
Fix missing logs when calling oneshot (#1446)
Fix missing logs when calling oneshot #1441 Summary: When calling oneshot (e.g., in gemma2_example.py), a sparse_logs folder is created, but the log file inside is nearly empty. This is because the logging setup in lifecycle.py and state.py uses loguru, but oneshot itself didn’t configure loguru to write logs to a file. As a result, logs were not being saved properly. This PR fixes the issue by adding a log file configuration directly in the oneshot init. This ensures loguru writes to the appropriate file by default. To clean up the nearly empty log file, I removed the two lines from stage.py that were generating it. These messages appear to be redundant, as similar info is already captured by loguru. Currently, I set the log path defaults to sparse_logs. Maybe we can consider making the log file path an optional input, allowing users to disable file logging by passing None. Let me know what you guys think. Test Plan: Ran gemma2_example.py after the changes: A proper log file was generated in sparse_logs The original nearly empty log file was no longer created Also ran make test and got the same results as the current main. --------- Signed-off-by: Kelvin Cheng <kelvincheng216@gmail.com> Co-authored-by: Kyle Sayers <kylesayrs@gmail.com>
1 parent ba5bb26 commit a0adf83

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/llmcompressor/entrypoints/oneshot.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import os
2+
from datetime import datetime
13
from typing import Optional
24

5+
from loguru import logger
36
from torch.utils.data import DataLoader
47
from transformers import PreTrainedModel
58

@@ -82,6 +85,7 @@ class Oneshot:
8285

8386
def __init__(
8487
self,
88+
log_dir: Optional[str] = "sparse_logs",
8589
**kwargs,
8690
):
8791
"""
@@ -100,6 +104,15 @@ def __init__(
100104
:param output_dir: Path to save the output model after carrying out oneshot
101105
102106
"""
107+
# Set up logging
108+
if log_dir:
109+
os.makedirs(log_dir, exist_ok=True)
110+
date_str = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
111+
logger.add(
112+
f"{log_dir}/oneshot_{date_str}.log",
113+
level="DEBUG",
114+
)
115+
103116
model_args, dataset_args, recipe_args, _, output_dir = parse_args(**kwargs)
104117

105118
self.model_args = model_args

src/llmcompressor/modifiers/stage.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def initialize(self, state: "State", **kwargs):
6767
modifier.initialize(state, **kwargs)
6868
if accelerator:
6969
accelerator.wait_for_everyone()
70-
state.loggers.system.info(tag="stage", string="Modifiers initialized")
7170

7271
def finalize(self, state: "State", **kwargs):
7372
"""
@@ -88,7 +87,6 @@ def finalize(self, state: "State", **kwargs):
8887
accelerator.wait_for_everyone()
8988

9089
self.applied = True
91-
state.loggers.system.info(tag="stage", string="Modifiers finalized")
9290

9391
def update_event(self, state: "State", event: "Event", **kwargs):
9492
"""

0 commit comments

Comments
 (0)