Release/0.9 (#141)

* add flake8 and prettier to pre-commit-config
* add setup.cfg
* add workers=True to seed_everything()
* update lightning badge logo
* bump package versions
* update README.md
* add __init__.py files
* add more logger configs parameters
* add default Dockerfile
* change .env.template to .env.example
* move inference example to readme
* remove img_dataset.py
* simplify names of wandb callbacks
* remove wandb test marker
* format files with prettier
This commit is contained in:
Łukasz Zalewski authored and GitHub committed 2021-05-21 09:26:31 +02:00
1 parent 023d4bdecc
commit 70ab061f75
49 files changed
+473 -415

No files matched your search

+13 -14
View File
@@ -1,17 +1,16 @@
model_checkpoint:
_target_: pytorch_lightning.callbacks.ModelCheckpoint
monitor: "val/acc" # name of the logged metric which determines when model is improving
save_top_k: 1 # save k best models (determined by above metric)
save_last: True # additionaly always save model from last epoch
mode: "max" # can be "max" or "min"
verbose: False
dirpath: 'checkpoints/'
filename: '{epoch:02d}'
_target_: pytorch_lightning.callbacks.ModelCheckpoint
monitor: "val/acc" # name of the logged metric which determines when model is improving
save_top_k: 1 # save k best models (determined by above metric)
save_last: True # additionaly always save model from last epoch
mode: "max" # can be "max" or "min"
verbose: False
dirpath: "checkpoints/"
filename: "{epoch:02d}"
early_stopping:
_target_: pytorch_lightning.callbacks.EarlyStopping
monitor: "val/acc" # name of the logged metric which determines when model is improving
patience: 100 # how many epochs of not improving until training stops
mode: "max" # can be "max" or "min"
min_delta: 0 # minimum change in the monitored metric needed to qualify as an improvement
_target_: pytorch_lightning.callbacks.EarlyStopping
monitor: "val/acc" # name of the logged metric which determines when model is improving
patience: 100 # how many epochs of not improving until training stops
mode: "max" # can be "max" or "min"
min_delta: 0 # minimum change in the monitored metric needed to qualify as an improvement
+14 -20
View File
@@ -1,32 +1,26 @@
defaults:
- default.yaml
- default.yaml
watch_model:
_target_: src.callbacks.wandb_callbacks.WatchModelWithWandb
log: "all"
log_freq: 100
_target_: src.callbacks.wandb_callbacks.WatchModel
log: "all"
log_freq: 100
upload_code_as_artifact:
_target_: src.callbacks.wandb_callbacks.UploadCodeToWandbAsArtifact
code_dir: ${work_dir}/src
_target_: src.callbacks.wandb_callbacks.UploadCodeAsArtifact
code_dir: ${work_dir}/src
upload_ckpts_as_artifact:
_target_: src.callbacks.wandb_callbacks.UploadCheckpointsToWandbAsArtifact
ckpt_dir: "checkpoints/"
upload_best_only: True
_target_: src.callbacks.wandb_callbacks.UploadCheckpointsAsArtifact
ckpt_dir: "checkpoints/"
upload_best_only: True
log_f1_precision_recall_heatmap:
_target_: src.callbacks.wandb_callbacks.LogF1PrecRecHeatmapToWandb
_target_: src.callbacks.wandb_callbacks.LogF1PrecRecHeatmap
log_confusion_matrix:
_target_: src.callbacks.wandb_callbacks.LogConfusionMatrixToWandb
_target_: src.callbacks.wandb_callbacks.LogConfusionMatrix
log_images_with_predictions:
_target_: src.callbacks.wandb_callbacks.ImagePredictionLogger
num_samples: 8
log_image_predictions:
_target_: src.callbacks.wandb_callbacks.LogImagePredictions
num_samples: 8
+11 -16
View File
@@ -2,21 +2,20 @@
# specify here default training configuration
defaults:
- trainer: minimal.yaml
- model: mnist_model.yaml
- datamodule: mnist_datamodule.yaml
- callbacks: default.yaml # set this to null if you don't want to use callbacks
- logger: null # set logger here or use command line (e.g. `python run.py logger=wandb`)
- trainer: minimal.yaml
- model: mnist_model.yaml
- datamodule: mnist_datamodule.yaml
- callbacks: default.yaml # set this to null if you don't want to use callbacks
- logger: null # set logger here or use command line (e.g. `python run.py logger=wandb`)
- experiment: null
- hparams_search: null
- experiment: null
- hparams_search: null
- hydra: default.yaml
# enable color logging
- override hydra/hydra_logging: colorlog
- override hydra/job_logging: colorlog
- hydra: 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 current log directory,
@@ -24,21 +23,17 @@ defaults:
# learn more here: https://hydra.cc/docs/next/tutorials/basic/running_your_app/working_directory
work_dir: ${hydra:runtime.cwd}
# path to folder with data
data_dir: ${work_dir}/data/
# use `python run.py debug=true` for easy debugging!
# this will run 1 train, val and test loop with only 1 batch
# equivalent to running `python run.py trainer.fast_dev_run=true`
# (this is placed here just for easier access from command line)
debug: False
# pretty print config at the start of the run using Rich library
print_config: True
# disable python warnings if they annoy you
ignore_warnings: True
+1 -1
View File
@@ -1,6 +1,6 @@
_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
train_val_test_split: [55_000, 5_000, 10_000]
num_workers: 0
+48 -48
View File
@@ -4,11 +4,11 @@
# python run.py experiment=example_full.yaml
defaults:
- override /trainer: null # override trainer to null so it's not loaded from main config defaults...
- override /model: null
- override /datamodule: null
- override /callbacks: null
- override /logger: null
- override /trainer: null # override trainer to null so it's not loaded from main config defaults...
- override /model: null
- override /datamodule: null
- override /callbacks: null
- override /logger: null
# we override default configurations with nulls to prevent them from loading at all
# instead we define all modules and their paths directly in this config,
@@ -17,54 +17,54 @@ defaults:
seed: 12345
trainer:
_target_: pytorch_lightning.Trainer
gpus: 0
min_epochs: 1
max_epochs: 10
gradient_clip_val: 0.5
accumulate_grad_batches: 2
weights_summary: null
# resume_from_checkpoint: ${work_dir}/last.ckpt
_target_: pytorch_lightning.Trainer
gpus: 0
min_epochs: 1
max_epochs: 10
gradient_clip_val: 0.5
accumulate_grad_batches: 2
weights_summary: null
# resume_from_checkpoint: ${work_dir}/last.ckpt
model:
_target_: src.models.mnist_model.MNISTLitModel
lr: 0.001
weight_decay: 0.00005
architecture: SimpleDenseNet
input_size: 784
lin1_size: 256
lin2_size: 256
lin3_size: 128
output_size: 10
_target_: src.models.mnist_model.MNISTLitModel
lr: 0.001
weight_decay: 0.00005
architecture: SimpleDenseNet
input_size: 784
lin1_size: 256
lin2_size: 256
lin3_size: 128
output_size: 10
datamodule:
_target_: src.datamodules.mnist_datamodule.MNISTDataModule
data_dir: ${data_dir}
batch_size: 64
train_val_test_split: [55_000, 5_000, 10_000]
num_workers: 0
pin_memory: False
_target_: src.datamodules.mnist_datamodule.MNISTDataModule
data_dir: ${data_dir}
batch_size: 64
train_val_test_split: [55_000, 5_000, 10_000]
num_workers: 0
pin_memory: False
callbacks:
model_checkpoint:
_target_: pytorch_lightning.callbacks.ModelCheckpoint
monitor: "val/acc"
save_top_k: 2
save_last: True
mode: "max"
dirpath: 'checkpoints/'
filename: 'sample-mnist-{epoch:02d}'
early_stopping:
_target_: pytorch_lightning.callbacks.EarlyStopping
monitor: "val/acc"
patience: 10
mode: "max"
model_checkpoint:
_target_: pytorch_lightning.callbacks.ModelCheckpoint
monitor: "val/acc"
save_top_k: 2
save_last: True
mode: "max"
dirpath: "checkpoints/"
filename: "sample-mnist-{epoch:02d}"
early_stopping:
_target_: pytorch_lightning.callbacks.EarlyStopping
monitor: "val/acc"
patience: 10
mode: "max"
logger:
wandb:
tags: ["best_model", "uwu"]
notes: "Description of this model."
neptune:
tags: ["best_model"]
csv_logger:
save_dir: "."
wandb:
tags: ["best_model", "uwu"]
notes: "Description of this model."
neptune:
tags: ["best_model"]
csv_logger:
save_dir: "."
+14 -14
View File
@@ -4,11 +4,11 @@
# python run.py experiment=example_simple.yaml
defaults:
- override /trainer: minimal.yaml # choose trainer from 'configs/trainer/'
- override /model: mnist_model.yaml
- override /datamodule: mnist_datamodule.yaml
- override /callbacks: default.yaml
- override /logger: null
- override /trainer: minimal.yaml # choose trainer from 'configs/trainer/'
- override /model: mnist_model.yaml
- override /datamodule: mnist_datamodule.yaml
- override /callbacks: default.yaml
- override /logger: null
# all parameters below will be merged with parameters from default configurations set above
# this allows you to overwrite only specified parameters
@@ -16,16 +16,16 @@ defaults:
seed: 12345
trainer:
min_epochs: 1
max_epochs: 10
gradient_clip_val: 0.5
min_epochs: 1
max_epochs: 10
gradient_clip_val: 0.5
model:
lin1_size: 128
lin2_size: 256
lin3_size: 64
lr: 0.002
lin1_size: 128
lin2_size: 256
lin3_size: 64
lr: 0.002
datamodule:
batch_size: 64
train_val_test_split: [55_000, 5_000, 10_000]
batch_size: 64
train_val_test_split: [55_000, 5_000, 10_000]
+44 -46
View File
@@ -6,58 +6,56 @@
# python run.py -m hparams_search=mnist_optuna experiment=example_simple logger=wandb
defaults:
- override /hydra/sweeper: optuna
- override /hydra/sweeper: optuna
# choose metric which will be optimized by Optuna
optimized_metric: "val/acc"
hydra:
# here we define Optuna hyperparameter search
# it optimizes for value returned from function with @hydra.main decorator
# learn more here: https://hydra.cc/docs/next/plugins/optuna_sweeper
sweeper:
_target_: hydra_plugins.hydra_optuna_sweeper.optuna_sweeper.OptunaSweeper
storage: null
study_name: null
n_jobs: 1
# here we define Optuna hyperparameter search
# it optimizes for value returned from function with @hydra.main decorator
# learn more here: https://hydra.cc/docs/next/plugins/optuna_sweeper
sweeper:
_target_: hydra_plugins.hydra_optuna_sweeper.optuna_sweeper.OptunaSweeper
storage: null
study_name: null
n_jobs: 1
# 'minimize' or 'maximize' the objective
direction: maximize
# 'minimize' or 'maximize' the objective
direction: maximize
# number of experiments that will be executed
n_trials: 20
# number of experiments that will be executed
n_trials: 20
# choose Optuna hyperparameter sampler
# learn more here: https://optuna.readthedocs.io/en/stable/reference/samplers.html
sampler:
_target_: optuna.samplers.TPESampler
seed: 12345
consider_prior: true
prior_weight: 1.0
consider_magic_clip: true
consider_endpoints: false
n_startup_trials: 10
n_ei_candidates: 24
multivariate: false
warn_independent_sampling: true
# choose Optuna hyperparameter sampler
# learn more here: https://optuna.readthedocs.io/en/stable/reference/samplers.html
sampler:
_target_: optuna.samplers.TPESampler
seed: 12345
consider_prior: true
prior_weight: 1.0
consider_magic_clip: true
consider_endpoints: false
n_startup_trials: 10
n_ei_candidates: 24
multivariate: false
warn_independent_sampling: true
# define range of hyperparameters
search_space:
datamodule.batch_size:
type: categorical
choices: [32, 64, 128]
model.lr:
type: float
low: 0.0001
high: 0.2
model.lin1_size:
type: categorical
choices: [32, 64, 128, 256, 512]
model.lin2_size:
type: categorical
choices: [32, 64, 128, 256, 512]
model.lin3_size:
type: categorical
choices: [32, 64, 128, 256, 512]
# define range of hyperparameters
search_space:
datamodule.batch_size:
type: categorical
choices: [32, 64, 128]
model.lr:
type: float
low: 0.0001
high: 0.2
model.lin1_size:
type: categorical
choices: [32, 64, 128, 256, 512]
model.lin2_size:
type: categorical
choices: [32, 64, 128, 256, 512]
model.lin3_size:
type: categorical
choices: [32, 64, 128, 256, 512]
+5 -5
View File
@@ -1,12 +1,12 @@
# output paths for hydra logs
run:
dir: logs/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
dir: logs/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
sweep:
dir: logs/multiruns/${now:%Y-%m-%d_%H-%M-%S}
subdir: ${hydra.job.num}
dir: logs/multiruns/${now:%Y-%m-%d_%H-%M-%S}
subdir: ${hydra.job.num}
# you can set here environment variables that are universal for all users
# for system specific variables (like data paths) it's better to use .env file!
job:
env_set:
EXAMPLE_VAR: "example_value"
env_set:
EXAMPLE_VAR: "example_value"
+4 -4
View File
@@ -1,7 +1,7 @@
# https://www.comet.ml
comet:
_target_: pytorch_lightning.loggers.comet.CometLogger
api_key: ???
project_name: "project_template_test"
experiment_name: null
_target_: pytorch_lightning.loggers.comet.CometLogger
api_key: ${oc.env:COMET_API_TOKEN} # api key is laoded from environment variable
project_name: "template-tests"
experiment_name: null
+6 -4
View File
@@ -1,6 +1,8 @@
# CSVLogger built in PyTorch Lightning
# csv logger built in lightning
csv:
_target_: pytorch_lightning.loggers.csv_logs.CSVLogger
save_dir: "."
name: "csv/"
_target_: pytorch_lightning.loggers.csv_logs.CSVLogger
save_dir: "."
name: "csv/"
version: null
prefix: ""
+7 -5
View File
@@ -1,8 +1,10 @@
# train with many loggers at once
defaults:
- csv.yaml
- wandb.yaml
# - neptune.yaml
# - comet.yaml
# - tensorboard.yaml
# - aim.yaml
# - comet.yaml
- csv.yaml
# - mlflow.yaml
# - neptune.yaml
# - tensorboard.yaml
- wandb.yaml
+10
View File
@@ -0,0 +1,10 @@
# https://mlflow.org
mlflow:
_target_: pytorch_lightning.loggers.mlflow.MLFlowLogger
experiment_name: default
tracking_uri: null
tags: null
save_dir: ./mlruns
prefix: ""
artifact_location: null
+8 -4
View File
@@ -1,7 +1,11 @@
# https://neptune.ai
neptune:
_target_: pytorch_lightning.loggers.neptune.NeptuneLogger
project_name: "your_name/lightning-hydra-template-test"
api_key: ${oc.env:NEPTUNE_API_TOKEN} # api key is laoded from environment variable
# experiment_name: "some_experiment"
_target_: pytorch_lightning.loggers.neptune.NeptuneLogger
api_key: ${oc.env:NEPTUNE_API_TOKEN} # api key is laoded from environment variable
project_name: your_name/template-tests
close_after_fit: True
offline_mode: False
experiment_name: null
experiment_id: null
prefix: ""
+8 -4
View File
@@ -1,6 +1,10 @@
# TensorBoard
# https://www.tensorflow.org/tensorboard/
tensorboard:
_target_: pytorch_lightning.loggers.tensorboard.TensorBoardLogger
save_dir: "tensorboard/"
name: "default"
_target_: pytorch_lightning.loggers.tensorboard.TensorBoardLogger
save_dir: "tensorboard/"
name: "default"
version: null
log_graph: False
default_hp_metric: True
prefix: ""
+13 -8
View File
@@ -1,10 +1,15 @@
# https://wandb.ai (Weights&Biases)
# https://wandb.ai
wandb:
_target_: pytorch_lightning.loggers.wandb.WandbLogger
project: "template-tests"
# entity: "" # set to name of your wandb team or just remove it
# offline: False # set True to store all logs only locally
job_type: "train"
group: ""
save_dir: "."
_target_: pytorch_lightning.loggers.wandb.WandbLogger
project: "template-tests"
name: null
save_dir: "."
offline: False # set True to store all logs only locally
id: null # pass correct id to resume experiment!
# entity: "" # set to name of your wandb team or just remove it
log_model: False
prefix: ""
job_type: "train"
group: ""
tags: []
-1
View File
@@ -1,4 +1,3 @@
_target_: pytorch_lightning.Trainer
gpus: 4
+1 -1
View File
@@ -3,7 +3,7 @@ _target_: pytorch_lightning.Trainer
gpus: 0
min_epochs: 1
max_epochs: 3
max_epochs: 2
# prints
progress_bar_refresh_rate: null
+3 -3
View File
@@ -30,7 +30,7 @@ log_every_n_steps: 50
accelerator: null
sync_batchnorm: False
precision: 32
weights_summary: 'top'
weights_summary: "top"
weights_save_path: null
num_sanity_val_steps: 2
truncated_bptt_steps: null
@@ -45,6 +45,6 @@ terminate_on_nan: False
auto_scale_batch_size: False
prepare_data_per_node: True
plugins: null
amp_backend: 'native'
amp_level: 'O2'
amp_backend: "native"
amp_level: "O2"
move_metrics_to_cpu: False
-1
View File
@@ -8,5 +8,4 @@ max_epochs: 10
weights_summary: null
progress_bar_refresh_rate: 10
# resume_from_checkpoint: null