diff --git a/README.md b/README.md index 8d29a72..7e2360d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ The directory structure of new project looks like this: │ ├── utils <- Different utilities │ │ ├── callbacks.py <- Useful training callbacks │ │ ├── execute_sweep.py <- Special file for executing Weights&Biases sweeps +│ │ ├── execute_all_runs.py <- Special file for executing all specified runs one after the other │ │ ├── init_utils.py <- Useful initializers │ │ └── predict_example.py <- Example of inference with trained model │ │ diff --git a/project/run_configs.yaml b/project/run_configs.yaml index 3627758..3e22387 100644 --- a/project/run_configs.yaml +++ b/project/run_configs.yaml @@ -50,5 +50,5 @@ MNIST_CLASSIFIER_V2: tags: ["v2", "uwu"] notes: "This is example run." resume_training: - checkpoint_path: "logs/checkpoints/7ab26xr/last.ckpt" - wandb_run_id: "7ab26xrj" + checkpoint_path: None + wandb_run_id: None diff --git a/project/train.py b/project/train.py index 7aa6343..6a13377 100644 --- a/project/train.py +++ b/project/train.py @@ -100,6 +100,14 @@ def main(run_config_name: str, use_wandb: bool): project_config: dict = load_config("project_config.yaml") run_config: dict = load_config("run_configs.yaml")[run_config_name] + # Print run config info + print("EXECUTING RUN:", run_config_name) + print("CONFIG:") + for section in run_config: + print(" " + section + ":") + for key in run_config[section]: + print(" " + key + ":", run_config[section][key]) + # Train model train(project_config=project_config, run_config=run_config, use_wandb=use_wandb) diff --git a/project/utils/execute_all_runs.py b/project/utils/execute_all_runs.py new file mode 100644 index 0000000..04dcb15 --- /dev/null +++ b/project/utils/execute_all_runs.py @@ -0,0 +1,41 @@ +# THIS FILE WILL EXECUTE ALL RUNS SPECIFIED IN run_configs.yaml ONE AFTER THE OTHER +# YOU CAN ALSO SPECIFY PATH TO DIFFERENT FILE WITH RUN CONFIGS + +from argparse import ArgumentParser +from train import train +import wandb +import yaml +import os + + +def main(project_config_path, run_configs_path): + + with open(project_config_path, "r") as ymlfile: + project_config = yaml.load(ymlfile, Loader=yaml.FullLoader) + + with open(run_configs_path, "r") as ymlfile: + run_configs = yaml.load(ymlfile, Loader=yaml.FullLoader) + + # EXECUTE ALL RUNS ONE AFTER THE OTHER + for conf_name in run_configs: + print() + print("EXECUTING RUN:", conf_name) + print("CONFIG:") + for section in run_configs[conf_name]: + print(" " + section + ":") + for key in run_configs[conf_name][section]: + print(" " + key + ":", run_configs[conf_name][section][key]) + print() + train(project_config=project_config, run_config=run_configs[conf_name], use_wandb=True) + wandb.finish() + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-p", "--project_config_path", type=str, + default=os.path.join(os.path.dirname(os.path.dirname(__file__)), "project_config.yaml")) + parser.add_argument("-r", "--run_configs_path", type=str, + default=os.path.join(os.path.dirname(os.path.dirname(__file__)), "run_configs.yaml")) + args = parser.parse_args() + + main(project_config_path=args.project_config_path, run_configs_path=args.run_configs_path) diff --git a/project/utils/execute_sweep.py b/project/utils/execute_sweep.py index e1b4983..9442d6a 100644 --- a/project/utils/execute_sweep.py +++ b/project/utils/execute_sweep.py @@ -1,5 +1,6 @@ # THIS FILE IS FOR HYPERPARAMETER SEARCH WITH Weights&Biases # IT SHOULDN't BE EXECUTED DIRECTLY, IT SHOULD BE RUN BY WANDB SWEEP AGENT! + import wandb import train diff --git a/project/utils/init_utils.py b/project/utils/init_utils.py index 818f998..39accbc 100644 --- a/project/utils/init_utils.py +++ b/project/utils/init_utils.py @@ -16,6 +16,8 @@ def init_lit_model(hparams: dict) -> pl.LightningModule: def init_data_module(hparams: dict) -> pl.LightningDataModule: """Load DataModule from folder specified in run config.""" module_path = "data_modules." + hparams["datamodule_folder"] + ".datamodule" + if "data_dir" not in hparams: + hparams["data_dir"] = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data") datamodule = importlib.import_module(module_path).DataModule(hparams=hparams) datamodule.prepare_data() datamodule.setup()