Intel® Developer Cloud
Help connecting to or getting started on Intel® Developer Cloud
175 Discussions

Error importing intel_extension_for_pytorch

kukevarius
Beginner
656 Views

Hello,

I have tried to install intel_extension_for_pytorch but have encountered an error while trying to import it:

/bin/sh: 1: source: not found
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last) Cell In[8], line 16 14 # Import packages and print device properties 15 import torch ---> 16 import intel_extension_for_pytorch as ipex 18 print(f"IPEX version: {ipex.__version__}") 19 for i in range(torch.xpu.device_count()): File ~/.local/lib/python3.9/site-packages/intel_extension_for_pytorch/__init__.py:93 89 raise err 91 kernel32.SetErrorMode(prev_error_mode) ---> 93 from .utils._proxy_module import * 94 from . import cpu 95 from . import xpu File ~/.local/lib/python3.9/site-packages/intel_extension_for_pytorch/utils/_proxy_module.py:43 39 # --- [ CPU proxys: 40 _register_proxy_ops('interaction_forward') ---> 43 if not hasattr(intel_extension_for_pytorch._C, 'FP32MathMode'): 44 intel_extension_for_pytorch._C.__dict__['FP32MathMode'] = proxy_math_mode 47 # --- [ XPU proxys: AttributeError: partially initialized module 'intel_extension_for_pytorch' has no attribute '_C' (most likely due to a circular import)

 

I have followed the instructions to install intel_extension_for_pytorch from https://intel.github.io/intel-extension-for-pytorch/#installation?platform=gpu&version=v2.1.30%2bxpu&os=linux%2fwsl2&package=pip
it installs without any errors.

My code:

 

#import sys
import subprocess

# Create virtual environment
#subprocess.run([sys.executable, '-m', 'venv', 'octan2'])

# Install packages into virtual environment
#!octan2/bin/python -m pip install torch==2.1.0.post2 torchvision==0.16.0.post2 torchaudio==2.1.0.post2 intel-extension-for-pytorch==2.1.30.post0 oneccl_bind_pt==2.1.300+xpu --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/

# Activate the virtual environment (only affects current shell, won't persist across cells)
activate_cmd = 'source octan2/bin/activate'  # Adjust for your OS if needed
subprocess.run(activate_cmd, shell=True)

# Import packages and print device properties
import torch
import intel_extension_for_pytorch as ipex

print(f"IPEX version: {ipex.__version__}")
for i in range(torch.xpu.device_count()):
    print(f"[{i}]: {torch.xpu.get_device_properties(i)}")

 

I am using the free idc training instance and i have selected the pytorch gpu kernel.

Thanks in advance.

Labels (3)
0 Kudos
1 Solution
Elmer_Intel
Moderator
313 Views

Hi kukevarius,


Thank you for your patience.


Could you please confirm whether you are currently using Jupyter Notebook in the SLURM "Training and Workshop "environment or whether you are using the machine specifically assigned to you?

 

If you are using "Training and Workshop," please note that the Intel Pytorch Extension cannot be installed due to its design limitations. If you are using the machine assigned to you, could you kindly provide us with the following information for our records:


System Instance ID:

System Instance type:

Regions:

Start date:

End date:



Regards,

Elmer


View solution in original post

0 Kudos
10 Replies
Elmer_Intel
Moderator
614 Views

Hi kukevarius,

Thank you for reaching out to us.


Before we proceed to investigate, please share with us which training you are having issues with.


Furthermore, please try the solution below and provide the issue you replicate along with a full screenshot.

The intel extension for pytorch require a very specific version of torch and torchvision that includes a patch. You may refer the link below.

https://intel.github.io/intel-extension-for-pytorch/xpu/latest/tutorials/installation.html


To verify the version, please share with us if use PyTorch:

"pip3 show torch"

or if use conda:

"conda list -f pytorch"


Besides, please help to source the oneAPI Base Toolkit Environments using the right directories:

# Source oneAPI Base Toolkit

$ source /opt/intel/oneapi/compiler/latest/env/vars.sh

$ source /opt/intel/oneapi/mkl/latest/env/vars.sh

$ source /opt/intel/oneapi/ccl/latest/env/vars.sh

$ source /opt/intel/oneapi/mpi/latest/env/vars.sh



Regards,

Elmer


0 Kudos
isale
Novice
570 Views

Hello, I have a similar problem... I entered the required commands, this is what the conda environment returns:

 

Screenshot 2024-06-27 191304.png

0 Kudos
kukevarius
Beginner
485 Views

Hello sorry for the late reply,

pip3 show torch
Name: torch
Version: 2.0.1a0+cxx11.abi
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /home/ubb083db7da1ae7febbf5cf6a4045f19/.local/lib/python3.9/site-packages
Requires: filelock, jinja2, networkx, sympy, typing-extensions
Required-by: accelerate, sentence-transformers, torchvision

 

 

How to reproduce:

create  a new venv with venv

activate that venv

install torch xpu in the venv 

pip install torch==2.1.0.post2 torchvision==0.16.0.post2 torchaudio==2.1.0.post2 intel-extension-for-pytorch==2.1.30.post0 oneccl_bind_pt==2.1.300+xpu --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/

run the code:

import torch
import intel_extension_for_pytorch as ipex

print(f"IPEX version: {ipex.__version__}")
for i in range(torch.xpu.device_count()):
    print(f"[{i}]: {torch.xpu.get_device_properties(i)}")


Expected result

'list of xpu devices'

Result:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[13], line 15
     12 subprocess.run(activate_cmd, shell=True)
     14 # Import packages and print device properties
---> 15 import torch
     16 import intel_extension_for_pytorch as ipex
     18 print(f"IPEX version: {ipex.__version__}")

File ~/.local/lib/python3.9/site-packages/torch/__init__.py:229
    227     if USE_GLOBAL_DEPS:
    228         _load_global_deps()
--> 229     from torch._C import *  # noqa: F403
    231 # Appease the type checker; ordinarily this binding is inserted by the
    232 # torch._C module initialization code in C
    233 if TYPE_CHECKING:

ImportError: /home/ubb083db7da1ae7febbf5cf6a4045f19/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so: undefined symbol: iJIT_NotifyEvent

 

Screenshot of the notebook below.

Again sorry for the late reply.

0 Kudos
Elmer_Intel
Moderator
545 Views

Hi isale,


Regarding the issue, please make sure to install the latest OneAPI basekit. You may install via the link below.


https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html?operatingsystem=linux



Regards,

Elmer


0 Kudos
isale
Novice
469 Views
Hi, I already have the latest version available for Windows
0 Kudos
Elmer_Intel
Moderator
416 Views

 Hi kukevarius,

 

Thank you for your response. For us to provide the solution efficiently, kindly send us the Jupyter Notebook for us to replicate the issue. We can do the comparison and solve the issue on our side, you may send it via private message to me after uploading the Jupyter Notebook to Google Drive.

community_private_message.png

 

Regards,

Elmer

 

 

0 Kudos
Elmer_Intel
Moderator
364 Views

Hi kukevarius,


We are investigating this issue with the relevant team and will get back to you soon. Your patience is greatly appreciated.

 

 

Regards,

Elmer

 


0 Kudos
Elmer_Intel
Moderator
314 Views

Hi kukevarius,


Thank you for your patience.


Could you please confirm whether you are currently using Jupyter Notebook in the SLURM "Training and Workshop "environment or whether you are using the machine specifically assigned to you?

 

If you are using "Training and Workshop," please note that the Intel Pytorch Extension cannot be installed due to its design limitations. If you are using the machine assigned to you, could you kindly provide us with the following information for our records:


System Instance ID:

System Instance type:

Regions:

Start date:

End date:



Regards,

Elmer


0 Kudos
kukevarius
Beginner
287 Views

Thank you for your response,

 

I am using the 'Training and Workshop' environment.

0 Kudos
Elmer_Intel
Moderator
282 Views

Hi kukevarius,


Thank you for responding. 


This thread will no longer be monitored since this issue has been resolved. If you need any additional information from Intel, please submit a new question.



Regards,

Elmer


0 Kudos
Reply