wilsonHuggingFace commited on
Commit
4f6e2c7
·
verified ·
1 Parent(s): 9afd21e

Create StableCascade.py

Browse files
Files changed (1) hide show
  1. StableCascade.py +53 -0
StableCascade.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # cascade
2
+ # https://hf-mirror.com/stabilityai/stable-cascade
3
+ # https://hf-mirror.com/stabilityai/stable-cascade-prior
4
+
5
+ import torch
6
+ from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
7
+
8
+ prompt = "an image of a shiba inu, donning a spacesuit and helmet"
9
+ negative_prompt = ""
10
+
11
+ prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", variant="bf16", torch_dtype=torch.bfloat16)
12
+ decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.float16)
13
+
14
+ prior.enable_model_cpu_offload()
15
+ prior_output = prior(
16
+ prompt=prompt,
17
+ height=1024,
18
+ width=1024,
19
+ negative_prompt=negative_prompt,
20
+ guidance_scale=4.0,
21
+ num_images_per_prompt=1,
22
+ num_inference_steps=20
23
+ )
24
+
25
+ decoder.enable_model_cpu_offload()
26
+ decoder_output = decoder(
27
+ image_embeddings=prior_output.image_embeddings.to(torch.float16),
28
+ prompt=prompt,
29
+ negative_prompt=negative_prompt,
30
+ guidance_scale=0.0,
31
+ output_type="pil",
32
+ num_inference_steps=10
33
+ ).images[0]
34
+ decoder_output.save("cascade.png")
35
+
36
+
37
+ # ------------------------------------------
38
+
39
+
40
+ from diffusers import StableCascadeCombinedPipeline
41
+
42
+ pipe = StableCascadeCombinedPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.bfloat16)
43
+
44
+ prompt = "an image of a shiba inu, donning a spacesuit and helmet"
45
+ pipe(
46
+ prompt=prompt,
47
+ negative_prompt="",
48
+ num_inference_steps=10,
49
+ prior_num_inference_steps=20,
50
+ prior_guidance_scale=3.0,
51
+ width=1024,
52
+ height=1024,
53
+ ).images[0].save("cascade-combined.png")