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:
ashleve authored and GitHub committed 2022-02-18 01:38:04 +01:00
1 parent 2ff8e053bf
commit 19f5454d13
27 files changed
+210 -238

No files matched your search

+74 -92
View File
@@ -66,11 +66,12 @@ The directory structure of new project looks like this:
├── configs <- Hydra configuration files ├── configs <- Hydra configuration files
│ ├── callbacks <- Callbacks configs │ ├── callbacks <- Callbacks configs
│ ├── datamodule <- Datamodule configs │ ├── datamodule <- Datamodule configs
│ ├── debug <- Debugging configs
│ ├── experiment <- Experiment configs │ ├── experiment <- Experiment configs
│ ├── hparams_search <- Hyperparameter search configs │ ├── hparams_search <- Hyperparameter search configs
│ ├── local <- Local configs │ ├── local <- Local configs
│ ├── log_dir <- Logging directory configs
│ ├── logger <- Logger configs │ ├── logger <- Logger configs
│ ├── mode <- Running mode configs
│ ├── model <- Model configs │ ├── model <- Model configs
│ ├── trainer <- Trainer configs │ ├── trainer <- Trainer configs
│ │ │ │
@@ -220,29 +221,13 @@ python run.py logger=wandb
</details> </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> <details>
<summary><b>Train model with chosen experiment config</b></summary> <summary><b>Train model with chosen experiment config</b></summary>
> Experiment configurations are placed in [configs/experiment/](configs/experiment/). > Experiment configurations are placed in [configs/experiment/](configs/experiment/).
```bash ```bash
python run.py experiment=example_simple python run.py experiment=example
``` ```
</details> </details>
@@ -286,15 +271,18 @@ python run.py +trainer.max_time="00:12:00:00"
<details> <details>
<summary><b>Easily debug</b></summary> <summary><b>Easily debug</b></summary>
```bash > Visit [configs/debug/](configs/debug/) for different debugging configs.
# 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
# enable trainer debugging options specified in `configs/trainer/debug.yaml` ```bash
python run.py trainer=debug # 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 # run 1 train, val and test loop, using only 1 batch
python run.py +trainer.fast_dev_run=true 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 ```yaml
# specify here default training configuration # specify here default training configuration
defaults: defaults:
- trainer: default.yaml
- model: mnist.yaml
- datamodule: mnist.yaml - datamodule: mnist.yaml
- model: mnist.yaml
- callbacks: default.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 # logging folder path
- mode: default.yaml - log_dir: default.yaml
# experiment configs allow for version control of specific configurations # experiment configs allow for version control of specific configurations
# e.g. best hyperparameters for each combination of model and datamodule
- experiment: null - experiment: null
# debugging config (enable through command line, e.g. `python run.py debug=one_epoch)
- debug: null
# config for hyperparameter optimization # config for hyperparameter optimization
- hparams_search: null - hparams_search: null
# optional local config for machine/user specific settings # 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 - optional local: default.yaml
# enable color logging
- override hydra/hydra_logging: colorlog
- override hydra/job_logging: colorlog
# path to original working directory # path to original working directory
# hydra hijacks working directory by changing it to the new log 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 # so it's useful to have this path as a special variable
# https://hydra.cc/docs/next/tutorials/basic/running_your_app/working_directory # 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 # 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 # pretty print config at the start of the run using Rich library
print_config: True print_config: True
@@ -485,12 +482,19 @@ print_config: True
# disable python warnings if they annoy you # disable python warnings if they annoy you
ignore_warnings: True ignore_warnings: True
# set False to skip model training
train: True
# evaluate on test set, using best model weights achieved during training # 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 test_after_training: True
# seed for random number generators in pytorch, numpy and python.random # seed for random number generators in pytorch, numpy and python.random
seed: null seed: null
# default name for the experiment, determines logging folder path
# (you can overwrite this name in experiment configs)
name: "default"
``` ```
</details> </details>
@@ -511,23 +515,22 @@ For example, you can use them to version control best hyperparameters for each c
# python run.py experiment=example # python run.py experiment=example
defaults: defaults:
- override /mode: exp.yaml
- override /trainer: default.yaml
- override /model: mnist.yaml
- override /datamodule: mnist.yaml - override /datamodule: mnist.yaml
- override /model: mnist.yaml
- override /callbacks: default.yaml - override /callbacks: default.yaml
- override /logger: null - override /logger: null
- override /trainer: default.yaml
# all parameters below will be merged with parameters from default configurations set above # 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 # name of the run determines folder name in logs
# can also be accessed by loggers name: "simple_dense_net"
name: "example"
seed: 12345 seed: 12345
trainer: trainer:
min_epochs: 1 min_epochs: 10
max_epochs: 10 max_epochs: 10
gradient_clip_val: 0.5 gradient_clip_val: 0.5
@@ -539,13 +542,10 @@ model:
datamodule: datamodule:
batch_size: 64 batch_size: 64
train_val_test_split: [55_000, 5_000, 10_000]
logger: logger:
csv:
name: csv/${name}
wandb: wandb:
tags: ["mnist", "simple_dense_net"] tags: ["mnist", "${name}"]
``` ```
</details> </details>
@@ -597,62 +597,44 @@ hydra:
**Hydra creates new working directory for every executed run.** <br> **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: 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 ├── logs
│ ├── experiments # Folder for logs generated by experiments │ ├── experiments # Folder for the logs generated by experiments
│ │ ├── experiment_name # Name of the experiment │ │ ├── runs # Folder for single runs
│ │ │ ├── runs │ │ │ ├── experiment_name # Experiment name
│ │ │ │ ├── YYYY-MM-DD # Date of execution │ │ │ │ ├── YYYY-MM-DD_HH-MM-SS # Datetime of the run
│ │ │ │ │ ├── HH-MM-SS # Time of execution │ │ │ │ │ ├── .hydra # Hydra logs
│ │ │ │ │ │ ├── .hydra # Hydra logs │ │ │ │ │ ├── wandb # Weights&Biases logs
│ │ │ │ │ │ ├── wandb # Weights&Biases logs │ │ │ │ │ ├── checkpoints # Training checkpoints
│ │ │ │ │ │ ├── checkpoints # Training checkpoints │ │ │ │ │ └── ... # Any other thing saved during training
│ │ │ │ │ │ └── ... # 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
│ │ │ │ └── ... │ │ │ │ └── ...
│ │ │ └── ... │ │ │ └── ...
│ │ └── multiruns │ │ │
│ │ ├── YYYY-MM-DD │ │ └── multiruns # Folder for multiruns
│ │ │ ├── HH-MM-SS │ │ ├── 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 │ └── debugs # Folder for the logs generated during debugging
│ │ ├── YYYY-MM-DD | ├── runs
│ │ │ ├── HH-MM-SS | │ ├── experiment_name
│ │ │ └── ... │ │ │ ├── YYYY-MM-DD_HH-MM-SS
│ │ └── ... │ │ │ │ └── ...
│ │ │ │ │ └── ...
│ └── multiruns # Folder for logs generated by normal multiruns (sweeps) │ │ └── ...
│ ├── 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). You can change this structure by modifying paths in [hydra configuration](configs/mode).
<br> <br>
+1 -1
View File
@@ -18,7 +18,7 @@ early_stopping:
model_summary: model_summary:
_target_: pytorch_lightning.callbacks.RichModelSummary _target_: pytorch_lightning.callbacks.RichModelSummary
max_depth: 1 max_depth: -1
rich_progress_bar: rich_progress_bar:
_target_: pytorch_lightning.callbacks.RichProgressBar _target_: pytorch_lightning.callbacks.RichProgressBar
+1 -1
View File
@@ -8,7 +8,7 @@ watch_model:
upload_code_as_artifact: upload_code_as_artifact:
_target_: src.callbacks.wandb_callbacks.UploadCodeAsArtifact _target_: src.callbacks.wandb_callbacks.UploadCodeAsArtifact
code_dir: ${work_dir}/src code_dir: ${original_work_dir}/src
upload_ckpts_as_artifact: upload_ckpts_as_artifact:
_target_: src.callbacks.wandb_callbacks.UploadCheckpointsAsArtifact _target_: src.callbacks.wandb_callbacks.UploadCheckpointsAsArtifact
+19 -11
View File
@@ -3,23 +3,27 @@
# specify here default training configuration # specify here default training configuration
defaults: defaults:
- _self_ - _self_
- trainer: default.yaml
- model: mnist.yaml
- datamodule: mnist.yaml - datamodule: mnist.yaml
- model: mnist.yaml
- callbacks: default.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 # logging folder path
- mode: default.yaml - log_dir: default.yaml
# experiment configs allow for version control of specific configurations # 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 - experiment: null
# debugging config (enable through command line, e.g. `python run.py debug=one_epoch)
- debug: null
# config for hyperparameter optimization # config for hyperparameter optimization
- hparams_search: null - hparams_search: null
# optional local config for machine/user specific settings # 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 - optional local: default.yaml
# enable color logging # enable color logging
@@ -30,10 +34,10 @@ defaults:
# hydra hijacks working directory by changing it to the new log 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 # so it's useful to have this path as a special variable
# https://hydra.cc/docs/next/tutorials/basic/running_your_app/working_directory # 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 # 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 # pretty print config at the start of the run using Rich library
print_config: True print_config: True
@@ -41,12 +45,16 @@ print_config: True
# disable python warnings if they annoy you # disable python warnings if they annoy you
ignore_warnings: True ignore_warnings: True
# set False to skip model training
train: True
# evaluate on test set, using best model weights achieved during training # 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 test_after_training: True
# seed for random number generators in pytorch, numpy and python.random # seed for random number generators in pytorch, numpy and python.random
seed: null seed: null
# name of the run, should be used along with experiment mode # default name for the experiment, determines logging folder path
name: null # (you can overwrite this name in experiment configs)
name: "default"
+1 -1
View File
@@ -3,5 +3,5 @@ _target_: src.datamodules.mnist_datamodule.MNISTDataModule
data_dir: ${data_dir} # data_dir is specified in config.yaml data_dir: ${data_dir} # data_dir is specified in config.yaml
batch_size: 64 batch_size: 64
train_val_test_split: [55_000, 5_000, 10_000] train_val_test_split: [55_000, 5_000, 10_000]
num_workers: 0 num_workers: 4
pin_memory: False pin_memory: False
+27
View File
@@ -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
+12
View File
@@ -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
+10
View File
@@ -0,0 +1,10 @@
# @package _global_
# overfits to 3 batches
defaults:
- default.yaml
trainer:
max_epochs: 20
overfit_batches: 3
+12
View File
@@ -0,0 +1,12 @@
# @package _global_
# debugs with execution time profiling
defaults:
- default.yaml
trainer:
max_epochs: 1
profiler: "simple"
# profiler: "advanced"
# profiler: "pytorch"
+9
View File
@@ -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
+9
View File
@@ -0,0 +1,9 @@
# @package _global_
# debugs by running only test epoch
defaults:
- default.yaml
train: False
test_after_training: True
+5 -10
View File
@@ -4,24 +4,22 @@
# python run.py experiment=example # python run.py experiment=example
defaults: defaults:
- override /mode: exp.yaml
- override /trainer: default.yaml
- override /model: mnist.yaml
- override /datamodule: mnist.yaml - override /datamodule: mnist.yaml
- override /model: mnist.yaml
- override /callbacks: default.yaml - override /callbacks: default.yaml
- override /logger: null - override /logger: null
- override /trainer: default.yaml
# all parameters below will be merged with parameters from default configurations set above # all parameters below will be merged with parameters from default configurations set above
# this allows you to overwrite only specified parameters # this allows you to overwrite only specified parameters
# name of the run determines folder name in logs # name of the run determines folder name in logs
# can also be accessed by loggers name: "simple_dense_net"
name: "example"
seed: 12345 seed: 12345
trainer: trainer:
min_epochs: 1 min_epochs: 10
max_epochs: 10 max_epochs: 10
gradient_clip_val: 0.5 gradient_clip_val: 0.5
@@ -33,10 +31,7 @@ model:
datamodule: datamodule:
batch_size: 64 batch_size: 64
train_val_test_split: [55_000, 5_000, 10_000]
logger: logger:
csv:
name: csv/${name}
wandb: wandb:
tags: ["mnist", "simple_dense_net"] tags: ["mnist", "${name}"]
+8
View File
@@ -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}
+8
View File
@@ -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}
-1
View File
@@ -4,5 +4,4 @@ csv:
_target_: pytorch_lightning.loggers.csv_logs.CSVLogger _target_: pytorch_lightning.loggers.csv_logs.CSVLogger
save_dir: "." save_dir: "."
name: "csv/" name: "csv/"
version: ${name}
prefix: "" prefix: ""
+1 -1
View File
@@ -3,7 +3,7 @@
wandb: wandb:
_target_: pytorch_lightning.loggers.wandb.WandbLogger _target_: pytorch_lightning.loggers.wandb.WandbLogger
project: "template-tests" project: "template-tests"
name: ${name} # name: ${name}
save_dir: "." save_dir: "."
offline: False # set True to store all logs only locally offline: False # set True to store all logs only locally
id: null # pass correct id to resume experiment! id: null # pass correct id to resume experiment!
-29
View File
@@ -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
-13
View File
@@ -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}
-17
View File
@@ -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}
+1
View File
@@ -3,3 +3,4 @@ defaults:
gpus: 4 gpus: 4
strategy: ddp strategy: ddp
sync_batchnorm: True
-19
View File
@@ -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
+3 -3
View File
@@ -5,7 +5,7 @@ gpus: 0
min_epochs: 1 min_epochs: 1
max_epochs: 10 max_epochs: 10
resume_from_checkpoint: null
# number of validation steps to execute at the beginning of the training # 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
+1 -5
View File
@@ -15,11 +15,7 @@ def main(config: DictConfig):
from src.train import train from src.train import train
from src import utils from src import utils
# A couple of optional utilities: # Applies 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
utils.extras(config) utils.extras(config)
# Pretty print config using Rich library # Pretty print config using Rich library
File renamed without changes.
-3
View File
@@ -43,9 +43,6 @@ class MNISTDataModule(LightningDataModule):
[transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))] [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_train: Optional[Dataset] = None
self.data_val: Optional[Dataset] = None self.data_val: Optional[Dataset] = None
self.data_test: Optional[Dataset] = None self.data_test: Optional[Dataset] = None
+5 -3
View File
@@ -73,8 +73,9 @@ def train(config: DictConfig) -> Optional[float]:
) )
# Train the model # Train the model
log.info("Starting training!") if config.get("train"):
trainer.fit(model=model, datamodule=datamodule) log.info("Starting training!")
trainer.fit(model=model, datamodule=datamodule)
# Get metric score for hyperparameter optimization # Get metric score for hyperparameter optimization
optimized_metric = config.get("optimized_metric") optimized_metric = config.get("optimized_metric")
@@ -88,7 +89,8 @@ def train(config: DictConfig) -> Optional[float]:
# Test the model # Test the model
if config.get("test_after_training") and not config.trainer.get("fast_dev_run"): if config.get("test_after_training") and not config.trainer.get("fast_dev_run"):
log.info("Starting testing!") 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 # Make sure everything closed properly
log.info("Finalizing!") log.info("Finalizing!")
+3 -28
View File
@@ -31,12 +31,7 @@ def get_logger(name=__name__) -> logging.Logger:
def extras(config: DictConfig) -> None: def extras(config: DictConfig) -> None:
"""A couple of optional utilities, controlled by main config file: """Optional utilities, controlled by hydra config.
- disabling warnings
- forcing debug friendly configuration
- verifying experiment name is set when running in experiment mode
Modifies DictConfig in place.
Args: Args:
config (DictConfig): Configuration composed by Hydra. config (DictConfig): Configuration composed by Hydra.
@@ -49,26 +44,6 @@ def extras(config: DictConfig) -> None:
log.info("Disabling python warnings! <config.ignore_warnings=True>") log.info("Disabling python warnings! <config.ignore_warnings=True>")
warnings.filterwarnings("ignore") 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 @rank_zero_only
def print_config( def print_config(
@@ -122,7 +97,7 @@ def log_hyperparameters(
callbacks: List[pl.Callback], callbacks: List[pl.Callback],
logger: List[pl.loggers.LightningLoggerBase], logger: List[pl.loggers.LightningLoggerBase],
) -> None: ) -> None:
"""This method controls which parameters from Hydra config are saved by Lightning loggers. """Controls which hyperparameters are saved by Lightning loggers.
Additionaly saves: Additionaly saves:
- number of model parameters - number of model parameters
@@ -130,7 +105,7 @@ def log_hyperparameters(
hparams = {} 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["trainer"] = config["trainer"]
hparams["model"] = config["model"] hparams["model"] = config["model"]
hparams["datamodule"] = config["datamodule"] hparams["datamodule"] = config["datamodule"]