diff --git a/.env b/.env deleted file mode 100644 index 57bcc9d..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -export MY_VAR="/home/user/my_system_path" diff --git a/.env.tmp b/.env.tmp new file mode 100644 index 0000000..6a749a8 --- /dev/null +++ b/.env.tmp @@ -0,0 +1,7 @@ +# change name of this file from `.env.tmp` to `.env` +# `.env` will be excluded from version control +# you can store here all your system specific environment variables like this: + +export MY_VAR="/home/user/my_system_path" + +# these variables are loaded automatically in run.py diff --git a/README.md b/README.md index 995c15e..50a575c 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ to your `README.md`. - [Project Structure](#project-structure) - [Quickstart](#quickstart) - [Guide](#guide) - - [How To Start?](#how-to-start) + - [How To Learn?](#how-to-learn) - [Main Project Configuration](#main-project-configuration) - [Experiment Configuration](#experiment-configuration) - [Workflow](#workflow) @@ -38,6 +38,12 @@ to your `README.md`. - [Inference](#inference) - [Callbacks](#callbacks) - [Best Practices](#best-practices) + - [Miniconda](#miniconda) + - [Automatic Code Formatting](#automatic-code-formatting) + - [Environment Variables](#environment-variables) + - [Data Version Control](#data-version-control) + - [Installing Project As A Package](#support-installing-project-as-a-package) + - [Tests](#tests) - [Tricks](#tricks) - [Other Repositories](#other-repositories)
@@ -145,7 +151,7 @@ Template contains example with MNIST classification.
When running `python run.py` you should see something like this:
-![](https://github.com/hobogalaxy/lightning-hydra-template/blob/resources/teminal.png) +![](https://github.com/hobogalaxy/lightning-hydra-template/blob/resources/terminal.png)
@@ -337,12 +343,36 @@ python run.py -m '+experiment=glob(*)' > *This should be achievable with simple config using [Ray AWS launcher for Hydra](https://hydra.cc/docs/next/plugins/ray_launcher). Example is not yet implemented in this template.* + +
+Execute sweep on a Linux SLURM cluster + +> *This should be achievable with simple config using [Submitit launcher for Hydra](https://hydra.cc/docs/plugins/submitit_launcher). Example is not yet implemented in this template.* + +
+ + +
+ ## Guide -### How To Start? +### How To Learn? - First, you should probably get familiar with [PyTorch Lightning](https://www.pytorchlightning.ai) - Next, go through [Hydra quick start guide](https://hydra.cc/docs/intro/), [basic Hydra tutorial](https://hydra.cc/docs/tutorials/basic/your_first_app/simple_cli/) and [docs about instantiating objects with Hydra](https://hydra.cc/docs/patterns/instantiate_objects/overview)
@@ -586,7 +616,18 @@ To provide examples of logging custom visualisations with callbacks only: *LogCo ## Best Practices -### Code Formating +### Miniconda +Use miniconda for your python environments (it's usually unnecessary to install full anaconda environment, miniconda should be enough). +It makes it easier to install some dependencies, like cudatoolkit for GPU support.
+Example installation: +```yaml +wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh +bash Miniconda3-latest-Linux-x86_64.sh +``` +
+ + +### Automatic Code Formatting Use pre-commit hooks to standardize code formatting of your project and save mental energy.
Simply install pre-commit package with: ```yaml @@ -606,25 +647,18 @@ pre-commit run --all-files
-### Miniconda -Use miniconda for your python environments (it's usually unnecessary to install full anaconda environment, miniconda should be enough). -It makes it easier to install some dependencies, like cudatoolkit for GPU support.
-Example installation: -```yaml -wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -bash Miniconda3-latest-Linux-x86_64.sh -``` -
- - ### Environment Variables -System specific variables (e.g. absolute paths to datasets) should not be under version control or it will result in conflict between different users. -Template contains `.env` file which is excluded from further version control, so you can use it for setting your environment variables. -Simply add your var to `.env` like this: +System specific variables (e.g. absolute paths to datasets) should not be under version control or it will result in conflict between different users.
+ + +Template contains `.env.tmp` file. Change its name to `.env` (this name is excluded from version control in .gitignore). +You should use it for storing environment variables like this: ``` bash export MY_VAR=/home/user/my_system_path ``` -You can use environment variables in your Hydra `.yaml` files like this: +All variables from `.env` are loaded in `run.py` automatically. + +Hydra allows you to reference any env variable in `.yaml` configs like this: ```yaml path_to_data: ${env:MY_VAR} ``` @@ -649,17 +683,6 @@ git commit -m "Add raw data"
-### Tests -I find myself often running into bugs that come out only in edge cases or on some specific hardware/environment. To speed up the development, I usually constantly execute simple bash scripts that run a couple of quick 1 epoch experiments, like overfitting to 10 batches, training on 25% of data, etc. You can easily modify the commands in the script for your use case. If even 1 epoch is too much for your model, then you can make it run for a couple of batches instead (by using the right trainer flags).
- -Keep in mind those aren't real tests - it's simply executing commands one after the other, after which you need to take a look in terminal if some of them crashed. It's always best if you write real unit tests for your code.
-To execute: -```yaml -bash tests/smoke_tests.sh -``` -
- - ### Support Installing Project As a Package It allows other people to easily use your modules in their own projects. Change name of the `src` folder to your project name and add `setup.py` file: @@ -691,13 +714,55 @@ So any file can be easily imported into any other file like so: from project_name.models.mnist_model import LitModelMNIST from project_name.datamodules.mnist_datamodule import MNISTDataModule ``` +
+ + +### Tests +I find myself often running into bugs that come out only in edge cases or on some specific hardware/environment. To speed up the development, I usually constantly execute simple bash scripts that run a couple of quick 1 epoch experiments, like overfitting to 10 batches, training on 25% of data, etc. You can easily modify the commands in the script for your use case. If even 1 epoch is too much for your model, then you can make it run for a couple of batches instead (by using the right trainer flags).
+ +Keep in mind those aren't real tests - it's simply executing commands one after the other, after which you need to take a look in terminal if some of them crashed. It's always best if you write real unit tests for your code.
+To execute: +```yaml +bash tests/smoke_tests.sh +```


- ## Tricks -(TODO) -

diff --git a/requirements.txt b/requirements.txt index 1338783..ea297f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ torch>=1.7.1 torchvision>=0.8.2 torchaudio>=0.7.2 pytorch-lightning>=1.2.2 +torchmetrics # --------- hydra --------- # hydra-core==1.1.0.dev3 diff --git a/run.py b/run.py index cf9ebc3..7b3abad 100644 --- a/run.py +++ b/run.py @@ -12,7 +12,7 @@ def main(config: DictConfig): from src.train import train from src.utils import template_utils - # load environment variables from `.env` file + # load environment variables from `.env` file if it exists dotenv.load_dotenv(dotenv_path=".env", override=True) # A couple of optional utilities: diff --git a/tests/smoke_tests.sh b/tests/smoke_tests.sh index 36fb2f2..b8be255 100644 --- a/tests/smoke_tests.sh +++ b/tests/smoke_tests.sh @@ -60,16 +60,16 @@ python run.py trainer=debug_trainer trainer.max_epochs=1 trainer.accumulate_grad print_config=false echo "TEST 9" -echo "Run validation loop twice per epoch (2 epochs)" -python run.py trainer=debug_trainer trainer.max_epochs=2 trainer.val_check_interval=0.5 \ +echo "Run validation loop twice per epoch (1 epoch)" +python run.py trainer=debug_trainer trainer.max_epochs=1 trainer.val_check_interval=0.5 \ print_config=false echo "TEST 10" -echo "Run with CSVLogger (2 epochs)" -python run.py trainer=debug_trainer logger=csv trainer.min_epochs=5 trainer.max_epochs=2 \ +echo "Run with CSVLogger (3 epochs)" +python run.py trainer=debug_trainer logger=csv trainer.max_epochs=2 trainer.limit_train_batches=10 \ print_config=false echo "TEST 11" -echo "Run with TensorBoardLogger (2 epochs)" -python run.py trainer=debug_trainer logger=tensorboard trainer.min_epochs=5 trainer.max_epochs=2 \ +echo "Run with TensorBoardLogger (3 epochs)" +python run.py trainer=debug_trainer logger=tensorboard trainer.max_epochs=2 trainer.limit_train_batches=10 \ print_config=false