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.63k stars 250 forks source link

IPEX AVX2 Import Error despite AVX2 Support #347

Open fredlarochelle opened 1 year ago

fredlarochelle commented 1 year ago

Describe the bug

I recently installed 1.13.120+xpu in a new, clean conda environment with Python 3.10, following the wheel files installation instructions provided here. While the installation process proceeded without issues, I encountered an error when attempting to import IPEX for the first time. The error message indicated that IPEX requires AVX2 instruction sets or newer, which it did not detect on my system:

SystemExit: ERROR! Intel® Extension for PyTorch* only works on machines with instruction sets equal or newer than AVX2, which are not detected on the current machine.

However, this system has an Intel Xeon E5-2695 v3 which does indeed supports AVX2 - a fact confirmed by executing the lscpu command. The system is running Fedora 37 on the 6.2 kernel (with an A770).

It is worth noting that in another conda env on the same machine, I have a functioning self-build from the xpu-master branch (not the latest commit tho). Therefore, while this issue isn't critical for me, I thought it would be valuable to bring to light.

Here is the full traceback using %tb in a notebook:

---------------------------------------------------------------------------
SystemExit                                Traceback (most recent call last)
Cell In[1], line 2
      1 import torch
----> 2 import intel_extension_for_pytorch as ipex

File [~/miniconda3/envs/ipex_env/lib/python3.10/site-packages/intel_extension_for_pytorch/__init__.py:26](https://vscode-remote+ssh-002dremote-002bdev1.vscode-resource.vscode-cdn.net/home/fred/Projects/llama_arc/~/miniconda3/envs/ipex_env/lib/python3.10/site-packages/intel_extension_for_pytorch/__init__.py:26)
     23 from ._version import (__version__, __ipex_gitrev__, __torch_gitrev__, 
     24             __gpu_onednn_gitrev__, __cpu_ideep_gitrev__, __build_type__)
     25 from .cpu.utils import _cpu_isa, _custom_fx_tracer
---> 26 _cpu_isa.check_minimal_isa_support()
     29 def version():
     30     print("intel_extension_for_pytorch version:          {}".format(__version__))

File [~/miniconda3/envs/ipex_env/lib/python3.10/site-packages/intel_extension_for_pytorch/cpu/utils/_cpu_isa.py:11](https://vscode-remote+ssh-002dremote-002bdev1.vscode-resource.vscode-cdn.net/home/fred/Projects/llama_arc/~/miniconda3/envs/ipex_env/lib/python3.10/site-packages/intel_extension_for_pytorch/cpu/utils/_cpu_isa.py:11), in check_minimal_isa_support()
      9 err_msg = "ERROR! Intel® Extension for PyTorch* only works on machines with instruction sets equal or newer than AVX2, which are not detected on the current machine."
     10 if not check_avx2_support():
---> 11     sys.exit(err_msg)

SystemExit: ERROR! Intel® Extension for PyTorch* only works on machines with instruction sets equal or newer than AVX2, which are not detected on the current machine.
An exception has occurred, use %tb to see the full traceback.

SystemExit: ERROR! Intel® Extension for PyTorch* only works on machines with instruction sets equal or newer than AVX2, which are not detected on the current machine.
[/home/fred/miniconda3/envs/ipex_env/lib/python3.10/site-packages/IPython/core/interactiveshell.py:3516](https://vscode-remote+ssh-002dremote-002bdev1.vscode-resource.vscode-cdn.net/home/fred/miniconda3/envs/ipex_env/lib/python3.10/site-packages/IPython/core/interactiveshell.py:3516): UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

Versions

Here is the not soo useful output from python collect_env.py:

/home/fred/miniconda3/envs/ipex_env/lib/python3.10/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: 
  warn(f"Failed to load image Python extension: {e}")
ERROR! Intel® Extension for PyTorch* only works on machines with instruction sets equal or newer than AVX2, which are not detected on the current machine.
fredlarochelle commented 1 year ago

326 also exists, but was closed and is related to IPEX 2.0 for CPU.

jingxu10 commented 1 year ago

This issue is fixed in 2.0.100+cpu, which will be released in a couple of days. Checking with internal teams to see how to get this issue fixed in GPU packages.

fredlarochelle commented 1 year ago

In the meantime, if anyone encounters the same problem, I got it working by commenting out the line 26 in __init__.py, quick dirty fix...

xuhancn commented 1 year ago

@fredlarochelle Thanks for your submit this issue.

Currently, We have fixed the issue in xpu_master branch: https://github.com/intel/intel-extension-for-pytorch/blob/xpu-master/csrc/cpu/isa/cpu_feature.cpp#L188 But, the binary release need been fixed in next time release.

Please bypass the isa check as an WA for temprary use:

diff --git a/intel_extension_for_pytorch/cpu/utils/_cpu_isa.py b/intel_extension_for_pytorch/cpu/utils/_cpu_isa.py
index 7d9c0569..9ca96fbf 100644
--- a/intel_extension_for_pytorch/cpu/utils/_cpu_isa.py
+++ b/intel_extension_for_pytorch/cpu/utils/_cpu_isa.py
@@ -2,6 +2,7 @@ import intel_extension_for_pytorch._isa_help as isa
 import sys

 def check_avx2_support():
+    return True
     return isa._check_isa_avx2()

 def check_minimal_isa_support():

Please referance to update _cpu_isa.py in your IPEX-XPU installed path.

Let's keep this issue open for trace until IPEX XPU binary release fixed.

fredlarochelle commented 1 year ago

@xuhancn After recompiling, I can confirm the issue has been fixed in the xpu_master branch.

fredlarochelle commented 1 year ago

Small update, just tried installing from the conda package on another system and the AVX2 import error is present despite AVX2 support from that processor.