You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
2
3
3
4
This document describes the process for contributing to Refiners.
4
5
5
6
## Licensing
6
7
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.
8
12
9
13
## Design principles
10
14
@@ -17,73 +21,108 @@ We do not enforce strict rules on the design of the code, but we do have a few g
17
21
18
22
## Setting up your environment
19
23
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.
21
26
22
27
Once Rye is installed, you can clone the repository and run `rye sync` to install the dependencies.
23
28
24
-
## Linting
29
+
You should regularly update your Rye version by running `rye self update`.
25
30
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
27
32
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:
28
35
```bash
29
36
rye fmt
30
37
rye lint --fix
31
38
```
32
39
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
+
```
34
44
45
+
We also enforce strict type checking with [pyright](https://github.com/microsoft/pyright). You can run the type checker with:
35
46
```bash
36
47
rye run pyright
37
48
```
38
49
39
-
## Running the tests
50
+
## Getting the weights
40
51
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
42
54
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.
44
56
45
-
```bash
46
-
rye sync --all-features
47
-
```
57
+
### Contributing a new model conversion
48
58
49
-
Then, download and convert all the necessary weights. Be aware that this will use around 100 GB of disk space:
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.
63
+
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).
66
+
67
+
## Running the tests
50
68
69
+
Running end-to-end tests is pretty compute-intensive.
70
+
71
+
To test everything, you can either:
72
+
- Use `REFINERS_USE_LOCAL_WEIGHTS=1` and manually convert all the model weights to the correct format before running the tests. See the above section to learn how to convert the weights.
73
+
- Use `REFINER_USE_LOCAL_WEIGHTS=0` and automatically download the weights from the huggingface hub. This is the default behavior. Though since some weights aren't available on the hub, some tests may be skipped.
74
+
75
+
> [!WARNING]
76
+
> GPU tests are notoriously hard to reproduce accross different hardware. (see https://pytorch.org/docs/stable/notes/randomness.html)
77
+
> Our tests are designed to work on a single NVIDIA GeForce RTX 3090 24GB, with nvidia drivers v545.23.08 and cuda v12.3.
78
+
> If you have a different GPU/drivers, the tests may fail or give different results.
79
+
80
+
First, install test dependencies with:
51
81
```bash
52
-
python scripts/prepare_test_weights.py
82
+
rye sync --all-features
53
83
```
54
84
55
85
Some tests require cloning the original implementation of the model as they use `torch.hub.load`:
0 commit comments