Refactoring configs (#248)
- make every run be an experiment by default - deprecate `mode` configs - introduce `debug` configs - introduce `log_dir` configs - remove unnecessary utilities from `utils.extras()` - add config flag for skipping training - update README.md
This commit is contained in:
1 parent
2ff8e053bf
commit
19f5454d13
27 files changed
+210
-238
No files matched your search
@@ -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
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Use different running modes</b></summary>
|
||||
|
||||
```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'
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Train model with chosen experiment config</b></summary>
|
||||
|
||||
> Experiment configurations are placed in [configs/experiment/](configs/experiment/).
|
||||
|
||||
```bash
|
||||
python run.py experiment=example_simple
|
||||
python run.py experiment=example
|
||||
```
|
||||
|
||||
</details>
|
||||
@@ -286,15 +271,18 @@ python run.py +trainer.max_time="00:12:00:00"
|
||||
<details>
|
||||
<summary><b>Easily debug</b></summary>
|
||||
|
||||
```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"
|
||||
```
|
||||
|
||||
</details>
|
||||
@@ -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}"]
|
||||
```
|
||||
|
||||
</details>
|
||||
@@ -597,62 +597,44 @@ hydra:
|
||||
**Hydra creates new working directory for every executed run.** <br>
|
||||
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:
|
||||
|
||||
<details>
|
||||
<summary><b>Show logs structure</b></summary>
|
||||
|
||||
```
|
||||
├── 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
|
||||
│ │ │ └── ...
|
||||
│ │ └── ...
|
||||
│ └── ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
You can change this structure by modifying paths in [hydra configuration](configs/mode).
|
||||
|
||||
<br>
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
+19
-11
@@ -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"
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,10 @@
|
||||
# @package _global_
|
||||
|
||||
# overfits to 3 batches
|
||||
|
||||
defaults:
|
||||
- default.yaml
|
||||
|
||||
trainer:
|
||||
max_epochs: 20
|
||||
overfit_batches: 3
|
||||
@@ -0,0 +1,12 @@
|
||||
# @package _global_
|
||||
|
||||
# debugs with execution time profiling
|
||||
|
||||
defaults:
|
||||
- default.yaml
|
||||
|
||||
trainer:
|
||||
max_epochs: 1
|
||||
profiler: "simple"
|
||||
# profiler: "advanced"
|
||||
# profiler: "pytorch"
|
||||
@@ -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
|
||||
@@ -0,0 +1,9 @@
|
||||
# @package _global_
|
||||
|
||||
# debugs by running only test epoch
|
||||
|
||||
defaults:
|
||||
- default.yaml
|
||||
|
||||
train: False
|
||||
test_after_training: True
|
||||
@@ -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}"]
|
||||
@@ -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}
|
||||
@@ -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}
|
||||
@@ -4,5 +4,4 @@ csv:
|
||||
_target_: pytorch_lightning.loggers.csv_logs.CSVLogger
|
||||
save_dir: "."
|
||||
name: "csv/"
|
||||
version: ${name}
|
||||
prefix: ""
|
||||
@@ -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!
|
||||
|
||||
@@ -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
|
||||
@@ -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}
|
||||
@@ -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}
|
||||
@@ -3,3 +3,4 @@ defaults:
|
||||
|
||||
gpus: 4
|
||||
strategy: ddp
|
||||
sync_batchnorm: True
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
File renamed without changes.
@@ -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
|
||||
|
||||
+5
-3
@@ -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!")
|
||||
|
||||
+3
-28
@@ -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! <config.ignore_warnings=True>")
|
||||
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 <config.trainer.fast_dev_run=True>
|
||||
# debuggers don't like GPUs and multiprocessing
|
||||
if config.trainer.get("fast_dev_run"):
|
||||
log.info("Forcing debugger friendly configuration! <config.trainer.fast_dev_run=True>")
|
||||
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"]
|
||||
|
||||
Reference in new issue
Block a user