From 82f31b97bfde44f5dad70007efa4a6ac274f4ff3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Feb 2023 13:17:00 +0100 Subject: [PATCH 1/5] Bump hydra-core from 1.3.1 to 1.3.2 (#536) Bumps [hydra-core](https://github.com/facebookresearch/hydra) from 1.3.1 to 1.3.2. - [Release notes](https://github.com/facebookresearch/hydra/releases) - [Changelog](https://github.com/facebookresearch/hydra/blob/v1.3.2/NEWS.md) - [Commits](https://github.com/facebookresearch/hydra/compare/v1.3.1...v1.3.2) --- updated-dependencies: - dependency-name: hydra-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7783b23a8..bad1c748e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ pytorch-lightning==1.9.1 torchmetrics==0.11.0 # --------- hydra --------- # -hydra-core==1.3.1 +hydra-core==1.3.2 hydra-colorlog==1.2.0 hydra-optuna-sweeper==1.2.0 From 81fafde7835fd957864c20d8fcbb4e801725000c Mon Sep 17 00:00:00 2001 From: Lukas Date: Sat, 25 Feb 2023 18:08:48 +0100 Subject: [PATCH 2/5] Set hydra version to 1.3 in tests (#542) --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7e454c67d..8fda2e0c1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,7 @@ @pytest.fixture(scope="package") def cfg_train_global() -> DictConfig: - with initialize(version_base="1.2", config_path="../configs"): + with initialize(version_base="1.3", config_path="../configs"): cfg = compose(config_name="train.yaml", return_hydra_config=True, overrides=[]) # set defaults for all tests @@ -32,7 +32,7 @@ def cfg_train_global() -> DictConfig: @pytest.fixture(scope="package") def cfg_eval_global() -> DictConfig: - with initialize(version_base="1.2", config_path="../configs"): + with initialize(version_base="1.3", config_path="../configs"): cfg = compose(config_name="eval.yaml", return_hydra_config=True, overrides=["ckpt_path=."]) # set defaults for all tests From 745b37bf7c1e1f9bbb01556f9b91883eb5ce9633 Mon Sep 17 00:00:00 2001 From: Lukas Date: Sat, 25 Feb 2023 23:06:27 +0100 Subject: [PATCH 3/5] Encourage resetting all validation metrics when training starts (#540) --- src/models/mnist_module.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/models/mnist_module.py b/src/models/mnist_module.py index dd00e41b5..8827f05ce 100644 --- a/src/models/mnist_module.py +++ b/src/models/mnist_module.py @@ -56,7 +56,9 @@ def forward(self, x: torch.Tensor): def on_train_start(self): # by default lightning executes validation step sanity checks before training starts, - # so we need to make sure val_acc_best doesn't store accuracy from these checks + # so it's worth to make sure validation metrics don't store results from these checks + self.val_loss.reset() + self.val_acc.reset() self.val_acc_best.reset() def model_step(self, batch: Any): From 2c2641cb8c0b2427be857bf7749991643068fa36 Mon Sep 17 00:00:00 2001 From: Mattie Tesfaldet Date: Wed, 8 Mar 2023 18:28:04 -0500 Subject: [PATCH 4/5] Support for installing dependencies with conda (#532) --- .pre-commit-config.yaml | 1 + README.md | 21 ++++++++++++++++++-- environment.yaml | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 environment.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ea18d19b..b3ba143a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -71,6 +71,7 @@ repos: hooks: - id: prettier types: [yaml] + exclude: "environment.yaml" # shell scripts linter - repo: https://github.com/shellcheck-py/shellcheck-py diff --git a/README.md b/README.md index 44b7b0432..0e0e0a430 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ The directory structure of new project looks like this: ├── .gitignore <- List of files ignored by git ├── .pre-commit-config.yaml <- Configuration of pre-commit hooks for code formatting ├── .project-root <- File for inferring the position of project root directory +├── environment.yaml <- File for installing conda environment ├── Makefile <- Makefile with commands like `make train` or `make test` ├── pyproject.toml <- Configuration options for testing and linting ├── requirements.txt <- File for installing python dependencies @@ -1216,9 +1217,9 @@ ______________________________________________________________________ What it does -## How to run +## Installation -Install dependencies +#### Pip ```bash # clone project @@ -1236,6 +1237,22 @@ conda activate myenv pip install -r requirements.txt ``` +#### Conda + +```bash +# clone project +git clone https://github.com/YourGithubName/your-repo-name +cd your-repo-name + +# create conda environment and install dependencies +conda env create -f environment.yaml + +# activate conda environment +conda activate myenv +``` + +## How to run + Train model with default configuration ```bash diff --git a/environment.yaml b/environment.yaml new file mode 100644 index 000000000..cd964a32c --- /dev/null +++ b/environment.yaml @@ -0,0 +1,43 @@ +# reasons you might want to use `environment.yaml` instead of `requirements.txt`: +# - pip installs packages in a loop, without ensuring dependencies across all packages +# are fulfilled simultaneously, but conda achieves proper dependency control across +# all packages +# - conda allows for installing packages without requiring certain compilers or +# libraries to be available in the system, since it installs precompiled binaries + +name: myenv + +channels: + - pytorch + - conda-forge + - defaults + +# it is strongly recommended to specify versions of packages installed through conda +# to avoid situation when version-unspecified packages install their latest major +# versions which can sometimes break things + +# current approach below keeps the dependencies in the same major versions across all +# users, but allows for different minor and patch versions of packages where backwards +# compatibility is usually guaranteed + +dependencies: + - pytorch>=1.10 + - torchvision>=0.11 + - pytorch-lightning=1.* + - torchmetrics=0.* + - hydra-core=1.* + - rich=13.* + - pre-commit=3.* + - pytest=7.* + + # --------- loggers --------- # + # - wandb + # - neptune-client + # - mlflow + # - comet-ml + + - pip>=23 + - pip: + - hydra-optuna-sweeper + - hydra-colorlog + - pyrootutils From 6d4b1e6b688f66b01cf6f7b8f23cfc6a2da1c8c9 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 9 Mar 2023 00:28:55 +0100 Subject: [PATCH 5/5] Add `__init__.py` to `configs/` folder (#539) --- configs/__init__.py | 1 + setup.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 configs/__init__.py diff --git a/configs/__init__.py b/configs/__init__.py new file mode 100644 index 000000000..56bf7f4aa --- /dev/null +++ b/configs/__init__.py @@ -0,0 +1 @@ +# this file is needed here to include configs when building project as a package diff --git a/setup.py b/setup.py index d492719ca..51becc7af 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,14 @@ description="Describe Your Cool Project", author="", author_email="", - url="https://github.com/user/project", # REPLACE WITH YOUR OWN GITHUB PROJECT LINK + url="https://github.com/user/project", install_requires=["pytorch-lightning", "hydra-core"], packages=find_packages(), + # use this to customize global commands available in the terminal after installing the package + entry_points={ + "console_scripts": [ + "train_command = src.train:main", + "eval_command = src.eval:main", + ] + }, )