Closed
Description
Describe the bug
This bug happens with any Diffusion model. Meaning it's not specific to Stable Diffusion models.
- Only happens at 1024x1024 or 1024x1024 sized (2048x512 etc) resolutions.
Any other resolution (1080x1080 etc) will work fine. - Only happens with Alchemist GPUs (A770, A750).
Does not happen with Intel Data Center GPU Max series or non Intel GPUs. - Happens with both Diffusers backend and A1111 backend. So it is not specific to Diffusers.
Happens with OpenVINO too. - Happens with older IPEX versions too.
Happens with SDPA almost all the time at 1024x1024.
- BF16 has the corruption.
- FP16 NaNs out.
- FP32 works fine.
Torch BMM can corrupt based on your luck too.
- BF16 and FP16 gets corrupted based on your luck.
- FP32 works fine.
Example of the bug:
- 2 corruption lines, one on the top and one on the bottom, and at the same place every time.
- Image will get over saturated or will get too bright.
Sample code to reproduce:
import os
import gc
import torch
import intel_extension_for_pytorch
from diffusers import AutoPipelineForText2Image, AutoencoderKL, EulerAncestralDiscreteScheduler
from diffusers.models.attention_processor import AttnProcessor
model="cagliostrolab/animagine-xl-3.0"
vae="madebyollin/sdxl-vae-fp16-fix"
prompt="masterpiece, best quality, newest, 1girl, solo, depth of field, rim lighting, flowers, petals, crystals, butterfly, scenery, upper body, dark red hair, straight hair, long hair, blue eyes, cat ears, mature female, white sweater, blush, slight smile,"
negative_prompt = "nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name"
seed=123456789
num_inference_steps=20
# BF16
pipeline = AutoPipelineForText2Image.from_pretrained(model, vae=AutoencoderKL.from_pretrained(vae))
pipeline.safety_checker = None
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
pipeline = pipeline.to("xpu", dtype=torch.bfloat16)
torch.xpu.empty_cache()
gc.collect()
image = pipeline(prompt, negative_prompt=negative_prompt, width=1024, height=1024, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-bf16.jpg")
image = pipeline(prompt, negative_prompt=negative_prompt, width=1080, height=1080, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-bf16-1080x1080.jpg")
# FP16
pipeline = pipeline.to("meta")
pipeline = None
del pipeline
torch.xpu.empty_cache()
gc.collect()
pipeline = AutoPipelineForText2Image.from_pretrained(model, vae=AutoencoderKL.from_pretrained(vae))
pipeline.safety_checker = None
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
pipeline = pipeline.to("xpu", dtype=torch.float16)
torch.xpu.empty_cache()
gc.collect()
image = pipeline(prompt, negative_prompt=negative_prompt, width=1024, height=1024, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-fp16.jpg")
image = pipeline(prompt, negative_prompt=negative_prompt, width=1080, height=1080, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-fp16-1080x1080.jpg")
# Torch BMM
# BF16
pipeline = pipeline.to("meta")
pipeline = None
del pipeline
torch.xpu.empty_cache()
gc.collect()
pipeline = AutoPipelineForText2Image.from_pretrained(model, vae=AutoencoderKL.from_pretrained(vae))
pipeline.safety_checker = None
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
pipeline.unet.set_attn_processor(AttnProcessor())
pipeline = pipeline.to("xpu", dtype=torch.bfloat16)
torch.xpu.empty_cache()
gc.collect()
image = pipeline(prompt, negative_prompt=negative_prompt, width=1024, height=1024, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-bf16-bmm.jpg")
image = pipeline(prompt, negative_prompt=negative_prompt, width=1080, height=1080, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-bf16-bmm-1080x1080.jpg")
# FP16
pipeline = pipeline.to("meta")
pipeline = None
del pipeline
torch.xpu.empty_cache()
gc.collect()
pipeline = AutoPipelineForText2Image.from_pretrained(model, vae=AutoencoderKL.from_pretrained(vae))
pipeline.safety_checker = None
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
pipeline.unet.set_attn_processor(AttnProcessor())
pipeline = pipeline.to("xpu", dtype=torch.float16)
torch.xpu.empty_cache()
gc.collect()
image = pipeline(prompt, negative_prompt=negative_prompt, width=1024, height=1024, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-fp16-bmm.jpg")
image = pipeline(prompt, negative_prompt=negative_prompt, width=1080, height=1080, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-fp16-bmm-1080x1080.jpg")
# Torch BMM + Slicing
# BF16
pipeline = pipeline.to("meta")
pipeline = None
del pipeline
torch.xpu.empty_cache()
gc.collect()
pipeline = AutoPipelineForText2Image.from_pretrained(model, vae=AutoencoderKL.from_pretrained(vae))
pipeline.safety_checker = None
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
pipeline.enable_attention_slicing()
pipeline = pipeline.to("xpu", dtype=torch.bfloat16)
torch.xpu.empty_cache()
gc.collect()
image = pipeline(prompt, negative_prompt=negative_prompt, width=1024, height=1024, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-bf16-bmm-sliced.jpg")
image = pipeline(prompt, negative_prompt=negative_prompt, width=1080, height=1080, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-bf16-bmm-sliced-1080x1080.jpg")
# FP16
pipeline = pipeline.to("meta")
pipeline = None
del pipeline
torch.xpu.empty_cache()
gc.collect()
pipeline = AutoPipelineForText2Image.from_pretrained(model, vae=AutoencoderKL.from_pretrained(vae))
pipeline.safety_checker = None
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
pipeline.enable_attention_slicing()
pipeline = pipeline.to("xpu", dtype=torch.float16)
torch.xpu.empty_cache()
gc.collect()
image = pipeline(prompt, negative_prompt=negative_prompt, width=1024, height=1024, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-fp16-bmm-sliced.jpg")
image = pipeline(prompt, negative_prompt=negative_prompt, width=1080, height=1080, seed=seed, num_inference_steps=num_inference_steps).images[0]
image.save("image-fp16-bmm-sliced-1080x1080.jpg")
Versions
Collecting environment information...
PyTorch version: 2.1.0a0+cxx11.abi
PyTorch CXX11 ABI: Yes
IPEX version: 2.1.10+xpu
IPEX commit: a12f9f650
Build type: Release
OS: Arch Linux (x86_64)
GCC version: (GCC) 13.2.1 20230801
Clang version: 16.0.6
IGC version: 2024.0.0 (2024.0.0.20231017)
CMake version: version 3.28.1
Libc version: glibc-2.38
Python version: 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (64-bit runtime)
Python platform: Linux-6.7.0-arch3-1-x86_64-with-glibc2.38
Is XPU available: True
DPCPP runtime version: 2024.0
MKL version: 2024.0
GPU models and configuration:
[0] _DeviceProperties(name='Intel(R) Arc(TM) A770 Graphics', platform_name='Intel(R) Level-Zero', dev_type='gpu, support_fp64=0, total_memory=15473MB, max_compute_units=512, gpu_eu_count=512)
Intel OpenCL ICD version: N/A
Level Zero version: N/A
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 48 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: AuthenticAMD
Model name: AMD Ryzen 7 5800X3D 8-Core Processor
CPU family: 25
Model: 33
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 2
Frequency boost: enabled
CPU(s) scaling MHz: 80%
CPU max MHz: 4548.8281
CPU min MHz: 2200.0000
BogoMIPS: 6802.32
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor smca fsrm debug_swap
Virtualization: AMD-V
L1d cache: 256 KiB (8 instances)
L1i cache: 256 KiB (8 instances)
L2 cache: 4 MiB (8 instances)
L3 cache: 96 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Vulnerable: Safe RET, no microcode
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Versions of relevant libraries:
[pip3] dctorch==0.1.2
[pip3] intel-extension-for-pytorch==2.1.10+xpu
[pip3] numpy==1.26.2
[pip3] open-clip-torch==2.24.0
[pip3] pytorch-lightning==1.9.4
[pip3] torch==2.1.0a0+cxx11.abi
[pip3] torchdiffeq==0.2.3
[pip3] torchmetrics==1.3.0.post0
[pip3] torchsde==0.2.6
[pip3] torchvision==0.16.0a0+cxx11.abi
[conda] N/A