Skip to content

Commit

Permalink
fix(project): add conditional wandb initialization check
Browse files Browse the repository at this point in the history
refactor(project): separate wandb initialization into new method
  • Loading branch information
entelecheia committed Jul 14, 2023
1 parent 2b3fb56 commit 35103d5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/hyfi/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,25 @@ def init_wandb(self):
if self.dotenv is None:
raise ValueError("DotEnv object not initialized")

if not self.use_wandb:
return
try:
self._init_wandb()
except ImportError:
logger.warning("wandb is not installed, please install it to use wandb.")

def _init_wandb(self):
import wandb # type: ignore

self.dotenv.WANDB_DIR = str(self.path.log_dir)
project_name = self.project_name.replace("/", "-").replace("\\", "-")
self.dotenv.WANDB_PROJECT = project_name
notebook_name = self.path.log_dir / f"{project_name}-nb"
notebook_name.mkdir(parents=True, exist_ok=True)
self.dotenv.WANDB_NOTEBOOK_NAME = str(notebook_name)
self.dotenv.WANDB_SILENT = str(not self.verbose)
if self.use_wandb:
try:
import wandb # type: ignore

wandb.init(project=self.project_name)
except ImportError:
logger.warning(
"wandb is not installed, please install it to use wandb."
)

wandb.init(project=project_name)

def init_huggingface_hub(self):
"""Initialize huggingface_hub"""
Expand Down

0 comments on commit 35103d5

Please sign in to comment.