diff --git a/project/configs/callbacks_configs/mnist_callbacks.yaml b/project/configs/callbacks_configs/mnist_callbacks.yaml index e69de29..f86281f 100644 --- a/project/configs/callbacks_configs/mnist_callbacks.yaml +++ b/project/configs/callbacks_configs/mnist_callbacks.yaml @@ -0,0 +1,16 @@ +EarlyStopping: # name of PyTorch Lightning class for early stopping callback + monitor: "val_acc" + patience: 5 + mode: "max" + +ModelCheckpoint: # name of PyTorch Lightning class for checkpointing callback + monitor: "val_acc" + save_top_k: 1 + save_last: True + mode: "max" + +ConfusionMatrixWandbLoggerCallback: # some custom callback class from template_utils/wandb_callbacks.py + class_names: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + +MetricsHeatmapWandbLoggerCallback: # some custom callback class from template_utils/wandb_callbacks.py + class_names: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] diff --git a/project/configs/experiment_configs/mnist_experiments/advanced_mnist_experiment_config.yaml b/project/configs/experiment_configs/mnist_experiments/advanced_mnist_experiment_config.yaml deleted file mode 100644 index 0a4e776..0000000 --- a/project/configs/experiment_configs/mnist_experiments/advanced_mnist_experiment_config.yaml +++ /dev/null @@ -1,59 +0,0 @@ -# to execute this run: -# python train.py --run_config_name SIMPLE_CONFIG_EXAMPLE_MNIST_v2 - -seed: 1234 -trainer: - args: - min_epochs: 1 # train for at least this many epochs (denies early stopping) - max_epochs: 10 - gradient_clip_val: 0.5 # gradient clipping (helps with exploding gradient issues) - accumulate_grad_batches: 2 # perform optimization step after accumulating gradient from 2 batches - fast_dev_run: False # execute 1 training, 1 validation and 1 test epoch only - limit_train_batches: 0.8 # train only on 80% of training data - limit_val_batches: 1.0 # validate on 100% of validation data - limit_test_batches: 1.0 # test on 100% of test data - val_check_interval: 0.5 # perform validation twice per epoch -model: - load_from: - model_path: "lightning_models/simple_mnist_classifier/simple_mnist_classifier.py" - model_class: "LitModel" - hparams: # you can add here any parameters you want and then read them in model! - lr: 0.001 - weight_decay: 0.00001 - input_size: 784 # img size is 1*28*28 - output_size: 10 # there are 10 digit classes - lin1_size: 256 - lin2_size: 256 - lin3_size: 128 -datamodule: - load_from: - datamodule_path: "lightning_datamodules/mnist_datamodule/mnist_datamodule.py" - datamodule_class: "MNISTDataModule" - hparams: # you can add here any parameters you want and then read them in datamodule! - batch_size: 256 - train_val_test_split: [55_000, 5_000, 10_000] - num_workers: 1 # num of processes used for loading data in parallel - pin_memory: False # dataloaders will copy tensors into CUDA pinned memory before returning them -# the following sections of config are optional and can be removed: -wandb: # Weights&Biases run options - group: "" - job_type: "train" - tags: ["v2", "uwu"] - notes: "This is example run." -callbacks: # you can add here any callback class available in PyTorch Lightning or template_utils/custom_callbacks.py - EarlyStopping: # name of PyTorch Lightning class for early stopping callback - monitor: "val_acc" - patience: 5 - mode: "max" - ModelCheckpoint: # name of PyTorch Lightning class for checkpointing callback - monitor: "val_acc" - save_top_k: 1 - save_last: True - mode: "max" - ConfusionMatrixWandbLoggerCallback: # some custom callback class from template_utils/wandb_callbacks.py - class_names: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] - MetricsHeatmapWandbLoggerCallback: # some custom callback class from template_utils/wandb_callbacks.py - class_names: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] -resume_training: - checkpoint_path: None # path to your checkpoint - wandb_run_id: None # you can add id of wandb run you want to resume but it's optional diff --git a/project/configs/experiment_configs/mnist_experiments/mnist_classifier_advanced_conf.yaml b/project/configs/experiment_configs/mnist_experiments/mnist_classifier_advanced_conf.yaml new file mode 100644 index 0000000..9aa548c --- /dev/null +++ b/project/configs/experiment_configs/mnist_experiments/mnist_classifier_advanced_conf.yaml @@ -0,0 +1,67 @@ +# to execute this experiment run: +# python train.py --exp_conf configs/experiment_configs/mnist_experiments/mnist_classifier_advanced_conf.yaml + +# (required section) +trainer_args: + min_epochs: 1 # train for at least this many epochs (denies early stopping) + max_epochs: 10 + gradient_clip_val: 0.5 # gradient clipping (helps with exploding gradient issues) + accumulate_grad_batches: 2 # perform optimization step after accumulating gradient from 2 batches + fast_dev_run: False # execute 1 training, 1 validation and 1 test epoch only + limit_train_batches: 0.8 # train only on 80% of training data + limit_val_batches: 1.0 # validate on 100% of validation data + limit_test_batches: 1.0 # test on 100% of test data + val_check_interval: 0.5 # perform validation twice per epoch + +# (required section) +model: + load_from: + model_path: "pytorch_modules/lightning_models/simple_mnist_classifier.py" + model_class: "LitModel" + hparams: # you can add here any parameters you want and then read them in model + lr: 0.001 + weight_decay: 0.00001 + input_size: 784 # img size is 1*28*28 + output_size: 10 # there are 10 digit classes + lin1_size: 256 + lin2_size: 256 + lin3_size: 128 + +# (required section) +datamodule: + load_from: + datamodule_path: "lightning_datamodules/mnist_datamodule/mnist_datamodule.py" + datamodule_class: "MNISTDataModule" + hparams: # you can add here any parameters you want and then read them in datamodule + batch_size: 256 + train_val_test_split: [55_000, 5_000, 10_000] + num_workers: 1 # num of processes used for loading data in parallel + pin_memory: False # dataloaders will copy tensors into CUDA pinned memory before returning them + +# (optional section) +# pytorch seed for this experiment +# it also affects random_split() method used in mnist_datamodule.py +# overwrites default pytorch seed set in project_config.yaml +pytorch_seed: + use_seed: True + pytorch_seed: 1234 + +# (optional section) +# Weights&Biases logger args +# this will be combained with default wandb args set in project_config.yaml (overwrites repeating args) +wandb_args: + group: "" + job_type: "train" + tags: ["v2", "uwu"] + notes: "This is example run." + +# (optional section) +# path to .yaml file containing configurations of all callbacks which will be used for this experiment +# this will be combained with default callbacks set in project_config.yaml (overwrites repeating callbacks) +callbacks_configs_path: "configs/callbacks_configs/mnist_callabcks.yaml" + +# (optional section) +# use this if you want to resume training from checkpoint +resume_training: + checkpoint_path: None # path to your checkpoint + wandb_run_id: None # you can add id of wandb run you want to resume but it's optional diff --git a/project/configs/experiment_configs/mnist_experiments/simple_mnist_experiment_config.yaml b/project/configs/experiment_configs/mnist_experiments/mnist_classifier_simple_conf.yaml similarity index 69% rename from project/configs/experiment_configs/mnist_experiments/simple_mnist_experiment_config.yaml rename to project/configs/experiment_configs/mnist_experiments/mnist_classifier_simple_conf.yaml index 6358cd7..4073603 100644 --- a/project/configs/experiment_configs/mnist_experiments/simple_mnist_experiment_config.yaml +++ b/project/configs/experiment_configs/mnist_experiments/mnist_classifier_simple_conf.yaml @@ -1,14 +1,12 @@ -# to execute this run: -# python train.py --run_config_name SIMPLE_CONFIG_EXAMPLE_MNIST - -seed: 1234 +# to execute this experiment run: +# python train.py --exp_conf configs/experiment_configs/mnist_experiments/mnist_classifier_simple_conf.yaml trainer_args: max_epochs: 10 model: load_from: - model_path: "lightning_models/simple_mnist_classifier/simple_mnist_classifier.py" + model_path: "pytorch_modules/lightning_models/simple_mnist_classifier.py" model_class: "LitModel" hparams: lr: 0.001 diff --git a/project/project_config.yaml b/project/project_config.yaml index c6846d4..70192c4 100644 --- a/project/project_config.yaml +++ b/project/project_config.yaml @@ -1,11 +1,18 @@ # default args passed to Lightning Trainer on every run/experiment # if you specify the same args in experiment config then they will overwrite the ones set here default_trainer_args: - num_of_gpus: -1 # set -1 to train on all GPUs abailable, set 0 to train on CPU only + num_of_gpus: 0 # set -1 to train on all GPUs abailable, set 0 to train on CPU only progress_bar_refresh_rate: 10 # refresh terminal every 10 batches weights_summary: "top" # print model summary (alternatively "full") +# default pytorch seed used on every run/experiment +# this can be overwritten by +default_pytorch_seed: + use_seed: True + pytorch_seed: 1234 + + # default loggers initialised on every run/experiment # if you specify this section in experiment config then it will be totally overwritten default_loggers: @@ -29,15 +36,19 @@ default_loggers: # if you specify the same callback class also in experiment config then it will overwrite the one set here # all of the callback parameters will be passed to it on initialization default_callbacks: - ModelCheckpoint: # name of PyTorch Lightning class for checkpointing callback - monitor: "val_acc" # name of the logged metric which determines when model is improving - save_top_k: 1 # save k best lightning_models (determined by above metric) - save_last: True # additionaly always save model from last epoch - mode: "max" # can be "max" or "min" - EarlyStopping: # name of PyTorch Lightning class for early stopping callback - monitor: "val_acc" # name of the logged metric which determines when model is improving - patience: 5 # how many epochs of not improving until training stops - mode: "max" # can be "max" or "min" + chekpointing: + class: "pytorch_lightning.callbacks.ModelCheckpoint" + args: + monitor: "val_acc" # name of the logged metric which determines when model is improving + save_top_k: 1 # save k best lightning_models (determined by above metric) + save_last: True # additionaly always save model from last epoch + mode: "max" # can be "max" or "min" + early_stopping: + class: "pytorch_lightning.callbacks.EarlyStopping" + args: + monitor: "val_acc" # name of the logged metric which determines when model is improving + patience: 5 # how many epochs of not improving until training stops + mode: "max" # can be "max" or "min" # use profiler to print execution time profiling after training ends diff --git a/project/template_utils/execute_all_experiments.py b/project/template_utils/execute_all_experiments.py index 193f9e6..c84e7ae 100644 --- a/project/template_utils/execute_all_experiments.py +++ b/project/template_utils/execute_all_experiments.py @@ -1,5 +1,4 @@ -# 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 +# THIS FILE WILL EXECUTE ALL EXPERIMENT CONFIGS LOCATED IN SPECIFIED FOLDER ONE AFTER THE OTHER from argparse import ArgumentParser import train