diff --git a/README.md b/README.md
index bc8f4eb..adb9258 100644
--- a/README.md
+++ b/README.md
@@ -66,11 +66,12 @@ The directory structure of new project looks like this:
├── configs <- Hydra configuration files
│ ├── callbacks <- Callbacks configs
│ ├── datamodule <- Datamodule configs
+│ ├── debug <- Debugging configs
│ ├── experiment <- Experiment configs
│ ├── hparams_search <- Hyperparameter search configs
│ ├── local <- Local configs
+│ ├── log_dir <- Logging directory configs
│ ├── logger <- Logger configs
-│ ├── mode <- Running mode configs
│ ├── model <- Model configs
│ ├── trainer <- Trainer configs
│ │
@@ -220,29 +221,13 @@ python run.py logger=wandb
-
-Use different running modes
-
-```bash
-# debug mode changes logging folder to `logs/debug/`
-# also enables default trainer debugging options from `configs/trainer/debug.yaml`
-# also sets level of all command line loggers to 'DEBUG'
-python run.py mode=debug
-
-# experiment mode changes logging folder to `logs/experiments/name_of_your_experiment/`
-# name is also used by loggers
-python run.py mode=exp name='my_new_experiment_253'
-```
-
-
-
Train model with chosen experiment config
> Experiment configurations are placed in [configs/experiment/](configs/experiment/).
```bash
-python run.py experiment=example_simple
+python run.py experiment=example
```
@@ -286,15 +271,18 @@ python run.py +trainer.max_time="00:12:00:00"
Easily debug
-```bash
-# run in debug mode
-# changes logging folder to `logs/debug/...`
-# enables trainer debugging options specified in `configs/trainer/debug.yaml`
-# sets level of all command line loggers to 'DEBUG'
-python run.py mode=debug
+> Visit [configs/debug/](configs/debug/) for different debugging configs.
-# enable trainer debugging options specified in `configs/trainer/debug.yaml`
-python run.py trainer=debug
+```bash
+# runs 1 epoch in default debugging mode
+# changes logging directory to `logs/debugs/...`
+# sets level of all command line loggers to 'DEBUG'
+# enables extra trainer flags like tracking gradient norm
+# enforces debug-friendly configuration
+python run.py debug=default
+
+# runs test epoch without training
+python run.py debug=test_only
# run 1 train, val and test loop, using only 1 batch
python run.py +trainer.fast_dev_run=true
@@ -452,32 +440,41 @@ It determines how config is composed when simply executing command `python run.p
```yaml
# specify here default training configuration
defaults:
- - trainer: default.yaml
- - model: mnist.yaml
- datamodule: mnist.yaml
+ - model: mnist.yaml
- callbacks: default.yaml
- - logger: null # set logger here or use command line (e.g. `python run.py logger=wandb`)
+ - logger: null # set logger here or use command line (e.g. `python run.py logger=tensorboard`)
+ - trainer: default.yaml
- # modes are special collections of config options for different purposes, e.g. debugging
- - mode: default.yaml
+ # logging folder path
+ - log_dir: default.yaml
# experiment configs allow for version control of specific configurations
+ # e.g. best hyperparameters for each combination of model and datamodule
- experiment: null
+ # debugging config (enable through command line, e.g. `python run.py debug=one_epoch)
+ - debug: null
+
# config for hyperparameter optimization
- hparams_search: null
# optional local config for machine/user specific settings
+ # it's optional since it doesn't need to exist and is excluded from version control
- optional local: default.yaml
+ # enable color logging
+ - override hydra/hydra_logging: colorlog
+ - override hydra/job_logging: colorlog
+
# path to original working directory
# hydra hijacks working directory by changing it to the new log directory
# so it's useful to have this path as a special variable
# https://hydra.cc/docs/next/tutorials/basic/running_your_app/working_directory
-work_dir: ${hydra:runtime.cwd}
+original_work_dir: ${hydra:runtime.cwd}
# path to folder with data
-data_dir: ${work_dir}/data/
+data_dir: ${original_work_dir}/data/
# pretty print config at the start of the run using Rich library
print_config: True
@@ -485,12 +482,19 @@ print_config: True
# disable python warnings if they annoy you
ignore_warnings: True
+# set False to skip model training
+train: True
+
# evaluate on test set, using best model weights achieved during training
-# lightning chooses best weights based on metric specified in checkpoint callback
+# lightning chooses best weights based on the metric specified in checkpoint callback
test_after_training: True
# seed for random number generators in pytorch, numpy and python.random
seed: null
+
+# default name for the experiment, determines logging folder path
+# (you can overwrite this name in experiment configs)
+name: "default"
```
@@ -511,23 +515,22 @@ For example, you can use them to version control best hyperparameters for each c
# python run.py experiment=example
defaults:
- - override /mode: exp.yaml
- - override /trainer: default.yaml
- - override /model: mnist.yaml
- override /datamodule: mnist.yaml
+ - override /model: mnist.yaml
- override /callbacks: default.yaml
- override /logger: null
+ - override /trainer: default.yaml
# all parameters below will be merged with parameters from default configurations set above
+# this allows you to overwrite only specified parameters
# name of the run determines folder name in logs
-# can also be accessed by loggers
-name: "example"
+name: "simple_dense_net"
seed: 12345
trainer:
- min_epochs: 1
+ min_epochs: 10
max_epochs: 10
gradient_clip_val: 0.5
@@ -539,13 +542,10 @@ model:
datamodule:
batch_size: 64
- train_val_test_split: [55_000, 5_000, 10_000]
logger:
- csv:
- name: csv/${name}
wandb:
- tags: ["mnist", "simple_dense_net"]
+ tags: ["mnist", "${name}"]
```
@@ -597,62 +597,44 @@ hydra:
**Hydra creates new working directory for every executed run.**
This means your working directory is different for every run, which might not be compatible with some libraries and workflows. By default, logs have the following structure:
-
-Show logs structure
-
```
├── logs
-│ ├── experiments # Folder for logs generated by experiments
-│ │ ├── experiment_name # Name of the experiment
-│ │ │ ├── runs
-│ │ │ │ ├── YYYY-MM-DD # Date of execution
-│ │ │ │ │ ├── HH-MM-SS # Time of execution
-│ │ │ │ │ │ ├── .hydra # Hydra logs
-│ │ │ │ │ │ ├── wandb # Weights&Biases logs
-│ │ │ │ │ │ ├── checkpoints # Training checkpoints
-│ │ │ │ │ │ └── ... # Any other thing saved during training
-│ │ │ │ │ └── ...
-│ │ │ │ └── ...
-│ │ │ │
-│ │ │ └── multiruns
-│ │ │ ├── YYYY-MM-DD
-│ │ │ │ ├── HH-MM-SS
-│ │ │ │ │ ├── 1 # Multirun job number
-│ │ │ │ │ │ └── ...
-│ │ │ │ │ ├── 2
-│ │ │ │ │ └── ...
-│ │ │ │ └── ...
-│ │ │ └── ...
-│ │ └── ...
-│ │
-│ ├── debugs # Folder for logs generated during debugging
-│ │ ├── runs
-│ │ │ ├── YYYY-MM-DD
-│ │ │ │ ├── HH-MM-SS
+│ ├── experiments # Folder for the logs generated by experiments
+│ │ ├── runs # Folder for single runs
+│ │ │ ├── experiment_name # Experiment name
+│ │ │ │ ├── YYYY-MM-DD_HH-MM-SS # Datetime of the run
+│ │ │ │ │ ├── .hydra # Hydra logs
+│ │ │ │ │ ├── wandb # Weights&Biases logs
+│ │ │ │ │ ├── checkpoints # Training checkpoints
+│ │ │ │ │ └── ... # Any other thing saved during training
│ │ │ │ └── ...
│ │ │ └── ...
-│ │ └── multiruns
-│ │ ├── YYYY-MM-DD
-│ │ │ ├── HH-MM-SS
+│ │ │
+│ │ └── multiruns # Folder for multiruns
+│ │ ├── experiment_name # Experiment name
+│ │ │ ├── YYYY-MM-DD_HH-MM-SS # Datetime of the multirun
+│ │ │ │ ├──1 # Multirun job number
+│ │ │ │ ├──2
+│ │ │ │ └── ...
│ │ │ └── ...
-│ │ └─ ...
+│ │ └── ...
│ │
-│ ├── runs # Folder for logs generated by normal runs
-│ │ ├── YYYY-MM-DD
-│ │ │ ├── HH-MM-SS
-│ │ │ └── ...
-│ │ └── ...
-│ │
-│ └── multiruns # Folder for logs generated by normal multiruns (sweeps)
-│ ├── YYYY-MM-DD
-│ | ├── HH-MM-SS
-│ | └── ...
-│ └── ...
-│
+│ └── debugs # Folder for the logs generated during debugging
+| ├── runs
+| │ ├── experiment_name
+│ │ │ ├── YYYY-MM-DD_HH-MM-SS
+│ │ │ │ └── ...
+│ │ │ └── ...
+│ │ └── ...
+│ │
+│ └── multiruns
+│ ├── experiment_name
+│ │ ├── YYYY-MM-DD_HH-MM-SS
+│ │ │ └── ...
+│ │ └── ...
+│ └── ...
```
-
-
You can change this structure by modifying paths in [hydra configuration](configs/mode).
diff --git a/configs/callbacks/default.yaml b/configs/callbacks/default.yaml
index 751d312..3c22ea0 100644
--- a/configs/callbacks/default.yaml
+++ b/configs/callbacks/default.yaml
@@ -18,7 +18,7 @@ early_stopping:
model_summary:
_target_: pytorch_lightning.callbacks.RichModelSummary
- max_depth: 1
+ max_depth: -1
rich_progress_bar:
_target_: pytorch_lightning.callbacks.RichProgressBar
diff --git a/configs/callbacks/wandb.yaml b/configs/callbacks/wandb.yaml
index c6ae21d..c4c1027 100644
--- a/configs/callbacks/wandb.yaml
+++ b/configs/callbacks/wandb.yaml
@@ -8,7 +8,7 @@ watch_model:
upload_code_as_artifact:
_target_: src.callbacks.wandb_callbacks.UploadCodeAsArtifact
- code_dir: ${work_dir}/src
+ code_dir: ${original_work_dir}/src
upload_ckpts_as_artifact:
_target_: src.callbacks.wandb_callbacks.UploadCheckpointsAsArtifact
diff --git a/configs/config.yaml b/configs/config.yaml
index 200ab5c..3aed9f7 100644
--- a/configs/config.yaml
+++ b/configs/config.yaml
@@ -3,23 +3,27 @@
# specify here default training configuration
defaults:
- _self_
- - trainer: default.yaml
- - model: mnist.yaml
- datamodule: mnist.yaml
+ - model: mnist.yaml
- callbacks: default.yaml
- - logger: null # set logger here or use command line (e.g. `python run.py logger=wandb`)
+ - logger: null # set logger here or use command line (e.g. `python run.py logger=tensorboard`)
+ - trainer: default.yaml
- # modes are special collections of config options for different purposes, e.g. debugging
- - mode: default.yaml
+ # logging folder path
+ - log_dir: default.yaml
# experiment configs allow for version control of specific configurations
- # for example, use them to store best hyperparameters for each combination of model and datamodule
+ # e.g. best hyperparameters for each combination of model and datamodule
- experiment: null
+ # debugging config (enable through command line, e.g. `python run.py debug=one_epoch)
+ - debug: null
+
# config for hyperparameter optimization
- hparams_search: null
# optional local config for machine/user specific settings
+ # it's optional since it doesn't need to exist and is excluded from version control
- optional local: default.yaml
# enable color logging
@@ -30,10 +34,10 @@ defaults:
# hydra hijacks working directory by changing it to the new log directory
# so it's useful to have this path as a special variable
# https://hydra.cc/docs/next/tutorials/basic/running_your_app/working_directory
-work_dir: ${hydra:runtime.cwd}
+original_work_dir: ${hydra:runtime.cwd}
# path to folder with data
-data_dir: ${work_dir}/data/
+data_dir: ${original_work_dir}/data/
# pretty print config at the start of the run using Rich library
print_config: True
@@ -41,12 +45,16 @@ print_config: True
# disable python warnings if they annoy you
ignore_warnings: True
+# set False to skip model training
+train: True
+
# evaluate on test set, using best model weights achieved during training
-# lightning chooses best weights based on metric specified in checkpoint callback
+# lightning chooses best weights based on the metric specified in checkpoint callback
test_after_training: True
# seed for random number generators in pytorch, numpy and python.random
seed: null
-# name of the run, should be used along with experiment mode
-name: null
+# default name for the experiment, determines logging folder path
+# (you can overwrite this name in experiment configs)
+name: "default"
diff --git a/configs/datamodule/mnist.yaml b/configs/datamodule/mnist.yaml
index cc9a005..1e049c7 100644
--- a/configs/datamodule/mnist.yaml
+++ b/configs/datamodule/mnist.yaml
@@ -3,5 +3,5 @@ _target_: src.datamodules.mnist_datamodule.MNISTDataModule
data_dir: ${data_dir} # data_dir is specified in config.yaml
batch_size: 64
train_val_test_split: [55_000, 5_000, 10_000]
-num_workers: 0
+num_workers: 4
pin_memory: False
diff --git a/configs/debug/default.yaml b/configs/debug/default.yaml
new file mode 100644
index 0000000..c864358
--- /dev/null
+++ b/configs/debug/default.yaml
@@ -0,0 +1,27 @@
+# @package _global_
+
+# default debugging setup, runs 1 full epoch
+
+defaults:
+ - override /log_dir: debug.yaml
+
+trainer:
+ max_epochs: 1
+ gpus: 0 # debuggers don't like gpus
+ detect_anomaly: true
+ track_grad_norm: 2
+
+datamodule:
+ num_workers: 0 # debuggers don't like multiprocessing
+ pin_memory: False
+
+# sets level of all command line loggers to 'DEBUG'
+# https://hydra.cc/docs/tutorials/basic/running_your_app/logging/
+hydra:
+ verbose: True
+
+ # use this to set level of only chosen command line loggers to 'DEBUG'
+ # verbose: [src.train, src.utils]
+
+# config is already printed by hydra when `hydra/verbose: True`
+print_config: False
diff --git a/configs/debug/limit_batches.yaml b/configs/debug/limit_batches.yaml
new file mode 100644
index 0000000..a115e90
--- /dev/null
+++ b/configs/debug/limit_batches.yaml
@@ -0,0 +1,12 @@
+# @package _global_
+
+# debugs by using only 1% of the data
+
+defaults:
+ - default.yaml
+
+trainer:
+ max_epochs: 3
+ limit_train_batches: 0.01
+ limit_val_batches: 0.01
+ limit_test_batches: 0.01
diff --git a/configs/debug/overfit.yaml b/configs/debug/overfit.yaml
new file mode 100644
index 0000000..2ce654b
--- /dev/null
+++ b/configs/debug/overfit.yaml
@@ -0,0 +1,10 @@
+# @package _global_
+
+# overfits to 3 batches
+
+defaults:
+ - default.yaml
+
+trainer:
+ max_epochs: 20
+ overfit_batches: 3
diff --git a/configs/debug/profiler.yaml b/configs/debug/profiler.yaml
new file mode 100644
index 0000000..84ec507
--- /dev/null
+++ b/configs/debug/profiler.yaml
@@ -0,0 +1,12 @@
+# @package _global_
+
+# debugs with execution time profiling
+
+defaults:
+ - default.yaml
+
+trainer:
+ max_epochs: 1
+ profiler: "simple"
+ # profiler: "advanced"
+ # profiler: "pytorch"
diff --git a/configs/debug/step.yaml b/configs/debug/step.yaml
new file mode 100644
index 0000000..7a3022e
--- /dev/null
+++ b/configs/debug/step.yaml
@@ -0,0 +1,9 @@
+# @package _global_
+
+# debugs by running 1 train, 1 validation and 1 test step
+
+defaults:
+ - default.yaml
+
+trainer:
+ fast_dev_run: true
diff --git a/configs/debug/test_only.yaml b/configs/debug/test_only.yaml
new file mode 100644
index 0000000..957b0b6
--- /dev/null
+++ b/configs/debug/test_only.yaml
@@ -0,0 +1,9 @@
+# @package _global_
+
+# debugs by running only test epoch
+
+defaults:
+ - default.yaml
+
+train: False
+test_after_training: True
diff --git a/configs/experiment/example.yaml b/configs/experiment/example.yaml
index eb440ab..ce4b360 100644
--- a/configs/experiment/example.yaml
+++ b/configs/experiment/example.yaml
@@ -4,24 +4,22 @@
# python run.py experiment=example
defaults:
- - override /mode: exp.yaml
- - override /trainer: default.yaml
- - override /model: mnist.yaml
- override /datamodule: mnist.yaml
+ - override /model: mnist.yaml
- override /callbacks: default.yaml
- override /logger: null
+ - override /trainer: default.yaml
# all parameters below will be merged with parameters from default configurations set above
# this allows you to overwrite only specified parameters
# name of the run determines folder name in logs
-# can also be accessed by loggers
-name: "example"
+name: "simple_dense_net"
seed: 12345
trainer:
- min_epochs: 1
+ min_epochs: 10
max_epochs: 10
gradient_clip_val: 0.5
@@ -33,10 +31,7 @@ model:
datamodule:
batch_size: 64
- train_val_test_split: [55_000, 5_000, 10_000]
logger:
- csv:
- name: csv/${name}
wandb:
- tags: ["mnist", "simple_dense_net"]
+ tags: ["mnist", "${name}"]
diff --git a/configs/log_dir/debug.yaml b/configs/log_dir/debug.yaml
new file mode 100644
index 0000000..83db732
--- /dev/null
+++ b/configs/log_dir/debug.yaml
@@ -0,0 +1,8 @@
+# @package _global_
+
+hydra:
+ run:
+ dir: logs/debugs/runs/${name}/${now:%Y-%m-%d}_${now:%H-%M-%S}
+ sweep:
+ dir: logs/debugs/multiruns/${name}/${now:%Y-%m-%d}_${now:%H-%M-%S}
+ subdir: ${hydra.job.num}
diff --git a/configs/log_dir/default.yaml b/configs/log_dir/default.yaml
new file mode 100644
index 0000000..12df3b8
--- /dev/null
+++ b/configs/log_dir/default.yaml
@@ -0,0 +1,8 @@
+# @package _global_
+
+hydra:
+ run:
+ dir: logs/experiments/runs/${name}/${now:%Y-%m-%d}_${now:%H-%M-%S}
+ sweep:
+ dir: logs/experiments/multiruns/${name}/${now:%Y-%m-%d}_${now:%H-%M-%S}
+ subdir: ${hydra.job.num}
diff --git a/configs/logger/csv.yaml b/configs/logger/csv.yaml
index 0f917e8..aaec6d7 100644
--- a/configs/logger/csv.yaml
+++ b/configs/logger/csv.yaml
@@ -4,5 +4,4 @@ csv:
_target_: pytorch_lightning.loggers.csv_logs.CSVLogger
save_dir: "."
name: "csv/"
- version: ${name}
prefix: ""
diff --git a/configs/logger/wandb.yaml b/configs/logger/wandb.yaml
index 4c37ff7..df6024b 100644
--- a/configs/logger/wandb.yaml
+++ b/configs/logger/wandb.yaml
@@ -3,7 +3,7 @@
wandb:
_target_: pytorch_lightning.loggers.wandb.WandbLogger
project: "template-tests"
- name: ${name}
+ # name: ${name}
save_dir: "."
offline: False # set True to store all logs only locally
id: null # pass correct id to resume experiment!
diff --git a/configs/mode/debug.yaml b/configs/mode/debug.yaml
deleted file mode 100644
index a8bfbda..0000000
--- a/configs/mode/debug.yaml
+++ /dev/null
@@ -1,29 +0,0 @@
-# @package _global_
-
-# debug mode sets name of the logging folder to 'logs/debug/...'
-# enables trainer debug options
-# also sets level od command line logger to DEBUG
-# example usage:
-# `python run.py mode=debug`
-
-defaults:
- - override /trainer: debug.yaml
-
-debug_mode: True
-
-hydra:
- # sets level of all command line loggers to 'DEBUG'
- verbose: True
-
- # https://hydra.cc/docs/tutorials/basic/running_your_app/logging/
- # use this to set level of only chosen command line loggers to 'DEBUG'
- # verbose: [src.train, src.utils]
-
- run:
- dir: logs/debug/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
- sweep:
- dir: logs/debug/multiruns/${now:%Y-%m-%d}/${now:%H-%M-%S}
- subdir: ${hydra.job.num}
-
-# disable rich config printing, since it will be already printed by hydra when `verbose: True`
-print_config: False
diff --git a/configs/mode/default.yaml b/configs/mode/default.yaml
deleted file mode 100644
index e002131..0000000
--- a/configs/mode/default.yaml
+++ /dev/null
@@ -1,13 +0,0 @@
-# @package _global_
-
-# default running mode
-
-default_mode: True
-
-hydra:
- # default output paths for all file logs
- run:
- dir: logs/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
- sweep:
- dir: logs/multiruns/${now:%Y-%m-%d}/${now:%H-%M-%S}
- subdir: ${hydra.job.num}
diff --git a/configs/mode/exp.yaml b/configs/mode/exp.yaml
deleted file mode 100644
index 545cb81..0000000
--- a/configs/mode/exp.yaml
+++ /dev/null
@@ -1,17 +0,0 @@
-# @package _global_
-
-# experiment mode sets name of the logging folder to the experiment name
-# can also be used to name the run in the logger
-# example usage:
-# `python run.py mode=exp name=some_name`
-
-experiment_mode: True
-
-name: ???
-
-hydra:
- run:
- dir: logs/experiments/${name}/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
- sweep:
- dir: logs/experiments/${name}/multiruns/${now:%Y-%m-%d}/${now:%H-%M-%S}
- subdir: ${hydra.job.num}
diff --git a/configs/trainer/ddp.yaml b/configs/trainer/ddp.yaml
index b798479..8a11249 100644
--- a/configs/trainer/ddp.yaml
+++ b/configs/trainer/ddp.yaml
@@ -3,3 +3,4 @@ defaults:
gpus: 4
strategy: ddp
+sync_batchnorm: True
diff --git a/configs/trainer/debug.yaml b/configs/trainer/debug.yaml
deleted file mode 100644
index 981cf14..0000000
--- a/configs/trainer/debug.yaml
+++ /dev/null
@@ -1,19 +0,0 @@
-defaults:
- - default.yaml
-
-gpus: 0
-
-min_epochs: 1
-max_epochs: 2
-
-# prints
-profiler: null
-
-# debugs
-fast_dev_run: true
-overfit_batches: 0
-limit_train_batches: 1.0
-limit_val_batches: 1.0
-limit_test_batches: 1.0
-track_grad_norm: -1
-detect_anomaly: true
diff --git a/configs/trainer/default.yaml b/configs/trainer/default.yaml
index f8f1bf1..0db9f11 100644
--- a/configs/trainer/default.yaml
+++ b/configs/trainer/default.yaml
@@ -5,7 +5,7 @@ gpus: 0
min_epochs: 1
max_epochs: 10
-resume_from_checkpoint: null
-
# number of validation steps to execute at the beginning of the training
-num_sanity_val_steps: 0
+# num_sanity_val_steps: 0
+
+resume_from_checkpoint: null
diff --git a/run.py b/run.py
index 339b76a..76a02fa 100644
--- a/run.py
+++ b/run.py
@@ -15,11 +15,7 @@ def main(config: DictConfig):
from src.train import train
from src import utils
- # A couple of optional utilities:
- # - disabling python warnings
- # - forcing debug-friendly configuration
- # - verifying experiment name is set when running in experiment mode
- # You can safely get rid of this line if you don't want those
+ # Applies optional utilities
utils.extras(config)
# Pretty print config using Rich library
diff --git a/src/datamodules/datasets/__init__.py b/src/datamodules/components/__init__.py
similarity index 100%
rename from src/datamodules/datasets/__init__.py
rename to src/datamodules/components/__init__.py
diff --git a/src/datamodules/mnist_datamodule.py b/src/datamodules/mnist_datamodule.py
index 1b705a2..705b63c 100644
--- a/src/datamodules/mnist_datamodule.py
+++ b/src/datamodules/mnist_datamodule.py
@@ -43,9 +43,6 @@ class MNISTDataModule(LightningDataModule):
[transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))]
)
- # self.dims is returned when you call datamodule.size()
- self.dims = (1, 28, 28)
-
self.data_train: Optional[Dataset] = None
self.data_val: Optional[Dataset] = None
self.data_test: Optional[Dataset] = None
diff --git a/src/train.py b/src/train.py
index 7ff6e2c..c74babe 100644
--- a/src/train.py
+++ b/src/train.py
@@ -73,8 +73,9 @@ def train(config: DictConfig) -> Optional[float]:
)
# Train the model
- log.info("Starting training!")
- trainer.fit(model=model, datamodule=datamodule)
+ if config.get("train"):
+ log.info("Starting training!")
+ trainer.fit(model=model, datamodule=datamodule)
# Get metric score for hyperparameter optimization
optimized_metric = config.get("optimized_metric")
@@ -88,7 +89,8 @@ def train(config: DictConfig) -> Optional[float]:
# Test the model
if config.get("test_after_training") and not config.trainer.get("fast_dev_run"):
log.info("Starting testing!")
- trainer.test(model=model, datamodule=datamodule, ckpt_path="best")
+ ckpt_path = None if not config.get("train") else "best"
+ trainer.test(model=model, datamodule=datamodule, ckpt_path=ckpt_path)
# Make sure everything closed properly
log.info("Finalizing!")
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index b8f6501..1c6bf1d 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -31,12 +31,7 @@ def get_logger(name=__name__) -> logging.Logger:
def extras(config: DictConfig) -> None:
- """A couple of optional utilities, controlled by main config file:
- - disabling warnings
- - forcing debug friendly configuration
- - verifying experiment name is set when running in experiment mode
-
- Modifies DictConfig in place.
+ """Optional utilities, controlled by hydra config.
Args:
config (DictConfig): Configuration composed by Hydra.
@@ -49,26 +44,6 @@ def extras(config: DictConfig) -> None:
log.info("Disabling python warnings! ")
warnings.filterwarnings("ignore")
- # verify experiment name is set when running in experiment mode
- if config.get("experiment_mode") and not config.get("name"):
- log.info(
- "Running in experiment mode without the experiment name specified! "
- "Use `python run.py mode=exp name=experiment_name`"
- )
- log.info("Exiting...")
- exit()
-
- # force debugger friendly configuration if
- # debuggers don't like GPUs and multiprocessing
- if config.trainer.get("fast_dev_run"):
- log.info("Forcing debugger friendly configuration! ")
- if config.trainer.get("gpus"):
- config.trainer.gpus = 0
- if config.datamodule.get("pin_memory"):
- config.datamodule.pin_memory = False
- if config.datamodule.get("num_workers"):
- config.datamodule.num_workers = 0
-
@rank_zero_only
def print_config(
@@ -122,7 +97,7 @@ def log_hyperparameters(
callbacks: List[pl.Callback],
logger: List[pl.loggers.LightningLoggerBase],
) -> None:
- """This method controls which parameters from Hydra config are saved by Lightning loggers.
+ """Controls which hyperparameters are saved by Lightning loggers.
Additionaly saves:
- number of model parameters
@@ -130,7 +105,7 @@ def log_hyperparameters(
hparams = {}
- # choose which parts of hydra config will be saved to loggers
+ # choose which parts of hydra config are saved by loggers
hparams["trainer"] = config["trainer"]
hparams["model"] = config["model"]
hparams["datamodule"] = config["datamodule"]