Description
Describe the bug
When I tested Stable Diffusion on dGPU (ARC series) based on ipex, I found a strange problem:
-
When I move both vae/unet/text_encoders in the pipeline to
xpu
, the pipeline forward can run normally. -
However, if I pull out the vae related functions, the vae decoding part cannot run through, and I always encounter device error or dtype error.
sample code
from diffusers import StableDiffusionPipeline
import time
import intel_extension_for_pytorch as ipex
import torch
from bigdl.nano.pytorch import InferenceOptimizer
from diffusers import LMSDiscreteScheduler
path = "runwayml/stable-diffusion-v1-5 "
pipeline = StableDiffusionPipeline.from_pretrained(path)
pipeline.unet = pipeline.unet.to('xpu')
pipeline.vae = pipeline.vae.to('xpu')
pipeline.text_encoder = pipeline.text_encoder.to('xpu')
def decode_latents(vae, latents):
# Explicit call to get the vae loaded, since `decode` isn't the forward method.
# self._model_group.load(self.vae)
# return super().decode_latents(latents.to('xpu'))
latents = 1 / vae.config.scaling_factor * latents
image = vae.decode(latents).sample
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
image = image.cpu().permute(0, 2, 3, 1).float().numpy()
return image
latents = torch.randn(1, 4, 64, 64).to('xpu')
with torch.xpu.amp.autocast(enabled=True, dtype=torch.float16):
for i in range(1):
st = time.perf_counter()
pipeline("a dog").images[0]
print(f"cost {time.perf_counter() - st}s.")
decode_latents(pipeline.vae, latents)
I will always meet error when executing the last line of code on F.conv2d like:
│ │
│ 456 │ │ │ return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=sel │
│ 457 │ │ │ │ │ │ │ weight, bias, self.stride, │
│ 458 │ │ │ │ │ │ │ _pair(0), self.dilation, self.groups) │
│ ❱ 459 │ │ return F.conv2d(input, weight, bias, self.stride, │
│ 460 │ │ │ │ │ │ self.padding, self.dilation, self.groups) │
│ 461 │ │
│ 462 │ def forward(self, input: Tensor) -> Tensor:
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, xpu:0 and cpu! (when checking argument for argument weight in method
wrapper__convolution_overrideable)
or
File "/home/sshuang/miniconda3/envs/rn_ipex_gpu/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 461, in _conv_forward
return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Input type (c10::Half) and bias type (float) should be the same
I wonder if there is a problem with the current version's support for Conv2d, or if there is a problem with my calling method? Why are the execution results different inside and outside the pipeline?
Thanks a lot.
Versions
Collecting environment information...
PyTorch version: 1.13.0a0+gitf2a6fc6
PyTorch CXX11 ABI: Yes
IPEX version: 1.13.10+xpu
IPEX commit: 81d3d2b
Build type: Release
OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: N/A
IGC version: 2023.0.0 (2023.0.0.20221201)
CMake version: version 3.26.0
Libc version: glibc-2.35
Python version: 3.9.16 (main, Mar 8 2023, 14:00:05) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.47+prerelease6469.7-x86_64-with-glibc2.35
Is XPU available: True
DPCPP runtime version: 2023.0.0
MKL version: 2023.0.0
GPU models and configuration:
[0] _DeviceProperties(name='Intel(R) Graphics [0x56a0]', platform_name='Intel(R) Level-Zero', dev_type='gpu, support_fp64=0, total_memory=15473MB, max_compute_units=512)
Intel OpenCL ICD version: 22.49.25018.24+i55620.0420.04
Level Zero version: 1.3.25018.24+i556
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 24
On-line CPU(s) list: 0-23
Vendor ID: GenuineIntel
Model name: 12th Gen Intel(R) Core(TM) i9-12900K
CPU family: 6
Model: 151
Thread(s) per core: 2
Core(s) per socket: 16
Socket(s): 1
Stepping: 2
CPU max MHz: 5200.0000
CPU min MHz: 800.0000
BogoMIPS: 6374.40
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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 640 KiB (16 instances)
L1i cache: 768 KiB (16 instances)
L2 cache: 14 MiB (10 instances)
L3 cache: 30 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-23
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Vulnerable: eIBRS with unprivileged eBPF
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Versions of relevant libraries:
[pip3] clip-anytorch==2.5.2
[pip3] intel-extension-for-pytorch==1.13.10+xpu
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.23.1
[pip3] pytorch-lightning==1.6.4
[pip3] torch==1.13.0a0+gitedda572
[pip3] torch-fidelity==0.3.0
[pip3] torchdiffeq==0.2.3
[pip3] torchmetrics==0.11.0
[pip3] torchsde==0.2.5
[pip3] torchvision==0.14.1
[conda] clip-anytorch 2.5.2 pypi_0 pypi
[conda] intel-extension-for-pytorch 1.13.10+xpu pypi_0 pypi
[conda] numpy 1.23.1 pypi_0 pypi
[conda] pytorch-lightning 1.6.4 pypi_0 pypi
[conda] torch 1.13.0a0+gitedda572 pypi_0 pypi
[conda] torch-fidelity 0.3.0 pypi_0 pypi
[conda] torchdiffeq 0.2.3 pypi_0 pypi
[conda] torchmetrics 0.11.0 pypi_0 pypi
[conda] torchsde 0.2.5 pypi_0 pypi
[conda] torchvision 0.14.1 pypi_0 pyp