From 7d09ab8ece4b4696908b8bfa2c2f2a0939e4f0af Mon Sep 17 00:00:00 2001 From: hobogalaxy Date: Tue, 24 Nov 2020 18:40:50 +0100 Subject: [PATCH] update execute_sweep.py --- project/execute_sweep.py | 41 +++++++++++++------------ project/lightning_modules/init_utils.py | 3 ++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/project/execute_sweep.py b/project/execute_sweep.py index 171cdad..4dcbea4 100644 --- a/project/execute_sweep.py +++ b/project/execute_sweep.py @@ -1,20 +1,23 @@ -# import wandb -# import train -# -# -# # Load project config -# config = train.load_config() -# -# # Initialize wandb -# wandb.init() -# -# # Replace project config hyperparameters with the ones loaded from wandb sweep server -# sweep_hparams = wandb.Config._as_dict(wandb.config) -# for key, value in sweep_hparams.items(): -# if key != "_wandb": -# config["hparams"][key] = value -# -# # Execute run -# train.train(config) +import wandb +import train -# TODO: this file + +# THIS FILE SHOULDN't BE EXECUTED DIRECTLY, IT SHOULD BE RUN BY WANDB SWEEP AGENT! + +# Load project config +conf = train.load_config() + +# Choose model for hyperparameter search +model_conf = conf["model_configs"]["simple_mnist_classifier_v1"] + +# Initialize wandb +wandb.init() + +# Replace project config hyperparameters with the ones loaded from wandb sweep server +sweep_hparams = wandb.Config._as_dict(wandb.config) +for key, value in sweep_hparams.items(): + if key != "_wandb" and not key.startswith("dataset/"): + model_conf[key] = value + +# Execute run +train.train(config=conf, model_config=model_conf) diff --git a/project/lightning_modules/init_utils.py b/project/lightning_modules/init_utils.py index f7f3314..a01b44b 100644 --- a/project/lightning_modules/init_utils.py +++ b/project/lightning_modules/init_utils.py @@ -2,6 +2,7 @@ from pytorch_lightning.loggers import WandbLogger, TensorBoardLogger, CometLogge from pytorch_lightning.callbacks import ModelCheckpoint, EarlyStopping from lightning_modules.data_modules import datamodules, transforms import importlib +import os def init_lit_model(model_config): @@ -52,6 +53,8 @@ def init_wandb_logger(config, lit_model, datamodule): save_dir="logs/", save_code=False ) + if not os.path.exists("logs/"): + os.mkdir("logs/") wandb_logger.watch(lit_model.model, log=None) wandb_logger.log_hyperparams({ "model_name": lit_model.model.__class__.__name__,