intel / intel-extension-for-pytorch

A Python package for extending the official PyTorch that can easily obtain performance on Intel platform
Apache License 2.0
1.61k stars 247 forks source link

iGPU in pentium G4620 generates bad image by diffusers when setting data type to bfloat16 #711

Closed LeptonWu closed 1 month ago

LeptonWu commented 1 month ago

Describe the bug

The following code will generate bad image, basically it looks like noise. change bfloat16 to float16 fix it. I understand bfloat16 is not supported by iGPU in G4620, but I don't get why it can run instead of throwing an exception.

See the attached image for the output. Good result is running with float16 and bad result is running with bfloat16

good bad

import torch
import intel_extension_for_pytorch
from diffusers import StableDiffusionPipeline

device = "xpu"
dtype=torch.bfloat16

pipe = StableDiffusionPipeline.from_single_file("models/Stable-diffusion/realisticVisionV60B1_v51HyperVAE.safetensors", torch_dtype=dtype).to(device)
torch.manual_seed(0)
image = pipe("black cat", guidance_scale=1.5, width=512, height=512, num_inference_steps=6)
image.images[0].save("out.jpg")

Versions

Collecting environment information... PyTorch version: 2.3.1+cxx11.abi PyTorch CXX11 ABI: Yes IPEX version: 2.3.110+xpu IPEX commit: 95c945927 Build type: Release

OS: Debian GNU/Linux 12 (bookworm) (x86_64) GCC version: (Debian 12.2.0-14) 12.2.0 Clang version: N/A IGC version: N/A CMake version: version 3.25.1 Libc version: glibc-2.36

Python version: 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] (64-bit runtime) Python platform: Linux-6.1.0-25-amd64-x86_64-with-glibc2.36 Is XPU available: True DPCPP runtime version: N/A MKL version: N/A GPU models and configuration: [0] _XpuDeviceProperties(name='Intel(R) HD Graphics 630', platform_name='Intel(R) Level-Zero', type='gpu', driver_version='1.3.29735', total_memory=6733MB, max_compute_units=24, gpu_eu_count=24, gpu_subslice_count=3, max_work_group_size=256, max_num_sub_groups=32, sub_group_sizes=[8 16 32], has_fp16=1, has_fp64=1, has_atomic64=1) Intel OpenCL ICD version: 24.22.29735.27-914~22.04 Level Zero version: 1.3.29735.27-914~22.04

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Vendor ID: GenuineIntel Model name: Intel(R) Pentium(R) CPU G4600 @ 3.60GHz CPU family: 6 Model: 158 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 Stepping: 9 CPU(s) scaling MHz: 22% CPU max MHz: 3600.0000 CPU min MHz: 800.0000 BogoMIPS: 7200.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust smep erms invpcid mpx rdseed smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp Virtualization: VT-x L1d cache: 64 KiB (2 instances) L1i cache: 64 KiB (2 instances) L2 cache: 512 KiB (2 instances) L3 cache: 3 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-3 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable Vulnerability Mds: Vulnerable: Clear CPU buffers attempted, no microcode; SMT vulnerable Vulnerability Meltdown: Mitigation; PTI Vulnerability Mmio stale data: Vulnerable: Clear CPU buffers attempted, no microcode; SMT vulnerable Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Mitigation; IBRS Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Vulnerable Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Vulnerable: No microcode Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] dctorch==0.1.2 [pip3] intel_extension_for_pytorch==2.3.110+xpu [pip3] numpy==1.26.4 [pip3] open_clip_torch==2.26.1 [pip3] pytorch-lightning==1.9.4 [pip3] torch==2.3.1+cxx11.abi [pip3] torchdiffeq==0.2.4 [pip3] torchmetrics==1.4.2 [pip3] torchsde==0.2.6 [pip3] torchvision==0.18.1+cxx11.abi [conda] N/A

Bhargav230m commented 1 month ago

Bro how install intel_extension_for_pytorch on that igpu, mine doesn't even send any tensor to my "iris xe graphics" igpu. Im using wsl2

LeptonWu commented 1 month ago

I am on debian 12, that could be a difference.

alexsin368 commented 1 month ago

@LeptonWu this issue could be related to https://github.com/intel/intel-extension-for-pytorch/issues/529 and my team members are looking into it. However, IPEX does not support iGPU. Specifically for IPEX v2.3.110+xpu:

image

Unfortunately, this issue is outside of our scope. For iGPU, I recommend using OpenVINO.

LeptonWu commented 1 month ago

Thanks, I understand that iGPU is not officially supported by IPEX. I am just wondering, could this reveal some bugs in the IPEX stack (and the same bug could also impact other supported devices) . A little difference with #529 is: it seems this only impacts on BF16.

Any way feel free to close this issue as infeasible.

alexsin368 commented 1 month ago

It's difficult to say if a bug exists on iGPU, it also exists on the supported GPUs. But if you do encounter new bugs with the supported GPUs, feel free to file a new issue.