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/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/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 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 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", + ] + }, ) 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): 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