From 5f57eb787599f31831068794681b6d7a1a713050 Mon Sep 17 00:00:00 2001 From: hobogalaxy Date: Wed, 10 Mar 2021 17:48:23 +0100 Subject: [PATCH] fix optuna config and prevent double logging --- README.md | 28 +++++++--------------------- configs/config_optuna.yaml | 2 +- src/utils/template_utils.py | 4 ++++ train.py | 1 - 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 45f3dbe..aaf7dbd 100644 --- a/README.md +++ b/README.md @@ -237,9 +237,6 @@ python train.py callbacks=default_callbacks > *PyTorch Lightning provides about [40+ useful trainer flags](https://pytorch-lightning.readthedocs.io/en/latest/common/trainer.html#trainer-flags).* ```yaml -# accumulate gradients from 10 training steps -python train.py trainer.accumulate_grad_batches=10 - # gradient clipping may be enabled to avoid exploding gradients python train.py trainer.gradient_clip_val=0.5 @@ -248,6 +245,9 @@ python train.py trainer.stochastic_weight_avg=True # run validation loop 4 times during a training epoch python train.py trainer.val_check_interval=0.25 + +# accumulate gradients +python train.py trainer.accumulate_grad_batches=10 ``` @@ -267,8 +267,8 @@ python train.py trainer.weights_summary="full" # print execution time profiling after training ends python train.py trainer.profiler="simple" -# try overfitting to 10 batches -python train.py trainer.overfit_batches=10 +# try overfitting to 1 batch +python train.py trainer.overfit_batches=1 trainer.max_epochs=20 # use only 20% of the data python train.py trainer.limit_train_batches=0.2 \ @@ -297,7 +297,7 @@ python train.py trainer.resume_from_checkpoint="/absolute/path/to/ckpt/name.ckpt ```yaml # this will run 6 experiments one after the other, # each with different combination of batch_size and learning rate -python train.py -m datamodule.batch_size=32,64,128 model.lr=0.001,0.0005 +python train.py -m datamodule.batch_size=32,64,128 optimizer.lr=0.001,0.0005 ``` > *Currently sweeps aren't failure resistant (if one job crashes than the whole sweep crashes), but it will be supported in future Hydra release.* @@ -708,20 +708,7 @@ Train model with default configuration: python train.py ``` -Train model with chosen logger like Weights&Biases: -```yaml -# set project and entity names in `configs/logger/wandb.yaml` -wandb: - project: "your_project_name" - entity: "your_wandb_team_name" -``` - -```yaml -# train model with Weights&Biases -python train.py logger=wandb -``` - -Train model with chosen experiment config: +Train model with chosen experiment configuration: ```yaml # experiment configurations are placed in folder `configs/experiment/` python train.py +experiment=exp_example_simple @@ -736,7 +723,6 @@ To train on GPU: ```yaml python train.py trainer.gpus=1 ``` -
diff --git a/configs/config_optuna.yaml b/configs/config_optuna.yaml index e9e7d12..50664c0 100644 --- a/configs/config_optuna.yaml +++ b/configs/config_optuna.yaml @@ -41,7 +41,7 @@ hydra: datamodule.batch_size: type: categorical choices: [32, 64, 128] - model.lr: + optimizer.lr: type: float low: 0.0001 high: 0.2 diff --git a/src/utils/template_utils.py b/src/utils/template_utils.py index 1b63210..852b073 100644 --- a/src/utils/template_utils.py +++ b/src/utils/template_utils.py @@ -24,6 +24,10 @@ def extras(config: DictConfig): # make it possible to add new keys to config OmegaConf.set_struct(config, False) + + # fix double logging bug (this will be removed when lightning releases patch) + pl_logger = logging.getLogger('lightning') + pl_logger.propagate = False # [OPTIONAL] Disable python warnings if if config.get("disable_warnings"): diff --git a/train.py b/train.py index 6cde3c9..2364a2a 100644 --- a/train.py +++ b/train.py @@ -107,7 +107,6 @@ def train(config: DictConfig): @hydra.main(config_path="configs/", config_name="config.yaml") def main(config: DictConfig): - pass return train(config)