card's code snippet using 1024 model and not 512 ("PixArt-alpha/PixArt-Sigma-XL-2-1024-MS"), if we fix it it will crash when generating validaton images

#3
by humanfornow - opened

This code (using the correct model size, 512) ...

import torch
from diffusers import Transformer2DModel, PixArtSigmaPipeline

device = torch.device("cuda:3" if torch.cuda.is_available() else "cpu")
weight_dtype = torch.float16

pipe = PixArtSigmaPipeline.from_pretrained(
    "PixArt-alpha/PixArt-Sigma-XL-2-512-MS",    #<---------------  
    torch_dtype=weight_dtype,
    use_safetensors=True,
)
pipe.to(device)

# Enable memory optimizations.
# pipe.enable_model_cpu_offload()

prompt = "A small cactus with a happy face in the Sahara desert."
image = pipe(prompt).images[0]
image.save("./catcus.png")

generates the following error

Entry Not Found for url: https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-512-MS/resolve/main/model_index.json.

I was facing the same issue. You can actually download the safetensors and config file and load the transformer manually.

from diffusers import Transformer2DModel, PixArtSigmaPipeline
import json
from safetensors.torch import load_file
import torch

pipe = PixArtSigmaPipeline.from_pretrained(
    "PixArt-alpha/PixArt-Sigma-XL-2-1024-MS", 
    torch_dtype=torch.float16,
    use_safetensors=True,
) 
config = json.load(open("config.json"))
state_dict = load_file("diffusion_pytorch_model.safetensors")
transformer = Transformer2DModel(**config)
transformer.load_state_dict(state_dict)
pipe.transformer = transformer

Sign up or log in to comment