Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPEX AMP RuntimeError: expected scalar type Float but found Half #731

Open
ssln-027 opened this issue Nov 5, 2024 · 6 comments
Open

IPEX AMP RuntimeError: expected scalar type Float but found Half #731

ssln-027 opened this issue Nov 5, 2024 · 6 comments
Assignees
Labels
CPU CPU specific issues Crash Execution crashes XPU/GPU XPU/GPU specific issues

Comments

@ssln-027
Copy link

ssln-027 commented Nov 5, 2024

Describe the bug

when running below code, got "RuntimeError: expected scalar type Float but found Half "

import torch
import torch.nn as nn
import intel_extension_for_pytorch as ipex

def layer_test(layer):
with torch.amp.autocast('xpu'):
layer = layer.to(device, torch.float16)
input_tensor = torch.randn(1, 1, 28, 28).to(device, torch.float32)
output_tensor = layer(input_tensor)
print('success', output_tensor.dtype, output_tensor.device)

layer_test(nn.LayerNorm([1, 28, 28]))

got below error message
Traceback (most recent call last):
File "/home/intel/sn/xpu.py", line 37, in
layer_test(nn.LayerNorm([1, 28, 28]))
File "/home/intel/sn/xpu.py", line 16, in layer_test
output_tensor = layer(input_tensor)
File "/home/intel/sn/sd-ipex/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/intel/sn/sd-ipex/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
return forward_call(*args, **kwargs)
File "/home/intel/sn/sd-ipex/lib/python3.10/site-packages/torch/nn/modules/normalization.py", line 201, in forward
return F.layer_norm(
File "/home/intel/sn/sd-ipex/lib/python3.10/site-packages/torch/nn/functional.py", line 2573, in layer_norm
return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled)
RuntimeError: expected scalar type Float but found Half

Versions

Collecting environment information...

PyTorch version: 2.3.1+cxx11.abi
PyTorch CXX11 ABI: Yes
IPEX version: 2.3.110+xpu
IPEX commit: 95c9459
Build type: Release

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Clang version: N/A
IGC version: N/A
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.5.0-18-generic-x86_64-with-glibc2.35
Is XPU available: True
DPCPP runtime: N/A
MKL version: N/A

GPU models and configuration onboard:
N/A

GPU models and configuration detected:

  • [0] _XpuDeviceProperties(name='Intel(R) Arc(TM) A770 Graphics', platform_name='Intel(R) Level-Zero', type='gpu', driver_version='1.3.30049', total_memory=15473MB, max_compute_units=512, gpu_eu_count=512, gpu_subslice_count=32, max_work_group_size=1024, max_num_sub_groups=128, sub_group_sizes=[8 16 32], has_fp16=1, has_fp64=0, has_atomic64=1)
  • [1] _XpuDeviceProperties(name='Intel(R) UHD Graphics 770', platform_name='Intel(R) Level-Zero', type='gpu', driver_version='1.3.30049', total_memory=59748MB, max_compute_units=32, gpu_eu_count=32, gpu_subslice_count=2, max_work_group_size=512, max_num_sub_groups=64, sub_group_sizes=[8 16 32], has_fp16=1, has_fp64=0, has_atomic64=1)

Driver version:

  • intel_opencl: 24.26.30049.10-950~22.04
  • level_zero: 1.3.30049.10-950~22.04

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): 12
On-line CPU(s) list: 0-11
Vendor ID: GenuineIntel
Model name: 12th Gen Intel(R) Core(TM) i7-12700
CPU family: 6
Model: 151
Thread(s) per core: 1
Core(s) per socket: 12
Socket(s): 1
Stepping: 2
CPU max MHz: 4900.0000
CPU min MHz: 800.0000
BogoMIPS: 4224.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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l2 cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a 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 hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 512 KiB (12 instances)
L1i cache: 512 KiB (12 instances)
L2 cache: 12 MiB (9 instances)
L3 cache: 25 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-11
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: Not affected
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; Enhanced / Automatic IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip] dpcpp-cpp-rt==2024.2.1
[pip] impi-devel==2021.13.1
[pip] impi-rt==2021.13.1
[pip] intel-cmplr-lib-rt==2024.2.1
[pip] intel-cmplr-lib-ur==2024.2.1
[pip] intel-cmplr-lic-rt==2024.2.1
[pip] intel_extension_for_pytorch==2.3.110+xpu
[pip] intel-opencl-rt==2024.2.1
[pip] intel-openmp==2024.2.1
[pip] intel-sycl-rt==2024.2.1
[pip] mkl==2024.2.1
[pip] mkl-dpcpp==2024.2.1
[pip] numpy==2.1.3
[pip] oneccl-bind-pt==2.3.100+xpu
[pip] oneccl-devel==2021.13.1
[pip] onemkl-sycl-blas==2024.2.1
[pip] onemkl-sycl-datafitting==2024.2.1
[pip] onemkl-sycl-dft==2024.2.1
[pip] onemkl-sycl-lapack==2024.2.1
[pip] onemkl-sycl-rng==2024.2.1
[pip] onemkl-sycl-sparse==2024.2.1
[pip] onemkl-sycl-stats==2024.2.1
[pip] onemkl-sycl-vm==2024.2.1
[pip] torch==2.3.1+cxx11.abi
[pip] torchaudio==2.3.1+cxx11.abi
[pip] torchvision==0.18.1+cxx11.abi

@ZailiWang
Copy link
Contributor

Had a quick test on CPU & CUDA.
CPU raises a similar error: RuntimeError: mixed dtype (CPU): expect parameter to have scalar type of Float
CUDA test passed: success torch.float32 cuda:0

@ssln-027
Copy link
Author

ssln-027 commented Nov 7, 2024

Please also test on A770 and MTL iGPU

@CaoE
Copy link
Contributor

CaoE commented Nov 7, 2024

This error is expected on the CPU. The CPU autocast handles layernorm as fallthrough. If it is mixed data types, then the weight should be fp32 and the input should be a lower precision data type. CUDA puts layernorm into the fp32 cast policy so cuda can pass the example, and generate a fp32 result.

@xiguiw
Copy link
Contributor

xiguiw commented Nov 7, 2024

View the PyTorch document, there is no limitation for layer_norm data type: torch.nn.functional.layer_norm — PyTorch 2.5 documentation

Double check the AMX example, everyone would change cuda as xpu and expect it works.

https://pytorch.org/docs/stable/notes/amp_examples.html#typical-mixed-precision-training

@xiguiw
Copy link
Contributor

xiguiw commented Nov 7, 2024

@CaoE
Would you plan to fix this issue?

@xiguiw xiguiw self-assigned this Nov 7, 2024
@jingxu10 jingxu10 added CPU CPU specific issues XPU/GPU XPU/GPU specific issues Crash Execution crashes labels Nov 12, 2024
@xiguiw
Copy link
Contributor

xiguiw commented Nov 12, 2024

@ssln-027
To be fixed in intel_extension_for_pytorch xpu 2.5

For CPU, this is PyTorch issue not IPEX specific.
If you want it to be fixed, Please file a ticket in PyTorch github repo.

Thanks!

Xigui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CPU CPU specific issues Crash Execution crashes XPU/GPU XPU/GPU specific issues
Projects
None yet
Development

No branches or pull requests

5 participants