Skip to content

Commit

Permalink
move export to class
Browse files Browse the repository at this point in the history
  • Loading branch information
dbogunowicz committed Feb 13, 2023
1 parent ec9e314 commit 545336d
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/sparseml/pytorch/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@
SummaryWriter = object
tensorboard_import_error = tensorboard_err


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

from sparseml.utils import ALL_TOKEN, create_dirs


Expand Down Expand Up @@ -526,12 +513,23 @@ class WANDBLogger(LambdaLogger):
:param enabled: True to log, False otherwise
"""

@staticmethod
def available() -> bool:
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
"""
return not wandb_err
return not self.wandb_err

def __init__(
self,
Expand All @@ -553,15 +551,15 @@ def __init__(
else:
init_kwargs = {"dir": test_log_path}

if wandb_err:
raise wandb_err
if self.wandb_err:
raise self.wandb_err

if init_kwargs:
wandb.init(**init_kwargs)
self.wandb.init(**init_kwargs)
else:
wandb.init()
self.wandb.init()

self.wandb = wandb
self.wandb = self.wandb

def _log_lambda(
self,
Expand All @@ -582,7 +580,7 @@ def _log_lambda(
values = {f"{tag}/{key}": val for key, val in values.items()}
params.update(values)

wandb.log(params, step=step)
self.wandb.log(params, step=step)

return True

Expand All @@ -593,7 +591,7 @@ def save(
"""
:param file_path: path to a file to be saved
"""
wandb.save(file_path)
self.wandb.save(file_path)
return True


Expand Down

0 comments on commit 545336d

Please sign in to comment.