Skip to content

Commit 0620473

Browse files
LaurentLaurent2916
authored andcommitted
Refresh docs, remove references to old conversion scripts
1 parent c5d3d1c commit 0620473

File tree

8 files changed

+514
-276
lines changed

8 files changed

+514
-276
lines changed

docs/getting-started/advanced.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ We use Rye to maintain and release Refiners but it conforms to the standard Pyth
1010

1111
## Using stable releases from PyPI
1212

13-
Although we recommend using our development branch, we do [publish more stable releases to PyPI](https://pypi.org/project/refiners/) and you are welcome to use them in your project. However, note that the format of weights can be different from the current state of the development branch, so you will need the conversion scripts from the corresponding tag in GitHub, for instance [here for v0.2.0](https://github.com/finegrain-ai/refiners/tree/v0.2.0).
13+
Although we recommend using our development branch, we do publish more stable releases to [PyPI](https://pypi.org/project/refiners/) and you are welcome to use them in your project.
14+
They are also available directly on the [GitHub releases page](https://github.com/finegrain-ai/refiners/releases).
15+
However, beware that the format of weights can be different from the current state of the development branch.

docs/getting-started/recommended.md

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,100 @@ icon: material/star-outline
66

77
Refiners is still a young project and development is active, so to use the latest and greatest version of the framework we recommend you use the `main` branch from our development repository.
88

9-
Moreover, we recommend using [Rye](https://rye-up.com) which simplifies several things related to Python package management, so start by following the instructions to install it on your system.
9+
Moreover, we recommend using [Rye](https://rye.astral.sh/) which simplifies several things related to Python package management, so start by following the instructions to install it on your system.
1010

1111
## Installing
1212

1313
To try Refiners, clone the GitHub repository and install it with all optional features:
1414

1515
```bash
16-
git clone "git@github.com:finegrain-ai/refiners.git"
16+
git clone git@github.com:finegrain-ai/refiners.git
1717
cd refiners
1818
rye sync --all-features
1919
```
2020

2121
## Converting weights
2222

23-
The format of state dicts used by Refiners is custom and we do not redistribute model weights, but we provide conversion tools and working scripts for popular models. For instance, let us convert the autoencoder from Stable Diffusion 1.5:
23+
The format of state dicts used by Refiners is custom, so to use pretrained models you will need to convert weights.
24+
We provide conversion tools and pre-converted weights on our [HuggingFace organization](https://huggingface.co/refiners) for popular models.
2425

25-
```bash
26-
python "scripts/conversion/convert_diffusers_autoencoder_kl.py" --to "lda.safetensors"
26+
For instance, to use the autoencoder from Stable Diffusion 1.5:
27+
28+
### Use pre-converted weights
29+
30+
```py
31+
from huggingface_hub import hf_hub_download
32+
from refiners.foundationals.latent_diffusion.stable_diffusion_1.model import SD1Autoencoder
33+
34+
# download the pre-converted weights from the hub
35+
safetensors_path = hf_hub_download(
36+
repo_id="refiners/sd15.autoencoder",
37+
filename="model.safetensors",
38+
revision="9ce6af42e21fce64d74b1cab57a65aea82fd40ea", # optional
39+
)
40+
41+
# initialize the model
42+
model = SD1Autoencoder()
43+
44+
# load the pre-converted weights
45+
model.load_from_safetensors(safetensors_path)
46+
```
47+
48+
### Convert the weights yourself
49+
50+
If you want to convert the weights yourself, you can use the conversion tools we provide.
51+
52+
```py
53+
from refiners.conversion import autoencoder_sd15
54+
55+
# This function will:
56+
# - download the original weights from the internet, and save them to disk at a known location
57+
# (e.g. tests/weights/stable-diffusion-v1-5/stable-diffusion-v1-5/vae/diffusion_pytorch_model.safetensors)
58+
# - convert them to the refiners format, and save them to disk at a known location
59+
# (e.g. tests/weights/refiners/sd15.autoencoder/model.safetensors)
60+
autoencoder_sd15.runwayml.convert()
61+
62+
# get the path to the converted weights
63+
safetensors_path = autoencoder_sd15.runwayml.converted.local_path
64+
65+
# initialize the model
66+
model = SD1Autoencoder()
67+
68+
# load the converted weights
69+
model.load_from_safetensors(safetensors_path)
2770
```
2871

29-
If you need to convert weights for all models, check out `script/prepare_test_weights.py`.
72+
!!! note
73+
If you need to convert more model weights or all of them, check out the `refiners.conversion` module.
74+
75+
!!! warning
76+
Converting all the weights requires a lot of disk space and CPU time, so be prepared.
77+
Currently downloading all the original weights takes around ~100GB of disk space,
78+
and converting them all takes around ~70GB of disk space.
3079

3180
!!! warning
32-
Using `script/prepare_test_weights.py` requires a GPU with significant VRAM and a lot of disk space.
81+
Some conversion scripts may also require quite a bit of RAM, since they load the entire weights in memory,
82+
~16GB of RAM should be enough for most models, but some models may require more.
3383

34-
Now to check that it works copy your favorite 512x512 picture in the current directory as `input.png` and create `ldatest.py` with this content:
84+
85+
### Testing the conversion
86+
87+
To quickly check that the weights you got from the hub or converted yourself are correct, you can run the following snippet:
3588

3689
```py
3790
from PIL import Image
3891
from refiners.fluxion.utils import no_grad
39-
from refiners.foundationals.latent_diffusion.stable_diffusion_1.model import SD1Autoencoder
40-
41-
with no_grad():
42-
lda = SD1Autoencoder()
43-
lda.load_from_safetensors("lda.safetensors")
4492

45-
image = Image.open("input.png")
46-
latents = lda.image_to_latents(image)
47-
decoded = lda.latents_to_image(latents)
48-
decoded.save("output.png")
49-
```
93+
image = Image.open("input.png")
5094

51-
Run it:
95+
with no_grad():
96+
latents = model.image_to_latents(image)
97+
decoded = model.latents_to_image(latents)
5298

53-
```bash
54-
python ldatest.py
99+
decoded.save("output.png")
55100
```
56101

57-
Inspect `output.png`: it should be similar to `input.png` but have a few differences. Latent Autoencoders are good compressors!
102+
Inspect `output.png`, if the converted weights are correct, it should be similar to `input.png` (but have a few differences).
58103

59104
## Using Refiners in your own project
60105

@@ -63,20 +108,28 @@ So far you used Refiners as a standalone package, but if you want to create your
63108
```bash
64109
rye init --py "3.11" myproject
65110
cd myproject
66-
rye add --git "git@github.com:finegrain-ai/refiners.git" --features training refiners
111+
rye add refiners@git+https://github.com/finegrain-ai/refiners
67112
rye sync
68113
```
69114

70-
If you only intend to do inference and no training, you can drop `--features training`.
115+
If you intend to use Refiners for training, you can install the `training` feature:
71116

72-
To convert weights, you can either use a copy of the `refiners` repository as described above or add the `conversion` feature as a development dependency:
117+
```bash
118+
rye add refiners[training]@git+https://github.com/finegrain-ai/refiners
119+
```
120+
121+
Similarly, if you need to use the conversion tools we provide, you install the `conversion` feature:
73122

74123
```bash
75-
rye add --dev --git "git@github.com:finegrain-ai/refiners.git" --features conversion refiners
124+
rye add refiners[conversion]@git+https://github.com/finegrain-ai/refiners
76125
```
77126

78127
!!! note
79-
You will still need to download the conversion scripts independently if you go that route.
128+
You can install multiple features at once by separating them with a comma:
129+
130+
```bash
131+
rye add refiners[training,conversion]@git+https://github.com/finegrain-ai/refiners
132+
```
80133

81134
## What's next?
82135

0 commit comments

Comments
 (0)