update README
Browse files
README.md
CHANGED
@@ -68,38 +68,158 @@ steps), SDXL (50 inference steps), SDXL Turbo (1 inference step) and Würstchen
|
|
68 |
|
69 |
## Code Example
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
```python
|
72 |
import torch
|
73 |
from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
|
74 |
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
prompt = "
|
82 |
negative_prompt = ""
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
prior_output = prior(
|
85 |
prompt=prompt,
|
86 |
height=1024,
|
87 |
width=1024,
|
88 |
negative_prompt=negative_prompt,
|
89 |
guidance_scale=4.0,
|
90 |
-
num_images_per_prompt=
|
91 |
num_inference_steps=20
|
92 |
)
|
|
|
|
|
93 |
decoder_output = decoder(
|
94 |
-
image_embeddings=prior_output.image_embeddings
|
95 |
prompt=prompt,
|
96 |
negative_prompt=negative_prompt,
|
97 |
guidance_scale=0.0,
|
98 |
output_type="pil",
|
99 |
num_inference_steps=10
|
100 |
-
).images
|
|
|
|
|
101 |
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
```
|
104 |
|
105 |
## Uses
|
|
|
68 |
|
69 |
## Code Example
|
70 |
|
71 |
+
**Note:** In order to use the `torch.bfloat16` data type with the `StableCascadeDecoderPipeline` you need to have PyTorch 2.2.0 or higher installed. This also means that using the `StableCascadeCombinedPipeline` with `torch.bfloat16` requires PyTorch 2.2.0 or higher, since it calls the StableCascadeDecoderPipeline internally.
|
72 |
+
|
73 |
+
If it is not possible to install PyTorch 2.2.0 or higher in your environment, the `StableCascadeDecoderPipeline` can be used on its own with the torch.float16 data type. You can download the full precision or bf16 variant weights for the pipeline and cast the weights to torch.float16.
|
74 |
+
|
75 |
+
```shell
|
76 |
+
pip install diffusers
|
77 |
+
```
|
78 |
+
|
79 |
```python
|
80 |
import torch
|
81 |
from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
|
82 |
|
83 |
+
prompt = "an image of a shiba inu, donning a spacesuit and helmet"
|
84 |
+
negative_prompt = ""
|
85 |
+
|
86 |
+
prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", variant="bf16", torch_dtype=torch.bfloat16)
|
87 |
+
decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.float16)
|
88 |
+
|
89 |
+
prior.enable_model_cpu_offload()
|
90 |
+
prior_output = prior(
|
91 |
+
prompt=prompt,
|
92 |
+
height=1024,
|
93 |
+
width=1024,
|
94 |
+
negative_prompt=negative_prompt,
|
95 |
+
guidance_scale=4.0,
|
96 |
+
num_images_per_prompt=1,
|
97 |
+
num_inference_steps=20
|
98 |
+
)
|
99 |
+
|
100 |
+
decoder.enable_model_cpu_offload()
|
101 |
+
decoder_output = decoder(
|
102 |
+
image_embeddings=prior_output.image_embeddings.to(torch.float16),
|
103 |
+
prompt=prompt,
|
104 |
+
negative_prompt=negative_prompt,
|
105 |
+
guidance_scale=0.0,
|
106 |
+
output_type="pil",
|
107 |
+
num_inference_steps=10
|
108 |
+
).images[0]
|
109 |
+
decoder_output.save("cascade.png")
|
110 |
+
```
|
111 |
+
|
112 |
+
### Using the Lite Version of the Stage B and Stage C models
|
113 |
+
|
114 |
+
```python
|
115 |
+
import torch
|
116 |
+
from diffusers import (
|
117 |
+
StableCascadeDecoderPipeline,
|
118 |
+
StableCascadePriorPipeline,
|
119 |
+
StableCascadeUNet,
|
120 |
+
)
|
121 |
+
|
122 |
+
prompt = "an image of a shiba inu, donning a spacesuit and helmet"
|
123 |
+
negative_prompt = ""
|
124 |
+
|
125 |
+
prior_unet = StableCascadeUNet.from_pretrained("stabilityai/stable-cascade-prior", subfolder="prior_lite")
|
126 |
+
decoder_unet = StableCascadeUNet.from_pretrained("stabilityai/stable-cascade", subfolder="decoder_lite")
|
127 |
+
|
128 |
+
prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", prior=prior_unet)
|
129 |
+
decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", decoder=decoder_unet)
|
130 |
+
|
131 |
+
prior.enable_model_cpu_offload()
|
132 |
+
prior_output = prior(
|
133 |
+
prompt=prompt,
|
134 |
+
height=1024,
|
135 |
+
width=1024,
|
136 |
+
negative_prompt=negative_prompt,
|
137 |
+
guidance_scale=4.0,
|
138 |
+
num_images_per_prompt=1,
|
139 |
+
num_inference_steps=20
|
140 |
+
)
|
141 |
+
|
142 |
+
decoder.enable_model_cpu_offload()
|
143 |
+
decoder_output = decoder(
|
144 |
+
image_embeddings=prior_output.image_embeddings,
|
145 |
+
prompt=prompt,
|
146 |
+
negative_prompt=negative_prompt,
|
147 |
+
guidance_scale=0.0,
|
148 |
+
output_type="pil",
|
149 |
+
num_inference_steps=10
|
150 |
+
).images[0]
|
151 |
+
decoder_output.save("cascade.png")
|
152 |
+
```
|
153 |
+
|
154 |
+
### Loading original checkpoints with `from_single_file`
|
155 |
+
|
156 |
+
Loading the original format checkpoints is supported via `from_single_file` method in the StableCascadeUNet.
|
157 |
|
158 |
+
```python
|
159 |
+
import torch
|
160 |
+
from diffusers import (
|
161 |
+
StableCascadeDecoderPipeline,
|
162 |
+
StableCascadePriorPipeline,
|
163 |
+
StableCascadeUNet,
|
164 |
+
)
|
165 |
|
166 |
+
prompt = "an image of a shiba inu, donning a spacesuit and helmet"
|
167 |
negative_prompt = ""
|
168 |
|
169 |
+
prior_unet = StableCascadeUNet.from_single_file(
|
170 |
+
"https://huggingface.co/stabilityai/stable-cascade/resolve/main/stage_c_bf16.safetensors",
|
171 |
+
torch_dtype=torch.bfloat16
|
172 |
+
)
|
173 |
+
decoder_unet = StableCascadeUNet.from_single_file(
|
174 |
+
"https://huggingface.co/stabilityai/stable-cascade/blob/main/stage_b_bf16.safetensors",
|
175 |
+
torch_dtype=torch.bfloat16
|
176 |
+
)
|
177 |
+
|
178 |
+
prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", prior=prior_unet, torch_dtype=torch.bfloat16)
|
179 |
+
decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", decoder=decoder_unet, torch_dtype=torch.bfloat16)
|
180 |
+
|
181 |
+
prior.enable_model_cpu_offload()
|
182 |
prior_output = prior(
|
183 |
prompt=prompt,
|
184 |
height=1024,
|
185 |
width=1024,
|
186 |
negative_prompt=negative_prompt,
|
187 |
guidance_scale=4.0,
|
188 |
+
num_images_per_prompt=1,
|
189 |
num_inference_steps=20
|
190 |
)
|
191 |
+
|
192 |
+
decoder.enable_model_cpu_offload()
|
193 |
decoder_output = decoder(
|
194 |
+
image_embeddings=prior_output.image_embeddings,
|
195 |
prompt=prompt,
|
196 |
negative_prompt=negative_prompt,
|
197 |
guidance_scale=0.0,
|
198 |
output_type="pil",
|
199 |
num_inference_steps=10
|
200 |
+
).images[0]
|
201 |
+
decoder_output.save("cascade-single-file.png")
|
202 |
+
```
|
203 |
|
204 |
+
### Using the `StableCascadeCombinedPipeline`
|
205 |
+
|
206 |
+
```python
|
207 |
+
from diffsers import StableCascadeCombinedPipeline
|
208 |
+
|
209 |
+
pipe = StableCascadeCombinedPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.bfloat16)
|
210 |
+
|
211 |
+
prompt = "an image of a shiba inu, donning a spacesuit and helmet"
|
212 |
+
negative_prompt = ""
|
213 |
+
|
214 |
+
pipe(
|
215 |
+
prompt="photorealistic portrait artwork of an floral robot with a dark night cyberpunk city background",
|
216 |
+
negative_prompt="",
|
217 |
+
num_inference_steps=10,
|
218 |
+
prior_num_inference_steps=20,
|
219 |
+
prior_guidance_scale=3.0,
|
220 |
+
width=1024,
|
221 |
+
height=1024,
|
222 |
+
).images[0].save("cascade-combined.png")
|
223 |
```
|
224 |
|
225 |
## Uses
|