Skip to content

Commit e88f156

Browse files
author
Laurent
committed
update CONTRIBUTING.md
1 parent 293458a commit e88f156

File tree

1 file changed

+54
-22
lines changed

1 file changed

+54
-22
lines changed

CONTRIBUTING.md

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
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.
1+
We are happy to accept contributions from everyone.
2+
Feel free to browse our [bounty list](https://www.finegrain.ai/bounties) to find a task you would like to work on.
23

34
This document describes the process for contributing to Refiners.
45

56
## Licensing
67

7-
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.
8+
Refiners is a library that is freely available to use and modify under the MIT License.
9+
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.
10+
It's worth noting that some open-source licenses can also be problematic.
11+
For instance, we'd need to redistribute an Apache 2.0 license if you're using code from an Apache 2.0 codebase.
812

913
## Design principles
1014

@@ -17,73 +21,101 @@ We do not enforce strict rules on the design of the code, but we do have a few g
1721

1822
## Setting up your environment
1923

20-
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.
24+
We use [Rye](https://rye-up.com/guide/installation/) to manage our development environment.
25+
Please follow the instructions on the Rye website to install it.
2126

2227
Once Rye is installed, you can clone the repository and run `rye sync` to install the dependencies.
2328

24-
## Linting
29+
You should regularly update your Rye version by running `rye self update`.
2530

26-
We use the standard integration of [ruff](https://docs.astral.sh/ruff/) in Rye to lint and format our code. You can lint your code by running:
31+
## Linting
2732

33+
We use the standard integration of [ruff](https://docs.astral.sh/ruff/) in Rye to lint and format our code.
34+
You can lint your code by running:
2835
```bash
2936
rye fmt
3037
rye lint --fix
3138
```
3239

33-
We also enforce strict type checking with [pyright](https://github.com/microsoft/pyright). You can run the type checker with:
40+
You should also check for typos, by running:
41+
```bash
42+
rye run typos
43+
```
3444

45+
We also enforce strict type checking with [pyright](https://github.com/microsoft/pyright). You can run the type checker with:
3546
```bash
3647
rye run pyright
3748
```
3849

39-
## Running the tests
50+
## Getting the weights
4051

41-
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.
52+
Since refiners re-implements models using fluxion, we can't directly use the weights from their original implementations, we need to convert them to the correct format.
53+
We provide already converted weights for some models on our huggingface organization: https://huggingface.co/refiners
4254

43-
First, install test dependencies with:
55+
If you need to convert the weights yourself (e.g. for running the tests), you may use the `get_weights` command (c.f. `project.scripts` in `pyproject.toml`) to convert the weights. This command will automatically download all original weights and convert them.
4456

45-
```bash
46-
rye sync --all-features
47-
```
57+
### Contributing a new model conversion
58+
59+
1. Add a new file in the `refiners.conversion.models` module, if necessary.
60+
2. Instantiate a new `WeightRecipe` object to declare how to translate the keys from the original weights to the refiners keys.
61+
3. Instantiate a new `Conversion` object to relate the original weights, the converted weights and the recipe.
62+
4. Update the associated `__init__.py` and `cli.py` files.
4863

49-
Then, download and convert all the necessary weights. Be aware that this will use around 100 GB of disk space:
64+
Note: The conversion process is not always straightforward, we would prefer if you could use the above steps (since it's the most declarative way to convert the weights),
65+
although alternative methods are acceptable if they are well documented (you may find some examples in the existing conversion scripts).
5066

67+
## Running the tests
68+
69+
Running end-to-end tests is pretty compute-intensive.
70+
To test everything, you must convert all the model weights to the correct format before you can run them.
71+
See the above section to learn how to convert the weights.
72+
73+
First, install test dependencies with:
5174
```bash
52-
python scripts/prepare_test_weights.py
75+
rye sync --all-features
5376
```
5477

5578
Some tests require cloning the original implementation of the model as they use `torch.hub.load`:
56-
5779
```bash
5880
git clone git@github.com:facebookresearch/dinov2.git tests/repos/dinov2
81+
git clone git@github.com:microsoft/Swin-Transformer.git tests/repos/Swin-Transformer
5982
```
6083

6184
Finally, run the tests:
62-
6385
```bash
6486
rye run pytest
6587
```
6688

6789
The `-k` option is handy to run a subset of tests that match a given expression, e.g.:
68-
6990
```bash
70-
rye run pytest -k diffusion_std_init_image
91+
rye run pytest -k "diffusion_std_init_image" -v
92+
rye run pytest -k "not e2e" -v
93+
rye run pytest -k "e2e" -v
7194
```
7295

73-
You can enforce running tests on CPU. Tests that require a GPU will be skipped.
96+
Some tests require a GPU, and may sometime OOM if you test a lot of models sequentially.
97+
You can re-run the failed tests with:
98+
```bash
99+
pytest -k "e2e" -v --last-failed
100+
```
74101

102+
You can modify the following environment variables to change the behavior of the tests:
75103
```bash
76-
REFINERS_TEST_DEVICE=cpu rye run pytest
104+
export REFINERS_USE_LOCAL_WEIGHTS=1 # checkpoints will be loaded from the local hub, instead of the hf hub
105+
export REFINERS_TEST_DEVICE=cpu # tests that require a GPU will be skipped
106+
export REFINERS_HUB_PATH=/path/to/hub # default is ./tests/weights
107+
export REFINERS_TEST_DATASETS_DIR=/path/to/datasets # default it ./tests/datasets
108+
export REFINERS_TEST_REPOS_DIR=/path/to/repos # default is ./tests/repos
77109
```
78110

79-
You can collect [code coverage](https://github.com/nedbat/coveragepy) data while running tests with, e.g.:
111+
### Code coverage
80112

113+
You can collect [code coverage](https://github.com/nedbat/coveragepy) data while running tests with, e.g.:
81114
```bash
82115
rye run test-cov
83116
```
84117

85118
Then, browse the corresponding HTML report with:
86-
87119
```bash
88120
rye run serve-cov-report
89121
```

0 commit comments

Comments
 (0)