Commit
•
8215975
1
Parent(s):
a23e402
Add diffusers example (#5)
Browse files- Add diffusers example (f38af4171bea08368e6ffe5a988df3b0bbe960b4)
Co-authored-by: Suraj Patil <valhalla@users.noreply.huggingface.co>
README.md
CHANGED
@@ -14,7 +14,7 @@ This `stable-diffusion-2` model is resumed from [stable-diffusion-2-base](https:
|
|
14 |
![image](https://github.com/Stability-AI/stablediffusion/blob/main/assets/stable-samples/txt2img/768/merged-0005.png?raw=true)
|
15 |
|
16 |
- Use it with the [`stablediffusion`](https://github.com/Stability-AI/stablediffusion) repository: download the `768-v-ema.ckpt` [here](https://huggingface.co/stabilityai/stable-diffusion-2/blob/main/768-v-ema.ckpt).
|
17 |
-
- Use it with 🧨 diffusers
|
18 |
|
19 |
## Model Details
|
20 |
- **Developed by:** Robin Rombach, Patrick Esser
|
@@ -34,6 +34,37 @@ This `stable-diffusion-2` model is resumed from [stable-diffusion-2-base](https:
|
|
34 |
pages = {10684-10695}
|
35 |
}
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# Uses
|
38 |
|
39 |
## Direct Use
|
|
|
14 |
![image](https://github.com/Stability-AI/stablediffusion/blob/main/assets/stable-samples/txt2img/768/merged-0005.png?raw=true)
|
15 |
|
16 |
- Use it with the [`stablediffusion`](https://github.com/Stability-AI/stablediffusion) repository: download the `768-v-ema.ckpt` [here](https://huggingface.co/stabilityai/stable-diffusion-2/blob/main/768-v-ema.ckpt).
|
17 |
+
- Use it with 🧨 [`diffusers`](https://huggingface.co/stabilityai/stable-diffusion-2#model-details#Examples)
|
18 |
|
19 |
## Model Details
|
20 |
- **Developed by:** Robin Rombach, Patrick Esser
|
|
|
34 |
pages = {10684-10695}
|
35 |
}
|
36 |
|
37 |
+
|
38 |
+
## Examples
|
39 |
+
|
40 |
+
Using the [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run Stable Diffusion 2 in a simple and efficient manner.
|
41 |
+
|
42 |
+
```bash
|
43 |
+
pip install --upgrade git+https://github.com/huggingface/diffusers.git transformers accelerate scipy
|
44 |
+
```
|
45 |
+
Running the pipeline (if you don't swap the scheduler it will run with the default DDIM, in this example we are swapping it to EulerDiscreteScheduler):
|
46 |
+
|
47 |
+
```python
|
48 |
+
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
49 |
+
|
50 |
+
model_id = "stabilityai/stable-diffusion-2"
|
51 |
+
|
52 |
+
# Use the Euler scheduler here instead
|
53 |
+
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
|
54 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, revision="fp16", torch_dtype=torch.float16)
|
55 |
+
pipe = pipe.to("cuda")
|
56 |
+
|
57 |
+
prompt = "a photo of an astronaut riding a horse on mars"
|
58 |
+
image = pipe(prompt, height=768, width=768).images[0]
|
59 |
+
|
60 |
+
image.save("astronaut_rides_horse.png")
|
61 |
+
```
|
62 |
+
|
63 |
+
**Notes**:
|
64 |
+
- Despite not being a dependency, we highly recommend you to install [xformers](https://github.com/facebookresearch/xformers) for memory efficient attention (better performance)
|
65 |
+
- If you have low GPU RAM available, make sure to add a `pipe.enable_attention_slicing()` after sending it to `cuda` for less VRAM usage (to the cost of speed)
|
66 |
+
|
67 |
+
|
68 |
# Uses
|
69 |
|
70 |
## Direct Use
|