Views
No views yet
[!IMPORTANT]
Make sure to upgrade diffusers to >= 0.28.0:pip install -U diffusers --upgradeIn addition make sure to installtransformers,safetensors,sentencepiece, andaccelerate:pip install transformers accelerate safetensors sentencepieceFordiffusers<0.28.0, check this script for help.
1import torch
2from diffusers import Transformer2DModel, PixArtSigmaPipeline
3
4device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
5weight_dtype = torch.float16
6
7pipe = PixArtSigmaPipeline.from_pretrained(
8 "dattrong/pixart-sigma-512",
9 torch_dtype=weight_dtype,
10 use_safetensors=True,
11)
12pipe.to(device)
13
14# Enable memory optimizations.
15# pipe.enable_model_cpu_offload()
16
17prompt = "A small cactus with a happy face in the Sahara desert."
18image = pipe(prompt).images[0]
19image.save("./catcus.png")torch >= 2.0, you can improve the inference speed by 20-30% with torch.compile. Simple wrap the unet with torch compile before running the pipeline:pipe.transformer = torch.compile(pipe.transformer, mode="reduce-overhead", fullgraph=True)pipe.enable_model_cpu_offload
instead of .to("cuda"):1- pipe.to("cuda")
2+ pipe.enable_model_cpu_offload()