Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Handlers being unnecessarily created for logger #1483

Merged
merged 8 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sparseml/pytorch/optim/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def initialize_loggers(self, loggers: Union[None, LoggerManager, List[BaseLogger
super().initialize_loggers(loggers)

for mod in self.iter_modifiers():
mod.initialize_loggers(loggers)
mod.initialize_loggers(self.loggers)

def modify(
self,
Expand Down
45 changes: 26 additions & 19 deletions src/sparseml/pytorch/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,26 +357,33 @@ def _create_default_logger(self, log_level: Optional[int] = None) -> logging.Log
logger = logging.getLogger(__name__)

# File handler setup, for logging modifier debug statements
base_log_path = (
os.environ.get("NM_TEST_LOG_DIR")
if os.environ.get("NM_TEST_MODE")
else "sparse_logs"
)
now = datetime.now()
dt_string = now.strftime("%d-%m-%Y_%H.%M.%S")
log_path = os.path.join(base_log_path, f"{dt_string}.log")
os.makedirs(base_log_path, exist_ok=True)
file_handler = logging.FileHandler(
log_path,
delay=True,
)
file_handler.setLevel(LOGGING_LEVELS["debug"])
logger.addHandler(file_handler)
logger.info(f"Logging all SparseML modifier-level logs to {log_path}")
if not any(
isinstance(handler, logging.FileHandler) for handler in logger.handlers
):
base_log_path = (
os.environ.get("NM_TEST_LOG_DIR")
if os.environ.get("NM_TEST_MODE")
else "sparse_logs"
)
now = datetime.now()
dt_string = now.strftime("%d-%m-%Y_%H.%M.%S")
log_path = os.path.join(base_log_path, f"{dt_string}.log")
os.makedirs(base_log_path, exist_ok=True)
file_handler = logging.FileHandler(
log_path,
delay=True,
)
file_handler.setLevel(LOGGING_LEVELS["debug"])
logger.addHandler(file_handler)
logger.info(f"Logging all SparseML modifier-level logs to {log_path}")

# Console handler, for logging high level modifier logs
stream_handler = logging.StreamHandler()
stream_handler.setLevel(log_level or logging.getLogger("sparseml").level)
if not any(
isinstance(handler, logging.StreamHandler) for handler in logger.handlers
):
# Console handler, for logging high level modifier logs
stream_handler = logging.StreamHandler()
stream_handler.setLevel(log_level or logging.getLogger("sparseml").level)
logger.addHandler(stream_handler)

logger.setLevel(LOGGING_LEVELS["debug"])
logger.propagate = False
Expand Down