refiners/CONTRIBUTING.md
limiteinductive 86c54977b9 replace poetry by rye for python dependency management
Co-authored-by: Cédric Deltheil <cedric@deltheil.me>
Co-authored-by: Pierre Chapuis <git@catwell.info>
2023-12-08 17:40:10 +01:00

75 lines
3 KiB
Markdown

We are happy to accept contributions from everyone. Feel free to browse our [bounty list](https://www.finegrain.ai/bounties) to find a task you would like to work on.
This document describes the process for contributing to Refiners.
## Licensing
Refiners is a library that is freely available to use and modify under the MIT License. It's essential to exercise caution when using external code, as any code that can affect the licensing of Refiners, including proprietary code, should not be copied and pasted. It's worth noting that some open-source licenses can also be problematic. For instance, we'd need to redistribute an Apache 2.0 license if you're using code from an Apache 2.0 codebase.
## Design principles
We do not enforce strict rules on the design of the code, but we do have a few guidelines that we try to follow:
- No dead code. We keep the codebase clean and remove unnecessary code/functionality.
- No unnecessary dependencies. We keep the number of dependencies to a minimum and only add new ones if necessary.
- Separate concerns. We separate the code into different modules and avoid having too many dependencies between modules. In particular, we try not to revisit existing code/models when adding new functionality. Instead, we add new functionality in a separate module with the `Adapter` pattern.
- Declarative style. We make the code as declarative, self-documenting, and easily read as possible. By reading the model's `repr`, you should understand how it works. We use explicit names for the different components of the models or the variables in the code.
## Setting up your environment
We use [Rye](https://rye-up.com/guide/installation/) to manage our development environment. Please follow the instructions on the Rye website to install it.
Once Rye is installed, you can clone the repository and run `rye sync` to install the dependencies.
## Linting
We use [ruff](https://docs.astral.sh/ruff/) to lint our code. You can lint your code by running.
```bash
rye run lint
```
We also enforce strict type checking with [pyright](https://github.com/microsoft/pyright). You can run the type checker with:
```bash
rye run pyright
```
## Running the tests
Running end-to-end tests is pretty compute-intensive, and you must convert all the model weights to the correct format before you can run them.
First, install test dependencies with:
```bash
rye sync --features test
```
Then, download and convert all the necessary weights. Be aware that this will use around 50 GB of disk space:
```bash
./scripts/prepare-test-weights.sh
```
To run all the tests, you will need to set the following environment variables:
```bash
export REFINERS_TEST_DEVICE=cuda:0
export REFINERS_TEST_WEIGHTS_DIR=$(pwd)/tests/weights
rye run pytest
```
In particular, `-k` is handy only to run tests that match a given expression, e.g.:
```bash
rye run pytest -k diffusion_std_init_image tests/e2e/test_diffusion.py
```
You can also run tests that are lightweight and will run on CPU:
```bash
rye run pytest -k "not test_diffusion"
```