Skip to content

Commit

Permalink
better solution
Browse files Browse the repository at this point in the history
  • Loading branch information
dbogunowicz committed Feb 13, 2023
1 parent 545336d commit ccfd555
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/sparseml/pytorch/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,18 +513,6 @@ class WANDBLogger(LambdaLogger):
:param enabled: True to log, False otherwise
"""

try:
import wandb

wandb_err = None
except Exception as err:
wandb = None
wandb_err = err
raise ModuleNotFoundError(
"Error: Failed to import wandb. "
"Please install the wandb library in order to use it."
) from wandb_err

def available(self) -> bool:
"""
:return: True if wandb is available and installed, False, otherwise
Expand All @@ -537,6 +525,21 @@ def __init__(
name: str = "wandb",
enabled: bool = True,
):
try:
import wandb

wandb_err = None
except Exception as err:
wandb = None
wandb_err = err
raise ModuleNotFoundError(
"Error: Failed to import wandb. "
"Please install the wandb library in order to use it."
) from wandb_err

self.wandb = wandb
self.wandb_err = wandb_err

super().__init__(
lambda_func=self._log_lambda,
name=name,
Expand Down

0 comments on commit ccfd555

Please sign in to comment.