-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the algorithm tests, setup incremental testing (#35)
* Add parametrize_when_used mark to simplify tests Signed-off-by: Fabrice Normandin <[email protected]> * Add a new, simpler test suite (that works!) Signed-off-by: Fabrice Normandin <[email protected]> * Rename the algorithm tests class (wip) Signed-off-by: Fabrice Normandin <[email protected]> * Further simplify the typing in the example Signed-off-by: Fabrice Normandin <[email protected]> * Remove the older (uglier) test suite for algos Signed-off-by: Fabrice Normandin <[email protected]> * Remove the unused classification test suite Signed-off-by: Fabrice Normandin <[email protected]> * Add missing config Signed-off-by: Fabrice Normandin <[email protected]> * Add the badges in the README Signed-off-by: Fabrice Normandin <[email protected]> * Remove outdated Protocol Signed-off-by: Fabrice Normandin <[email protected]> * Set JAX_PLATFORMS=cpu when no GPU is found Signed-off-by: Fabrice Normandin <[email protected]> * Debugging weird xpass/xfails Signed-off-by: Fabrice Normandin <[email protected]> * (ugly commit) remove unused code, add doctests Signed-off-by: Fabrice Normandin <[email protected]> * Fix some issues in tests Signed-off-by: Fabrice Normandin <[email protected]> * Add missing __init__.py Signed-off-by: Fabrice Normandin <[email protected]> * Fix more issues in tests Signed-off-by: Fabrice Normandin <[email protected]> * Add a docstring in TestJaxExample Signed-off-by: Fabrice Normandin <[email protected]> * Fix weird XPASS in tests Signed-off-by: Fabrice Normandin <[email protected]> * Add batch size fix from Lightning-Hydra-Template Signed-off-by: Fabrice Normandin <[email protected]> * [ugly] Add regression files to check if CI works Signed-off-by: Fabrice Normandin <[email protected]> * Add nice docstrings for env_vars.py Signed-off-by: Fabrice Normandin <[email protected]> * Revert "[ugly] Add regression files to check if CI works" This reverts commit ad1e630. * Use --gen-missing flag in CI for now Signed-off-by: Fabrice Normandin <[email protected]> * Slightly simplify main.py objective calculation Signed-off-by: Fabrice Normandin <[email protected]> * Remove broken test for code blocks in docstrings Signed-off-by: Fabrice Normandin <[email protected]> * Fix test for jax on CPU Signed-off-by: Fabrice Normandin <[email protected]> * Simplify main_test.py Signed-off-by: Fabrice Normandin <[email protected]> * Save regression files in subfolder based on device Signed-off-by: Fabrice Normandin <[email protected]> * Change README and fix link Signed-off-by: Fabrice Normandin <[email protected]> * Trim down docs generation script, minor doc fixes Signed-off-by: Fabrice Normandin <[email protected]> * Skip regression check when files are missing Signed-off-by: Fabrice Normandin <[email protected]> * Reduce amount of warnings generated in tests Signed-off-by: Fabrice Normandin <[email protected]> * Remove unused code in project.utils.utils.py Signed-off-by: Fabrice Normandin <[email protected]> * Fix command-line flag used to skip checks Signed-off-by: Fabrice Normandin <[email protected]> * Tweak README.md Signed-off-by: Fabrice Normandin <[email protected]> * Simplify the actions-runner-job.sh Signed-off-by: Fabrice Normandin <[email protected]> * Add missing flag in build.yml Signed-off-by: Fabrice Normandin <[email protected]> * Fix the `example.yaml` config in example group Signed-off-by: Fabrice Normandin <[email protected]> * Add todos for generating reference docs Signed-off-by: Fabrice Normandin <[email protected]> * Simplify example.py Signed-off-by: Fabrice Normandin <[email protected]> * Add a small docstring to project.configs Signed-off-by: Fabrice Normandin <[email protected]> * Remove overrides in top-level config, fix 'name' Signed-off-by: Fabrice Normandin <[email protected]> * Use hydra_zen.instantiate by default (no pydantic) Signed-off-by: Fabrice Normandin <[email protected]> * Add useful callbacks to defaults Signed-off-by: Fabrice Normandin <[email protected]> * Add/tweak config files Signed-off-by: Fabrice Normandin <[email protected]> * Simplify the network / layers Signed-off-by: Fabrice Normandin <[email protected]> * Don't dynamically create algo configs Signed-off-by: Fabrice Normandin <[email protected]> * Add tensorboard logger config from hydra-template Signed-off-by: Fabrice Normandin <[email protected]> * Rename `optimizer` arg to `optimizer_config` Signed-off-by: Fabrice Normandin <[email protected]> * Fix test_defaults Signed-off-by: Fabrice Normandin <[email protected]> * Update tensor-regression dependency Signed-off-by: Fabrice Normandin <[email protected]> * Fix missing python in actions-runner-job.sh Signed-off-by: Fabrice Normandin <[email protected]> --------- Signed-off-by: Fabrice Normandin <[email protected]>
- Loading branch information
Showing
54 changed files
with
1,280 additions
and
2,225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,65 @@ | ||
# Research Project Template | ||
|
||
![Build](https://github.com/mila-iqia/ResearchTemplate/workflows/build.yml/badge.svg) | ||
[![Build](https://github.com/mila-iqia/ResearchTemplate/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/mila-iqia/ResearchTemplate/actions/workflows/build.yml) | ||
[![codecov](https://codecov.io/gh/mila-iqia/ResearchTemplate/graph/badge.svg?token=I2DYLK8NTD)](https://codecov.io/gh/mila-iqia/ResearchTemplate) | ||
[![hydra](https://img.shields.io/badge/Config-Hydra_1.3-89b8cd)](https://hydra.cc/) | ||
[![license](https://img.shields.io/badge/License-MIT-green.svg?labelColor=gray)](https://github.com/mila-iqia/ResearchTemplate#license) | ||
|
||
Please note: This is a **Work-in-Progress**. The goal is to make a first release by the end of summer 2024. | ||
Please note: This is a Work-in-Progress. The goal is to make a first release by the end of summer 2024. | ||
|
||
For now, feel free to take a look at the [documentation page](https://mila-iqia.github.io/ResearchTemplate/) if you want more information about this project. | ||
This is a template repository for a research project in machine learning. It is meant to be a starting point for new ML researchers that run jobs on SLURM clusters. | ||
The main target audience is [Mila](https://mila.quebec/en) researchers and students, but this should still be useful to anyone that uses PyTorch-Lightning with Hydra. | ||
|
||
For more context, see [this introduction to the project.](https://mila-iqia.github.io/ResearchTemplate/overview/intro). | ||
|
||
## Overview | ||
|
||
This project makes use of the following libraries: | ||
|
||
- [Hydra](https://hydra.cc/) is used to configure the project. It allows you to define configuration files and override them from the command line. | ||
- [PyTorch Lightning](https://lightning.ai/docs/pytorch/stable/) is used to as the training framework. It provides a high-level interface to organize ML research code. | ||
- 🔥 Please note: You can also use [Jax](https://jax.readthedocs.io/en/latest/) with this repo, as is shown in the [Jax example](https://mila-iqia.github.io/ResearchTemplate/examples/jax) 🔥 | ||
- [Weights & Biases](https://wandb.ai) is used to log metrics and visualize results. | ||
- [pytest](https://docs.pytest.org/en/stable/) is used for testing. | ||
|
||
## Why use this template? | ||
|
||
Why should you use this template (instead of another)? | ||
|
||
Here are some of the advantages to using this template compared to [some of the other templates out there](https://mila-iqia.github.io/ResearchTemplate/related): | ||
|
||
- ❗Support for both Jax and Torch with PyTorch-Lightning ❗ | ||
- Easy development inside a [Development Container](https://code.visualstudio.com/docs/remote/containers) with [VsCode](https://code.visualstudio.com/) | ||
- Tailor-made for ML researchers that run their jobs on SLURM clusters (with default configurations for the [Mila](https://docs.mila.quebec) and [DRAC](https://docs.alliancecan.ca) clusters.) | ||
- Rich typing and documentation of all parts of the source code using Python 3.12's new type annotation syntax | ||
- A comprehensive suite of automated tests for all algorithms, datasets and networks that are easy to reuse and extend | ||
- Automatically creates Yaml Schemas for your Hydra config files (as soon as #7 is merged) | ||
|
||
## Usage | ||
|
||
To see all available options: | ||
|
||
```bash | ||
python project/main.py --help | ||
``` | ||
|
||
For a detailed list of examples, see the [examples page](https://mila-iqia.github.io/ResearchTemplate/examples/examples). | ||
|
||
<!-- * `mkdocs new [dir-name]` - Create a new project. | ||
* `mkdocs serve` - Start the live-reloading docs server. | ||
* `mkdocs build` - Build the documentation site. | ||
* `mkdocs -h` - Print help message and exit. --> | ||
|
||
## Project layout | ||
|
||
``` | ||
pyproject.toml # Project metadata and dependencies | ||
project/ | ||
main.py # main entry-point | ||
algorithms/ # learning algorithms | ||
datamodules/ # datasets, processing and loading | ||
networks/ # Neural networks used by algorithms | ||
configs/ # configuration files | ||
docs/ # documentation | ||
conftest.py # Test fixtures and utilities | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pathlib | ||
|
||
import pytest | ||
from mktestdocs import check_md_file | ||
|
||
# This retrieves all methods/properties that have a docstring. | ||
# todo: Brittle. We'd like something like griffe, that gets all functions / classes / etc in our module. | ||
# members = get_codeblock_members(*[v for k, v in vars(project).items() if k != "__all__"]) | ||
|
||
|
||
def get_pretty_id(obj): | ||
if hasattr(obj, "__qualname__"): | ||
return obj.__qualname__ | ||
if hasattr(obj, "__name__"): | ||
return obj.__name__ | ||
return str(obj) | ||
|
||
|
||
# todo: do we want to run the tests here? or do we just test the doc pages? | ||
# @pytest.mark.parametrize( | ||
# "obj", | ||
# list(itertools.chain(map(getmembers, [project, project.configs, project.algorithms]))), | ||
# ids=get_pretty_id, | ||
# ) | ||
# def test_member(obj): | ||
# check_docstring(obj) | ||
|
||
|
||
docs_folder = pathlib.Path(__file__).parent | ||
|
||
|
||
# Note the use of `str`, makes for pretty output | ||
@pytest.mark.parametrize("fpath", docs_folder.rglob("*.md"), ids=str) | ||
def test_documentation_file(fpath): | ||
check_md_file(fpath=fpath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.