fix some bugs
This commit is contained in:
1 parent
ec7cb25364
commit
6ed07c94ce
4 files changed
+24
-20
No files matched your search
@@ -43,11 +43,12 @@ MNIST_CLASSIFIER_V2:
|
||||
datamodule_folder: "mnist_digits_datamodule"
|
||||
batch_size: 256
|
||||
train_val_split_ratio: 0.9
|
||||
num_workers: 1
|
||||
num_workers: 4
|
||||
pin_memory: False
|
||||
wandb:
|
||||
group: None
|
||||
tags: ["v2", "uwu"]
|
||||
notes: "This is example run."
|
||||
resume_training:
|
||||
checkpoint_path: "logs/wandb/run-20201201_041527-7ab26xrj/files/tests/7ab26xrj/checkpoints/last.ckpt"
|
||||
checkpoint_path: "logs/checkpoints/7ab26xr/last.ckpt"
|
||||
wandb_run_id: "7ab26xrj"
|
||||
+2
-4
@@ -60,9 +60,7 @@ def train(project_config: dict, run_config: dict, use_wandb: bool):
|
||||
|
||||
# resume training from checkpoint if it was set in the run config
|
||||
resume_from_checkpoint=resume_from_checkpoint
|
||||
if resume_from_checkpoint != "None"
|
||||
and resume_from_checkpoint != "False"
|
||||
and resume_from_checkpoint is not False
|
||||
if resume_from_checkpoint != "None" and resume_from_checkpoint is not False
|
||||
else None,
|
||||
|
||||
# print related
|
||||
@@ -74,7 +72,7 @@ def train(project_config: dict, run_config: dict, use_wandb: bool):
|
||||
num_sanity_val_steps=3,
|
||||
|
||||
# default log dir if no logger is found
|
||||
default_root_dir="logs/lightning_logs",
|
||||
default_root_dir=os.path.dirname(__file__) + "logs/lightning_logs",
|
||||
|
||||
# insert all other trainer parameters specified in run config
|
||||
**run_config["trainer"]
|
||||
|
||||
@@ -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__,
|
||||
|
||||
Reference in new issue
Block a user