sana1.6b-cache.py 895 Bytes
Newer Older
Hyunsung Lee's avatar
Hyunsung Lee committed
1
2
3
4
5
6
import torch
from diffusers import SanaPipeline

from nunchaku import NunchakuSanaTransformer2DModel
from nunchaku.caching.diffusers_adapters import apply_cache_on_pipe

7
transformer = NunchakuSanaTransformer2DModel.from_pretrained(
8
    "nunchaku-tech/nunchaku-sana/svdq-int4_r32-sana1.6b.safetensors"
9
)
Hyunsung Lee's avatar
Hyunsung Lee committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pipe = SanaPipeline.from_pretrained(
    "Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers",
    transformer=transformer,
    variant="bf16",
    torch_dtype=torch.bfloat16,
).to("cuda")
pipe.vae.to(torch.bfloat16)
pipe.text_encoder.to(torch.bfloat16)

apply_cache_on_pipe(pipe, residual_diff_threshold=0.25)

# WarmUp

prompt = "A cute 🐼 eating 🎋, ink drawing style"
image = pipe(
    prompt=prompt,
    height=1024,
    width=1024,
    guidance_scale=4.5,
    num_inference_steps=20,
    generator=torch.Generator().manual_seed(42),
).images[0]

33
image.save("sana1.6b-int4.png")