4 files changed
+30
-23
No files matched your search
@@ -99,12 +99,12 @@ You can store many run configurations in this file.<br>
|
|||||||
Example run configuration:
|
Example run configuration:
|
||||||
```yaml
|
```yaml
|
||||||
MNIST_CLASSIFIER_V1:
|
MNIST_CLASSIFIER_V1:
|
||||||
trainer: <- lightning 'Trainer' parameters (all except 'max_epochs' are optional)
|
trainer: <- parameters passed to lightning 'Trainer'
|
||||||
max_epochs: 5
|
max_epochs: 5
|
||||||
gradient_clip_val: 0.5
|
gradient_clip_val: 0.5
|
||||||
accumulate_grad_batches: 3
|
accumulate_grad_batches: 3
|
||||||
limit_train_batches: 1.0
|
limit_train_batches: 1.0
|
||||||
model: <- all of the parameters here will be passed to 'LitModel' in 'hparams' dictionary
|
model: <- parameters passed to 'LitModel' in 'hparams' dictionary
|
||||||
model_folder: "simple_mnist_classifier" <- name of folder from which 'lightning_module.py' (with 'LitMdodel' class) will be loaded
|
model_folder: "simple_mnist_classifier" <- name of folder from which 'lightning_module.py' (with 'LitMdodel' class) will be loaded
|
||||||
lr: 0.001
|
lr: 0.001
|
||||||
weight_decay: 0.000001
|
weight_decay: 0.000001
|
||||||
@@ -113,7 +113,7 @@ MNIST_CLASSIFIER_V1:
|
|||||||
lin1_size: 256
|
lin1_size: 256
|
||||||
lin2_size: 256
|
lin2_size: 256
|
||||||
lin3_size: 128
|
lin3_size: 128
|
||||||
dataset: <- all of the parameters here will be passed to 'DataModule' in 'hparams' dictionary
|
dataset: <- parameters passed to 'DataModule' in 'hparams' dictionary
|
||||||
datamodule_folder: "mnist_digits_datamodule" <- name of folder from which 'datamodule.py' (with 'DataModule' class) will be loaded
|
datamodule_folder: "mnist_digits_datamodule" <- name of folder from which 'datamodule.py' (with 'DataModule' class) will be loaded
|
||||||
batch_size: 256
|
batch_size: 256
|
||||||
train_val_split_ratio: 0.9
|
train_val_split_ratio: 0.9
|
||||||
@@ -122,8 +122,8 @@ MNIST_CLASSIFIER_V1:
|
|||||||
wandb: <- this section is optional and can be removed
|
wandb: <- this section is optional and can be removed
|
||||||
group: ""
|
group: ""
|
||||||
tags: ["v1", "uwu"]
|
tags: ["v1", "uwu"]
|
||||||
resume_training: <- this section is optional and can be removed if you don't want to resume training
|
resume_training: <- this section is optional and can be removed
|
||||||
checkpoint_path: "path_to_checkpoint/last.ckpt" <- path to checkpoint
|
checkpoint_path: "path_to_checkpoint/last.ckpt"
|
||||||
wandb_run_id: None <- you can set id of Weights&Biases run that you want to resume but it's optional
|
wandb_run_id: None <- you can set id of Weights&Biases run that you want to resume but it's optional
|
||||||
```
|
```
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@@ -43,11 +43,12 @@ MNIST_CLASSIFIER_V2:
|
|||||||
datamodule_folder: "mnist_digits_datamodule"
|
datamodule_folder: "mnist_digits_datamodule"
|
||||||
batch_size: 256
|
batch_size: 256
|
||||||
train_val_split_ratio: 0.9
|
train_val_split_ratio: 0.9
|
||||||
num_workers: 1
|
num_workers: 4
|
||||||
pin_memory: False
|
pin_memory: False
|
||||||
wandb:
|
wandb:
|
||||||
group: None
|
group: None
|
||||||
tags: ["v2", "uwu"]
|
tags: ["v2", "uwu"]
|
||||||
|
notes: "This is example run."
|
||||||
resume_training:
|
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"
|
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 training from checkpoint if it was set in the run config
|
||||||
resume_from_checkpoint=resume_from_checkpoint
|
resume_from_checkpoint=resume_from_checkpoint
|
||||||
if resume_from_checkpoint != "None"
|
if resume_from_checkpoint != "None" and resume_from_checkpoint is not False
|
||||||
and resume_from_checkpoint != "False"
|
|
||||||
and resume_from_checkpoint is not False
|
|
||||||
else None,
|
else None,
|
||||||
|
|
||||||
# print related
|
# print related
|
||||||
@@ -74,7 +72,7 @@ def train(project_config: dict, run_config: dict, use_wandb: bool):
|
|||||||
num_sanity_val_steps=3,
|
num_sanity_val_steps=3,
|
||||||
|
|
||||||
# default log dir if no logger is found
|
# 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
|
# insert all other trainer parameters specified in run config
|
||||||
**run_config["trainer"]
|
**run_config["trainer"]
|
||||||
|
|||||||
+20
-12
@@ -40,16 +40,18 @@ def init_main_callbacks(project_config: dict) -> List[pl.Callback]:
|
|||||||
return callbacks
|
return callbacks
|
||||||
|
|
||||||
|
|
||||||
def init_wandb_logger(
|
def init_wandb_logger(project_config: dict, run_config: dict,
|
||||||
project_config: dict,
|
lit_model: pl.LightningModule, datamodule: pl.LightningDataModule,
|
||||||
run_config: dict,
|
log_path: str = "logs/") -> pl.loggers.WandbLogger:
|
||||||
lit_model: pl.LightningModule,
|
|
||||||
datamodule: pl.LightningDataModule,
|
|
||||||
log_path: str = "logs/"
|
|
||||||
) -> pl.loggers.WandbLogger:
|
|
||||||
"""Initialize Weights&Biases logger."""
|
"""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)
|
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_run_id = run_config.get("resume_training", {}).get("wandb_run_id", None)
|
||||||
|
|
||||||
wandb_logger = WandbLogger(
|
wandb_logger = WandbLogger(
|
||||||
project=project_config["loggers"]["wandb"]["project"],
|
project=project_config["loggers"]["wandb"]["project"],
|
||||||
entity=project_config["loggers"]["wandb"]["entity"],
|
entity=project_config["loggers"]["wandb"]["entity"],
|
||||||
@@ -59,29 +61,35 @@ def init_wandb_logger(
|
|||||||
group=run_config.get("wandb", {}).get("group", None),
|
group=run_config.get("wandb", {}).get("group", None),
|
||||||
job_type=run_config.get("wandb", {}).get("job_type", "train"),
|
job_type=run_config.get("wandb", {}).get("job_type", "train"),
|
||||||
tags=run_config.get("wandb", {}).get("tags", []),
|
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
|
# resume run only if ckpt was set in the run config
|
||||||
id=wandb_run_id
|
id=wandb_run_id
|
||||||
if resume_from_checkpoint != "None" and wandb_run_id != "None"
|
if resume_from_checkpoint != "None" and wandb_run_id != "None" and resume_from_checkpoint is not None
|
||||||
and resume_from_checkpoint != "False" and wandb_run_id != "False"
|
|
||||||
and resume_from_checkpoint is not False and wandb_run_id is not False
|
and resume_from_checkpoint is not False and wandb_run_id is not False
|
||||||
else None,
|
else None,
|
||||||
|
|
||||||
save_dir=log_path,
|
save_dir=log_path,
|
||||||
save_code=False
|
save_code=False
|
||||||
)
|
)
|
||||||
|
|
||||||
if not os.path.exists(log_path):
|
if not os.path.exists(log_path):
|
||||||
os.makedirs(log_path)
|
os.makedirs(log_path)
|
||||||
|
|
||||||
if hasattr(lit_model, 'model'):
|
if hasattr(lit_model, 'model'):
|
||||||
wandb_logger.watch(lit_model.model, log=None)
|
wandb_logger.watch(lit_model.model, log=None)
|
||||||
else:
|
else:
|
||||||
wandb_logger.watch(lit_model, log=None)
|
wandb_logger.watch(lit_model, log=None)
|
||||||
|
|
||||||
wandb_logger.log_hyperparams({
|
wandb_logger.log_hyperparams({
|
||||||
"model_name": lit_model.model.__class__.__name__,
|
"model_name": lit_model.model.__class__.__name__,
|
||||||
"optimizer": lit_model.configure_optimizers().__class__.__name__,
|
"optimizer": lit_model.configure_optimizers().__class__.__name__,
|
||||||
"train_size": len(datamodule.data_train) if datamodule.data_train is not None else 0,
|
"train_size": len(datamodule.data_train)
|
||||||
"val_size": len(datamodule.data_val) if datamodule.data_val is not None else 0,
|
if hasattr(datamodule, 'data_train') and datamodule.data_train is not None else 0,
|
||||||
"test_size": len(datamodule.data_test) if datamodule.data_test is not None else 0,
|
"val_size": len(datamodule.data_val)
|
||||||
|
if hasattr(datamodule, 'data_val') and datamodule.data_val is not None else 0,
|
||||||
|
"test_size": len(datamodule.data_test)
|
||||||
|
if hasattr(datamodule, 'data_test') and datamodule.data_test is not None else 0,
|
||||||
})
|
})
|
||||||
wandb_logger.log_hyperparams(run_config["trainer"])
|
wandb_logger.log_hyperparams(run_config["trainer"])
|
||||||
wandb_logger.log_hyperparams(run_config["model"])
|
wandb_logger.log_hyperparams(run_config["model"])
|
||||||
|
|||||||
Reference in new issue
Block a user