Views
No views yet

StableCascade Github repository (https://github.com/Stability-AI/StableCascade).

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.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.pip install diffusers1import torch
2from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
3
4prompt = "an image of a shiba inu, donning a spacesuit and helmet"
5negative_prompt = ""
6
7prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", variant="bf16", torch_dtype=torch.bfloat16)
8decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.float16)
9
10prior.enable_model_cpu_offload()
11prior_output = prior(
12 prompt=prompt,
13 height=1024,
14 width=1024,
15 negative_prompt=negative_prompt,
16 guidance_scale=4.0,
17 num_images_per_prompt=1,
18 num_inference_steps=20
19)
20
21decoder.enable_model_cpu_offload()
22decoder_output = decoder(
23 image_embeddings=prior_output.image_embeddings.to(torch.float16),
24 prompt=prompt,
25 negative_prompt=negative_prompt,
26 guidance_scale=0.0,
27 output_type="pil",
28 num_inference_steps=10
29).images[0]
30decoder_output.save("cascade.png")1import torch
2from diffusers import (
3 StableCascadeDecoderPipeline,
4 StableCascadePriorPipeline,
5 StableCascadeUNet,
6)
7
8prompt = "an image of a shiba inu, donning a spacesuit and helmet"
9negative_prompt = ""
10
11prior_unet = StableCascadeUNet.from_pretrained("stabilityai/stable-cascade-prior", subfolder="prior_lite")
12decoder_unet = StableCascadeUNet.from_pretrained("stabilityai/stable-cascade", subfolder="decoder_lite")
13
14prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", prior=prior_unet)
15decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", decoder=decoder_unet)
16
17prior.enable_model_cpu_offload()
18prior_output = prior(
19 prompt=prompt,
20 height=1024,
21 width=1024,
22 negative_prompt=negative_prompt,
23 guidance_scale=4.0,
24 num_images_per_prompt=1,
25 num_inference_steps=20
26)
27
28decoder.enable_model_cpu_offload()
29decoder_output = decoder(
30 image_embeddings=prior_output.image_embeddings,
31 prompt=prompt,
32 negative_prompt=negative_prompt,
33 guidance_scale=0.0,
34 output_type="pil",
35 num_inference_steps=10
36).images[0]
37decoder_output.save("cascade.png")from_single_filefrom_single_file method in the StableCascadeUNet.1import torch
2from diffusers import (
3 StableCascadeDecoderPipeline,
4 StableCascadePriorPipeline,
5 StableCascadeUNet,
6)
7
8prompt = "an image of a shiba inu, donning a spacesuit and helmet"
9negative_prompt = ""
10
11prior_unet = StableCascadeUNet.from_single_file(
12 "https://huggingface.co/stabilityai/stable-cascade/resolve/main/stage_c_bf16.safetensors",
13 torch_dtype=torch.bfloat16
14)
15decoder_unet = StableCascadeUNet.from_single_file(
16 "https://huggingface.co/stabilityai/stable-cascade/blob/main/stage_b_bf16.safetensors",
17 torch_dtype=torch.bfloat16
18)
19
20prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", prior=prior_unet, torch_dtype=torch.bfloat16)
21decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", decoder=decoder_unet, torch_dtype=torch.bfloat16)
22
23prior.enable_model_cpu_offload()
24prior_output = prior(
25 prompt=prompt,
26 height=1024,
27 width=1024,
28 negative_prompt=negative_prompt,
29 guidance_scale=4.0,
30 num_images_per_prompt=1,
31 num_inference_steps=20
32)
33
34decoder.enable_model_cpu_offload()
35decoder_output = decoder(
36 image_embeddings=prior_output.image_embeddings,
37 prompt=prompt,
38 negative_prompt=negative_prompt,
39 guidance_scale=0.0,
40 output_type="pil",
41 num_inference_steps=10
42).images[0]
43decoder_output.save("cascade-single-file.png")StableCascadeCombinedPipeline1from diffusers import StableCascadeCombinedPipeline
2
3pipe = StableCascadeCombinedPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.bfloat16)
4
5prompt = "an image of a shiba inu, donning a spacesuit and helmet"
6pipe(
7 prompt=prompt,
8 negative_prompt="",
9 num_inference_steps=10,
10 prior_num_inference_steps=20,
11 prior_guidance_scale=3.0,
12 width=1024,
13 height=1024,
14).images[0].save("cascade-combined.png")