Alex Birch
commited on
Commit
•
f957023
1
Parent(s):
5e22649
update usage example to supply WD1.4 VAE, to save disk space
Browse files
README.md
CHANGED
@@ -14,12 +14,28 @@ Float16 is [all you need](https://twitter.com/Birchlabs/status/15999038832786636
|
|
14 |
```python
|
15 |
# make sure you're logged in with `huggingface-cli login`
|
16 |
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
|
|
|
17 |
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
|
18 |
import torch
|
19 |
from torch import Generator, compile
|
20 |
from PIL import Image
|
21 |
from typing import List
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# variant=None
|
24 |
# variant='ink'
|
25 |
# variant='mofu'
|
@@ -28,34 +44,24 @@ variant='radiance'
|
|
28 |
pipe: StableDiffusionPipeline = StableDiffusionPipeline.from_pretrained(
|
29 |
'Birchlabs/wd-1-5-beta3-unofficial',
|
30 |
torch_dtype=torch.float16,
|
|
|
|
|
31 |
variant=variant,
|
32 |
)
|
33 |
pipe.to('cuda')
|
34 |
compile(pipe.unet, mode='reduce-overhead')
|
35 |
|
36 |
-
# scheduler args documented here:
|
37 |
-
# https://github.com/huggingface/diffusers/blob/0392eceba8d42b24fcecc56b2cc1f4582dbefcc4/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py#L83
|
38 |
-
scheduler = DPMSolverMultistepScheduler.from_config(
|
39 |
-
pipe.scheduler.config,
|
40 |
-
# sde-dpmsolver++ is very new. if your diffusers version doesn't have it: use 'dpmsolver++' instead.
|
41 |
-
algorithm_type='sde-dpmsolver++',
|
42 |
-
solver_order=2,
|
43 |
-
# solver_type='heun' may give a sharper image. Cheng Lu reckons midpoint is better.
|
44 |
-
solver_type='midpoint',
|
45 |
-
use_karras_sigmas=True,
|
46 |
-
)
|
47 |
-
pipe.scheduler = scheduler
|
48 |
-
|
49 |
# WD1.5 was trained on area=896**2 and no side longer than 1152
|
50 |
sqrt_area=896
|
51 |
-
#
|
52 |
-
|
53 |
-
height = int(sqrt_area*aspect_ratio)
|
54 |
width = sqrt_area**2//height
|
55 |
|
56 |
prompt = 'artoria pendragon (fate), reddizen, 1girl, best aesthetic, best quality, blue dress, full body, white shirt, blonde hair, looking at viewer, hair between eyes, floating hair, green eyes, blue ribbon, long sleeves, juliet sleeves, light smile, hair ribbon, outdoors, painting (medium), traditional media'
|
57 |
negative_prompt = 'lowres, bad anatomy, bad hands, missing fingers, extra fingers, blurry, mutation, deformed face, ugly, bad proportions, monster, cropped, worst quality, jpeg, bad posture, long body, long neck, jpeg artifacts, deleted, bad aesthetic, realistic, real life, instagram'
|
58 |
|
|
|
|
|
59 |
out: StableDiffusionPipelineOutput = pipe.__call__(
|
60 |
prompt,
|
61 |
negative_prompt=negative_prompt,
|
@@ -102,8 +108,31 @@ Except the "base" aesthetic was a special case, where I didn't pass any `--varia
|
|
102 |
|
103 |
### Why is there a `vae` folder
|
104 |
|
105 |
-
The `vae` folder contains copies of WD 1.4's VAE, to make it easier to load stable-diffusion via
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
## Original model card
|
109 |
|
|
|
14 |
```python
|
15 |
# make sure you're logged in with `huggingface-cli login`
|
16 |
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
|
17 |
+
from diffusers.models.autoencoder_kl import AutoencoderKL
|
18 |
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
|
19 |
import torch
|
20 |
from torch import Generator, compile
|
21 |
from PIL import Image
|
22 |
from typing import List
|
23 |
|
24 |
+
vae: AutoencoderKL = AutoencoderKL.from_pretrained('hakurei/waifu-diffusion', subfolder='vae', torch_dtype=torch.float16)
|
25 |
+
|
26 |
+
# scheduler args documented here:
|
27 |
+
# https://github.com/huggingface/diffusers/blob/0392eceba8d42b24fcecc56b2cc1f4582dbefcc4/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py#L83
|
28 |
+
scheduler: DPMSolverMultistepScheduler = DPMSolverMultistepScheduler.from_pretrained(
|
29 |
+
'Birchlabs/wd-1-5-beta3-unofficial',
|
30 |
+
subfolder='scheduler',
|
31 |
+
# sde-dpmsolver++ is very new. if your diffusers version doesn't have it: use 'dpmsolver++' instead.
|
32 |
+
algorithm_type='sde-dpmsolver++',
|
33 |
+
solver_order=2,
|
34 |
+
# solver_type='heun' may give a sharper image. Cheng Lu reckons midpoint is better.
|
35 |
+
solver_type='midpoint',
|
36 |
+
use_karras_sigmas=True,
|
37 |
+
)
|
38 |
+
|
39 |
# variant=None
|
40 |
# variant='ink'
|
41 |
# variant='mofu'
|
|
|
44 |
pipe: StableDiffusionPipeline = StableDiffusionPipeline.from_pretrained(
|
45 |
'Birchlabs/wd-1-5-beta3-unofficial',
|
46 |
torch_dtype=torch.float16,
|
47 |
+
vae=vae,
|
48 |
+
scheduler=scheduler,
|
49 |
variant=variant,
|
50 |
)
|
51 |
pipe.to('cuda')
|
52 |
compile(pipe.unet, mode='reduce-overhead')
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# WD1.5 was trained on area=896**2 and no side longer than 1152
|
55 |
sqrt_area=896
|
56 |
+
# note: pipeline requires width and height to be multiples of 8
|
57 |
+
height = 1024
|
|
|
58 |
width = sqrt_area**2//height
|
59 |
|
60 |
prompt = 'artoria pendragon (fate), reddizen, 1girl, best aesthetic, best quality, blue dress, full body, white shirt, blonde hair, looking at viewer, hair between eyes, floating hair, green eyes, blue ribbon, long sleeves, juliet sleeves, light smile, hair ribbon, outdoors, painting (medium), traditional media'
|
61 |
negative_prompt = 'lowres, bad anatomy, bad hands, missing fingers, extra fingers, blurry, mutation, deformed face, ugly, bad proportions, monster, cropped, worst quality, jpeg, bad posture, long body, long neck, jpeg artifacts, deleted, bad aesthetic, realistic, real life, instagram'
|
62 |
|
63 |
+
# pipeline invocation args documented here:
|
64 |
+
# https://github.com/huggingface/diffusers/blob/0392eceba8d42b24fcecc56b2cc1f4582dbefcc4/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#LL544C18-L544C18
|
65 |
out: StableDiffusionPipelineOutput = pipe.__call__(
|
66 |
prompt,
|
67 |
negative_prompt=negative_prompt,
|
|
|
108 |
|
109 |
### Why is there a `vae` folder
|
110 |
|
111 |
+
The `vae` folder contains copies of WD 1.4's VAE, to make it easier to load stable-diffusion via diffusers [pipelines](https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines#readme).
|
112 |
+
I saved a duplicate of the VAE for each variant.
|
113 |
+
|
114 |
+
So you _can_ skip the `vae` arg, and load the pipeline like this:
|
115 |
+
|
116 |
+
```python
|
117 |
+
pipe: StableDiffusionPipeline = StableDiffusionPipeline.from_pretrained(
|
118 |
+
'Birchlabs/wd-1-5-beta3-unofficial',
|
119 |
+
torch_dtype=torch.float16,
|
120 |
+
variant='radiance'
|
121 |
+
)
|
122 |
+
```
|
123 |
+
|
124 |
+
But I recommend to supply the WD1.4 `vae` explicitly, to save disk space (i.e. because you already had WD1.4, or because you intend to try multiple variants of WD1.5 and don't want to download VAE duplicates for each variant):
|
125 |
+
|
126 |
+
```python
|
127 |
+
vae: AutoencoderKL = AutoencoderKL.from_pretrained('hakurei/waifu-diffusion', subfolder='vae', torch_dtype=torch.float16)
|
128 |
+
|
129 |
+
pipe: StableDiffusionPipeline = StableDiffusionPipeline.from_pretrained(
|
130 |
+
'Birchlabs/wd-1-5-beta3-unofficial',
|
131 |
+
torch_dtype=torch.float16,
|
132 |
+
variant='radiance'
|
133 |
+
vae=vae,
|
134 |
+
)
|
135 |
+
```
|
136 |
|
137 |
## Original model card
|
138 |
|