fix some bugs

This commit is contained in:
hobogalaxy committed 2020-12-05 19:56:54 +01:00
1 parent ec7cb25364
commit 6ed07c94ce
4 files changed
+24 -20

No files matched your search

+14 -9
View File
@@ -40,16 +40,18 @@ def init_main_callbacks(project_config: dict) -> List[pl.Callback]:
return callbacks
def init_wandb_logger(
project_config: dict,
run_config: dict,
lit_model: pl.LightningModule,
datamodule: pl.LightningDataModule,
log_path: str = "logs/"
) -> pl.loggers.WandbLogger:
def init_wandb_logger(project_config: dict, run_config: dict,
lit_model: pl.LightningModule, datamodule: pl.LightningDataModule,
log_path: str = "logs/") -> pl.loggers.WandbLogger:
"""Initialize Weights&Biases logger."""
# with this line wandb will throw an error if the run to be resumed does not exist yet
# instead of auto-creating a new run
os.environ["WANDB_RESUME"] = "must"
resume_from_checkpoint = run_config.get("resume_training", {}).get("resume_from_checkpoint", None)
wandb_run_id = run_config.get("resume_training", {}).get("wandb_run_id", None)
wandb_logger = WandbLogger(
project=project_config["loggers"]["wandb"]["project"],
entity=project_config["loggers"]["wandb"]["entity"],
@@ -59,23 +61,26 @@ def init_wandb_logger(
group=run_config.get("wandb", {}).get("group", None),
job_type=run_config.get("wandb", {}).get("job_type", "train"),
tags=run_config.get("wandb", {}).get("tags", []),
notes=run_config.get("wandb", {}).get("notes", ""),
# resume run only if ckpt was set in the run config
id=wandb_run_id
if resume_from_checkpoint != "None" and wandb_run_id != "None"
and resume_from_checkpoint != "False" and wandb_run_id != "False"
if resume_from_checkpoint != "None" and wandb_run_id != "None" and resume_from_checkpoint is not None
and resume_from_checkpoint is not False and wandb_run_id is not False
else None,
save_dir=log_path,
save_code=False
)
if not os.path.exists(log_path):
os.makedirs(log_path)
if hasattr(lit_model, 'model'):
wandb_logger.watch(lit_model.model, log=None)
else:
wandb_logger.watch(lit_model, log=None)
wandb_logger.log_hyperparams({
"model_name": lit_model.model.__class__.__name__,
"optimizer": lit_model.configure_optimizers().__class__.__name__,