diffusers: Black image on SDXL 1.0 + RuntimeWarning: invalid value encountered in cast images = (images * 255).round().astype("uint8")
Describe the bug
I’m trying to run SDXL in a container environment (Debian). I tried both diffusers[torch]==0.18.0 and diffusers[torch]==0.19.0 with Python 3.10 on A10g and A100 but I get a black image back and RuntimeWarning: invalid value encountered in cast images = (images * 255).round().astype(“uint8”) when running 0.18.0.
Basically, when building the container’s image I’m doing:
pipe = diffusers.DiffusionPipeline.from_pretrained(
model_id,
use_auth_token=hugging_face_token,
torch_dtype=torch.float16,
use_safetensors=True,
variant="fp16",
cache_dir=cache_path
)
pipe.save_pretrained(cache_path, safe_serialization=True)
After that, when running the function I’m calling:
self.pipe = diffusers.DiffusionPipeline.from_pretrained(
cache_path).to("cuda")
With 0.19.0 I’m getting Out of memory errors. .enable_model_cpu_offload() didn’t work for me. Anyway, with both versions in the end I get a black image.
Reproduction
pipe = diffusers.DiffusionPipeline.from_pretrained(
model_id,
use_auth_token=hugging_face_token,
torch_dtype=torch.float16,
use_safetensors=True,
variant="fp16",
cache_dir=cache_path
)
pipe.save_pretrained(cache_path, safe_serialization=True)
pipe = diffusers.DiffusionPipeline.from_pretrained(
cache_path).to("cuda")
Logs
The config attributes {'force_upcast': True} were passed to AutoencoderKL, but are not expected and will be ignored. Please verify your config.json configuration file.
98%|█████████▊| 49/50 [00:10<00:00, 5.28it/s]100%|██████████| 50/50 [00:10<00:00, 5.27it/s]100%|██████████| 50/50 [00:10<00:00, 4.90it/s]
/usr/local/lib/python3.10/site-packages/diffusers/image_processor.py:65: RuntimeWarning: invalid value encountered in cast
images = (images * 255).round().astype("uint8")
System Info
0.18.0 and 0.19.0. Linux Debian (don’t have access to the container now).
Who can help?
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 17 (10 by maintainers)
Your setup is correct. The mixed precision you’re using is probably fp16 and the vae is broken with fp16. You can either set the vae to run in fp32, or use a fixed vae like https://huggingface.co/madebyollin/sdxl-vae-fp16-fix
Ah ok the last code snippet seems correct. Note that you can speed it up by using less inference steps and potentially a better scheduler such as: https://huggingface.co/docs/diffusers/api/schedulers/unipc
The solution was to switch out the VAE to (https://huggingface.co/madebyollin/sdxl-vae-fp16-fix) based on this note: https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/README_sdxl.md#specifying-a-better-vae