From cc4e896cd2df301195d0af0617736c8d13135082 Mon Sep 17 00:00:00 2001 From: hobogalaxy Date: Sat, 21 Nov 2020 04:53:15 +0100 Subject: [PATCH 1/2] add config explanation to readme --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index cdfeb59..29de4d3 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,53 @@ Installation command generator: https://pytorch.org/get-started/locally/
+## [config.yaml](project/config.yaml) parameters explanation: +``` +num_of_gpus: -1 <- -1 means use all gpus available on your machine, 0 means train on cpu + +hparams: <- you can add any parameters here and then acces them in your network model or datamodule + max_epochs: 3 + batch_size: 64 + lr: 0.001 + weight_decay: 0.000001 <- L2 normalization set in optimizer + gradient_clip_val: 0.5 <- gradient clipping value (0 means don’t clip), helps with exploding gradient issues + accumulate_grad_batches: 1 <- perform optimisation after accumulating gradient from n batches + +resume: + resume_from_ckpt: False <- set to True if you want to resume + wandb_run_id: "8uuomodb" <- id of wandb run + ckpt_path: "epoch=2.ckpt" <- lightning checkpoint path + +loggers: + wandb: + project: "hackathon_template_test" <- wandb project name + team: "kino" <- entity name (your username or team name you belong to) + group: None + job_type: "train" + tags: [] + log_model: True <- True if you want to automatically upload your model to wandb at the end of training + offline: False <- True if you don't want to send any data to wandb server + +callbacks: + checkpoint: + monitor: "val_acc" <- name of the logged metric that determines when ckpt is saved + save_top_k: 1 <- save k best models (determined by above metric) + save_last: True <- additionaly always save model from last epoch + mode: "max" # "min" <- save models with best minimum or maximum metrics score + early_stop: + monitor: "val_acc" <- name of the logged metric that determines when training is stopped + patience: 100 <- for how long metric needs to not improve in order to stop training + mode: "max" # "min" + +printing: + progress_bar_refresh_rate: 5 <- refresh rate of training bar in terminal + weights_summary: "top" # "full" <- print summary of model an the beginning of the run + profiler: False <- True will print mean execution time of all methods at the end of the training + +``` +
+ + ## Useful tips - Useful pl.Trainer() parameters: - gpus=-1 - use all gpus available on your machine From 94cb2375c1907b53101d00159c8f2369c2093011 Mon Sep 17 00:00:00 2001 From: hobogalaxy Date: Sat, 21 Nov 2020 04:53:31 +0100 Subject: [PATCH 2/2] some silly tweaks --- project/config.yaml | 14 +++++++++----- project/train.py | 2 +- project/training_modules/lightning_wrapper.py | 7 +------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/project/config.yaml b/project/config.yaml index ef2b1d6..df455f1 100644 --- a/project/config.yaml +++ b/project/config.yaml @@ -1,19 +1,23 @@ num_of_gpus: -1 hparams: + # these hyperparameters should always be in this file max_epochs: 3 batch_size: 64 lr: 0.001 - accumulate_grad_batches: 1 - gradient_clip_val: 0.5 - output_size: 10 weight_decay: 0.000001 - split_ratio: 0.9 + gradient_clip_val: 0.5 + accumulate_grad_batches: 1 + + # these hyperparameters are custom, you can add here anything + train_val_split_ratio: 0.9 + output_size: 10 lin1_size: 256 lin2_size: 256 lin3_size: 128 -resume: + +resume: # this is for resuming training from lightning checkpoint resume_from_ckpt: False wandb_run_id: "8uuomodb" ckpt_path: "checkpoints/epoch=2.ckpt" diff --git a/project/train.py b/project/train.py index 2976d0a..65825a6 100644 --- a/project/train.py +++ b/project/train.py @@ -13,7 +13,7 @@ def train(config): # Init data module datamodule = MNISTDataModule( batch_size=config["hparams"]["batch_size"], - split_ratio=config["hparams"]["split_ratio"] + split_ratio=config["hparams"]["train_val_split_ratio"] ) datamodule.prepare_data() datamodule.setup() diff --git a/project/training_modules/lightning_wrapper.py b/project/training_modules/lightning_wrapper.py index e44aaf3..53a290a 100644 --- a/project/training_modules/lightning_wrapper.py +++ b/project/training_modules/lightning_wrapper.py @@ -33,8 +33,6 @@ class LitModel(pl.LightningModule): acc = accuracy_score(preds, y) self.log('train_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('train_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True) - # f1 = f1_score(preds, y, average="micro") - # self.log('train_f1', f1, on_step=False, on_epoch=True, logger=True, prog_bar=True) return loss @@ -50,9 +48,8 @@ class LitModel(pl.LightningModule): acc = accuracy_score(preds, y) self.log('val_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('val_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True) - # f1 = f1_score(preds, y, average="micro") - # self.log('val_f1', f1, on_step=False, on_epoch=True, logger=True, prog_bar=True) + # we can return here anything and then read it in some callback return preds, y # logic for a single testing step @@ -67,8 +64,6 @@ class LitModel(pl.LightningModule): acc = accuracy_score(preds, y) self.log('test_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('test_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True) - # f1 = f1_score(preds, y, average="micro") - # self.log('test_f1', f1, on_step=False, on_epoch=True, logger=True, prog_bar=True) return loss