* add conference badges

* change TestDataset to ImgDataset

* update conda env

* bump package versions

* update README

* move optuna config to subfolder
This commit is contained in:
Łukasz Zalewski authored and GitHub committed 2021-04-15 21:13:18 +02:00
1 parent 296c5bf5ed
commit e27c11c342
8 files changed
+95 -87

No files matched your search

+15 -18
View File
@@ -12,7 +12,7 @@
<a href="https://black.readthedocs.io/en/stable/"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-black.svg?style=for-the-badge"></a> <a href="https://black.readthedocs.io/en/stable/"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-black.svg?style=for-the-badge"></a>
A clean and scalable template to kickstart your deep learning project 🚀⚡🔥<br> A clean and scalable template to kickstart your deep learning project 🚀⚡🔥<br>
Click on [<kbd>Use this template</kbd>](https://github.com/hobogalaxy/lightning-hydra-template/generate) to initialize new repository. Click on [<kbd>Use this template</kbd>](https://github.com/ashleve/lightning-hydra-template/generate) to initialize new repository.
*Currently uses dev version of Hydra.<br>Suggestions are always welcome!* *Currently uses dev version of Hydra.<br>Suggestions are always welcome!*
@@ -21,7 +21,7 @@ Click on [<kbd>Use this template</kbd>](https://github.com/hobogalaxy/lightning-
<!-- <!--
If you use this template please add <br> If you use this template please add <br>
[![](https://shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=303030)](https://github.com/hobogalaxy/lightning-hydra-template) <br> [![](https://shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=303030)](https://github.com/ashleve/lightning-hydra-template) <br>
to your `README.md`. to your `README.md`.
<br><br> <br><br>
--> -->
@@ -69,12 +69,12 @@ The directory structure of new project looks like this:
│ ├── callbacks <- Callbacks configs │ ├── callbacks <- Callbacks configs
│ ├── datamodule <- Datamodule configs │ ├── datamodule <- Datamodule configs
│ ├── experiment <- Experiment configs │ ├── experiment <- Experiment configs
│ ├── hparams_search <- Hyperparameter search configs
│ ├── logger <- Logger configs │ ├── logger <- Logger configs
│ ├── model <- Model configs │ ├── model <- Model configs
│ ├── trainer <- Trainer configs │ ├── trainer <- Trainer configs
│ │ │ │
│ ├── config.yaml <- Main project configuration file │ └── config.yaml <- Main project configuration file
│ └── config_optuna.yaml <- Configuration of Optuna hyperparameter search
│ │
├── data <- Project data ├── data <- Project data
│ │
@@ -128,7 +128,7 @@ Template contains example with MNIST classification.<br>
When running `python run.py` you should see something like this: When running `python run.py` you should see something like this:
<div align="center"> <div align="center">
![](https://github.com/hobogalaxy/lightning-hydra-template/blob/resources/terminal.png) ![](https://github.com/ashleve/lightning-hydra-template/blob/resources/terminal.png)
</div> </div>
@@ -205,7 +205,7 @@ python run.py logger=wandb
> Experiment configurations are placed in [configs/experiment/](configs/experiment/). > Experiment configurations are placed in [configs/experiment/](configs/experiment/).
```yaml ```yaml
python run.py +experiment=exp_example_simple python run.py experiment=exp_example_simple
``` ```
</details> </details>
@@ -301,9 +301,9 @@ python run.py -m datamodule.batch_size=32,64,128 optimizer.lr=0.001,0.0005
> Using [Optuna Sweeper](https://hydra.cc/docs/next/plugins/optuna_sweeper) plugin doesn't require you to code any boilerplate into your pipeline, everything is defined in a [single config file](configs/config_optuna.yaml)! > Using [Optuna Sweeper](https://hydra.cc/docs/next/plugins/optuna_sweeper) plugin doesn't require you to code any boilerplate into your pipeline, everything is defined in a [single config file](configs/config_optuna.yaml)!
```yaml ```yaml
# this will run hyperparameter search defined in `configs/config_optuna.yaml` # this will run hyperparameter search defined in `configs/hparams_search/mnist_optuna.yaml`
# over chosen experiment config # over chosen experiment config
python run.py -m --config-name config_optuna.yaml +experiment=exp_example_simple python run.py -m hparams_search=mnist_optuna experiment=exp_example_simple
``` ```
</details> </details>
@@ -313,7 +313,7 @@ python run.py -m --config-name config_optuna.yaml +experiment=exp_example_simple
> Hydra provides special syntax for controlling behavior of multiruns. Learn more [here](https://hydra.cc/docs/next/tutorials/basic/running_your_app/multi-run). The command below executes all experiments from folder [configs/experiment/](configs/experiment/). > Hydra provides special syntax for controlling behavior of multiruns. Learn more [here](https://hydra.cc/docs/next/tutorials/basic/running_your_app/multi-run). The command below executes all experiments from folder [configs/experiment/](configs/experiment/).
```yaml ```yaml
python run.py -m '+experiment=glob(*)' python run.py -m 'experiment=glob(*)'
``` ```
</details> </details>
@@ -362,7 +362,7 @@ If you want to use some popular official image instead, I recommend the [nvidia
## :heart:&nbsp; Contributions ## :heart:&nbsp; Contributions
Have a question? Found a bug? Missing a specific feature? Ran into a problem? Feel free to file a new issue with respective title and description. If you already found a solution to your problem, don't hesitate to share it. Suggestions for new best practices and tricks are always welcome! Have a question? Found a bug? Missing a specific feature? Ran into a problem? Feel free to file a new issue or PR with respective title and description. If you already found a solution to your problem, don't hesitate to share it. Suggestions for new best practices and tricks are always welcome!
<br><br><br><br> <br><br><br><br>
@@ -656,12 +656,7 @@ List of extra utilities available in the template:
- method for logging hyperparameters to loggers - method for logging hyperparameters to loggers
- (TODO) resuming latest run - (TODO) resuming latest run
You can easily remove all of those by modifying [run.py](run.py) and [src/train.py](src/train.py). You can easily remove any of those by modifying [run.py](run.py) and [src/train.py](src/train.py).
<br><br>
### How To Speed Up Training
(TODO)
<br><br> <br><br>
@@ -824,7 +819,7 @@ setup(
author="", author="",
author_email="", author_email="",
# replace with your own github project link # replace with your own github project link
url="https://github.com/hobogalaxy/lightning-hydra-template", url="https://github.com/ashleve/lightning-hydra-template",
install_requires=["pytorch-lightning>=1.2.0", "hydra-core>=1.0.6"], install_requires=["pytorch-lightning>=1.2.0", "hydra-core>=1.0.6"],
packages=find_packages(), packages=find_packages(),
) )
@@ -994,7 +989,9 @@ This template was inspired by:
<a href="https://pytorch.org/get-started/locally/"><img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-ee4c2c?logo=pytorch&logoColor=white"></a> <a href="https://pytorch.org/get-started/locally/"><img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-ee4c2c?logo=pytorch&logoColor=white"></a>
<a href="https://pytorchlightning.ai/"><img alt="Lightning" src="https://img.shields.io/badge/-Lightning-792ee5"></a> <a href="https://pytorchlightning.ai/"><img alt="Lightning" src="https://img.shields.io/badge/-Lightning-792ee5"></a>
<a href="https://hydra.cc/"><img alt="Config: Hydra" src="https://img.shields.io/badge/Config-Hydra-89b8cd"></a> <a href="https://hydra.cc/"><img alt="Config: Hydra" src="https://img.shields.io/badge/Config-Hydra-89b8cd"></a>
<a href="https://github.com/hobogalaxy/lightning-hydra-template"><img alt="Template" src="https://img.shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=gray"></a> <a href="https://github.com/ashleve/lightning-hydra-template"><img alt="Template" src="https://img.shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=gray"></a><br>
[![Paper](http://img.shields.io/badge/paper-arxiv.1001.2234-B31B1B.svg)](https://www.nature.com/articles/nature14539)
[![Conference](http://img.shields.io/badge/AnyConference-year-4b44ce.svg)](https://papers.nips.cc/paper/2020)
</div> </div>
+2 -1
View File
@@ -3,7 +3,6 @@ name: myenv
channels: channels:
- pytorch - pytorch
- conda-forge - conda-forge
- defaults
dependencies: dependencies:
- python=3.8 - python=3.8
@@ -13,3 +12,5 @@ dependencies:
- cudatoolkit - cudatoolkit
- pytorch=1.8.1 - pytorch=1.8.1
- torchvision=0.9.1 - torchvision=0.9.1
- pip:
- -r requirements.txt
+5 -2
View File
@@ -8,9 +8,12 @@ defaults:
- callbacks: default_callbacks.yaml # set this to null if you don't want to use callbacks - callbacks: default_callbacks.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`) - logger: null # set logger here or use command line (e.g. `python run.py logger=wandb`)
- experiment: null
- hparams_search: null
# enable color logging # enable color logging
# - override hydra/hydra_logging: colorlog - override hydra/hydra_logging: colorlog
# - override hydra/job_logging: colorlog - override hydra/job_logging: colorlog
# path to original working directory # path to original working directory
-56
View File
@@ -1,56 +0,0 @@
# @package _global_
# example hyperparameter optimization of some experiment with optuna:
# python run.py -m --config-name config_optuna.yaml +experiment=exp_example_simple logger=wandb
defaults:
# load everything from main config file
- config.yaml
# override sweeper to Optuna!
- override hydra/sweeper: optuna
# choose metric which will be optimized by optuna
optimized_metric: "val/acc_best"
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:
optuna_config:
study_name: null
storage: null
n_jobs: 1
seed: 12345
# 'minimize' or 'maximize' the objective
direction: maximize
# number of experiments that will be executed
n_trials: 20
# choose optuna hyperparameter sampler ('tpe', 'random', 'cmaes' or 'nsgaii', 'motpe')
# learn more here: https://optuna.readthedocs.io/en/stable/reference/samplers.html
sampler: tpe
# 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]
+63
View File
@@ -0,0 +1,63 @@
# @package _global_
# example hyperparameter optimization of some experiment with Optuna:
# python run.py -m hparams_search=mnist_optuna experiment=exp_example_simple
# python run.py -m hparams_search=mnist_optuna experiment=exp_example_simple hydra.sweeper.n_trials=30
# python run.py -m hparams_search=mnist_optuna experiment=exp_example_simple logger=wandb
defaults:
- override /hydra/sweeper: optuna
# choose metric which will be optimized by Optuna
optimized_metric: "val/acc_best"
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
# 'minimize' or 'maximize' the objective
direction: maximize
# 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
# 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]
+6 -6
View File
@@ -1,17 +1,17 @@
# --------- pytorch --------- # # --------- pytorch --------- #
torch==1.8.1 torch==1.8.1
torchvision==0.9.1 torchvision==0.9.1
pytorch-lightning>=1.2.5 pytorch-lightning>=1.2.7
# --------- hydra --------- # # --------- hydra --------- #
hydra-core==1.1.0.dev5 hydra-core==1.1.0.dev5
hydra-colorlog==1.0.0 hydra-colorlog==1.1.0.dev1
hydra-optuna-sweeper==0.9.0rc2 hydra-optuna-sweeper==1.1.0.dev1
# hydra-ray-launcher==0.1.2 # hydra-ray-launcher==0.1.2
# hydra-submitit-launcher==1.1.0 # hydra-submitit-launcher==1.1.0
# --------- loggers --------- # # --------- loggers --------- #
wandb>=0.10.20 wandb>=0.10.26
# neptune-client # neptune-client
# comet-ml # comet-ml
# mlflow # mlflow
@@ -24,6 +24,6 @@ scikit-learn
pandas pandas
matplotlib matplotlib
seaborn seaborn
pudb # pudb
pytest # pytest
# dvc # dvc
+1 -1
View File
@@ -5,7 +5,7 @@ from PIL import Image
from torch.utils.data import Dataset from torch.utils.data import Dataset
class TestDataset(Dataset): class ImgDataset(Dataset):
"""Example dataset class for loading images from folder.""" """Example dataset class for loading images from folder."""
def __init__(self, dir: str, transform: Optional[Callable] = None): def __init__(self, dir: str, transform: Optional[Callable] = None):
+3 -3
View File
@@ -9,14 +9,14 @@ from torchvision.transforms import transforms
class MNISTDataModule(LightningDataModule): class MNISTDataModule(LightningDataModule):
""" """
Example of LightningDataModule for MNIST dataset. Example of LightningDataModule for MNIST dataset.
A DataModule implements 5 key methods: A DataModule implements 5 key methods:
- prepare_data (things to do on 1 GPU/TPU, not on every GPU/TPU in distributed mode) - prepare_data (things to do on 1 GPU/TPU, not on every GPU/TPU in distributed mode)
- setup (things to do on every accelerator in distributed mode) - setup (things to do on every accelerator in distributed mode)
- train_dataloader (the training dataloader) - train_dataloader (the training dataloader)
- val_dataloader (the validation dataloader(s)) - val_dataloader (the validation dataloader(s))
- test_dataloader (the test dataloader(s)) - test_dataloader (the test dataloader(s))
This allows you to share a full dataset without explaining how to download, This allows you to share a full dataset without explaining how to download,
split, transform and process the data split, transform and process the data
@@ -31,7 +31,7 @@ class MNISTDataModule(LightningDataModule):
batch_size: int = 64, batch_size: int = 64,
num_workers: int = 0, num_workers: int = 0,
pin_memory: bool = False, pin_memory: bool = False,
**kwargs **kwargs,
): ):
super().__init__() super().__init__()