Skip to content

Commit

Permalink
log model details in NequIPLightningModule under DEBUG mode control…
Browse files Browse the repository at this point in the history
…led by env var `_NEQUIP_LOG_LEVEL=DEBUG`
  • Loading branch information
cw-tan committed Oct 21, 2024
1 parent 86dfc35 commit 1ea9077
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nequip/train/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
from hydra.utils import instantiate
from nequip.model import model_from_config
from nequip.data import AtomicDataDict
from nequip.utils import RankedLogger
from ._metrics_utils import gather_all_tensors
import warnings
from typing import Optional, Dict


logger = RankedLogger(__name__, rank_zero_only=True)


# metrics are already synced before logging, but Lightning still sends a PossibleUserWarning about setting sync_dist=True in self.logdict()
warnings.filterwarnings(
"ignore",
Expand Down Expand Up @@ -62,6 +66,7 @@ def __init__(
super().__init__()
self.save_hyperparameters()
self.model = model_from_config(config=model, initialize=True)
logger.debug(f"Built Model Details:\n{str(self.model)}")
self.optimizer_config = optimizer
self.lr_scheduler_config = lr_scheduler

Expand Down
6 changes: 6 additions & 0 deletions nequip/utils/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""From https://github.com/ashleve/lightning-hydra-template"""

import os
import logging
from typing import Mapping, Optional

Expand All @@ -26,6 +27,11 @@ def __init__(
super().__init__(logger=logger, extra=extra)
self.rank_zero_only = rank_zero_only

# get log level from the environment variable, default to 'INFO'
log_level = os.getenv("_NEQUIP_LOG_LEVEL", "INFO").upper()
log_level = getattr(logging, log_level, logging.INFO)
self.logger.setLevel(log_level)

def log(
self, level: int, msg: str, rank: Optional[int] = None, *args, **kwargs
) -> None:
Expand Down

0 comments on commit 1ea9077

Please sign in to comment.