diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Stable Diffusion 3 single file safetensors model with 8b quantized T5xxl returns zeroes, black image

Open hnhparitosh opened this issue 2 years ago • 3 comments

Describe the bug

Loading sd3_medium_incl_clips_t5xxlfp8.safetensors like the official example generates a black image of zeroes. People in community found same to be happening with fp16 model as well.

Related huggingface thread: https://huggingface.co/stabilityai/stable-diffusion-3-medium/discussions/161

Reproduction

import torch
from diffusers import StableDiffusion3Pipeline
import cv2
import numpy as np

pipe = StableDiffusion3Pipeline.from_single_file(
    "https://huggingface.co/stabilityai/stable-diffusion-3-medium/blob/main/sd3_medium_incl_clips_t5xxlfp8.safetensors",
    torch_dtype=torch.float16,
)
print('model loaded')
pipe = pipe.to('cuda')

image = pipe(
    "A cat holding a sign that says hello world",
    negative_prompt="",
    num_inference_steps=10,
    guidance_scale=7.0,
).images[0]

image.save('image.jpg')

Logs

No response

System Info

More details found here https://huggingface.co/stabilityai/stable-diffusion-3-medium/discussions/161

Who can help?

@yiyixuxu @sayakpaul @DN6 @asomoza

hnhparitosh avatar Jul 21 '24 12:07 hnhparitosh

It works in Kaggle's notebook with this environment:

- 🤗 Diffusers version: 0.29.2
- Platform: Linux-5.15.154+-x86_64-with-glibc2.31
- Python version: 3.10.13
- PyTorch version (GPU?): 2.1.2 (True)
- Flax version (CPU?/GPU?/TPU?): 0.8.4 (gpu)
- Jax version: 0.4.26
- JaxLib version: 0.4.26.dev20240504
- Huggingface_hub version: 0.23.4
- Transformers version: 4.42.3
- Accelerate version: 0.32.1
- PEFT version: not installed
- Bitsandbytes version: not installed
- Safetensors version: 0.4.3
- xFormers version: not installed
- Accelerator: Tesla P100-PCIE-16GB, 16384 MiB VRAM

I had to use pipe.enable_model_cpu_offload() rather than pipe = pipe.to('cuda'). Could you share the result of this command: diffusers-cli env?

Edit 1: When I try with torch==2.3.1+cu121, it gives black images :/

Edit 2: When I install diffusers from the source, it works again.

Edit 3: Duplicate of #8759.

mtolgacangoz avatar Jul 21 '24 14:07 mtolgacangoz

Hi @hnhparitosh can you try installing diffusers from main and rerunning your code?

pip install --upgrade git+https://github.com/huggingface/diffusers.git

DN6 avatar Jul 22 '24 10:07 DN6

seems that installing diffusers from git makes the code run as expected. Also, had to use pipe.enable_model_cpu_offload() rather than pipe = pipe.to('cuda'). Thanks! Closing now

hnhparitosh avatar Jul 22 '24 13:07 hnhparitosh