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.57k stars 239 forks source link

Torchvision functions are broken #297

Open BA8F0D39 opened 1 year ago

BA8F0D39 commented 1 year ago

Using the docker image https://github.com/intel/intel-extension-for-pytorch/tree/v1.13.10%2Bxpu/docker

Reading an image gives an error

import torch
from torchvision.io import read_image
import intel_extension_for_pytorch as ipex

print("reading")
image = read_image("a.png")
print("done")
root@3ddc5256fb95:/workspace# python3 ./a.py 
/usr/local/lib/python3.10/dist-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: 
  warn(f"Failed to load image Python extension: {e}")
reading
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/torch/_ops.py", line 501, in __getattr__
    op, overload_names = torch._C._jit_get_operation(qualified_op_name)
RuntimeError: No such operator image::read_file

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/workspace/./a.py", line 12, in <module>
    image = read_image("a.png")
  File "/usr/local/lib/python3.10/dist-packages/torchvision/io/image.py", line 253, in read_image
    data = read_file(path)
  File "/usr/local/lib/python3.10/dist-packages/torchvision/io/image.py", line 47, in read_file
    data = torch.ops.image.read_file(path)
  File "/usr/local/lib/python3.10/dist-packages/torch/_ops.py", line 505, in __getattr__
    raise AttributeError(
AttributeError: '_OpNamespace' 'image' object has no attribute 'read_file'
Sikerdebaard commented 1 year ago

Adding to this: this seems to happen because various libs are missing in all of the stable release torchvision Intel® Extension for PyTorch* v1.13.10+xpu wheels.

This is not limited to the image.so lib, the whole torchvision.libs directory is missing. Transplanting these libs from regular cpu torchvision wheels does not yield a working version of torchvision.

In its current state torchvision wheels seem to be broken and cannot be used.

Here is a workaround that works for me under ubuntu 22.04. Hopefully Intel releases a working version soon.

# setup conda build env
conda create --prefix=./ipex_build python==3.10 -y
conda activate ./ipex_build

# checkout torchvision and switch to appropriate version
git clone https://github.com/pytorch/vision.git
cd vision
git checkout v0.14.0

# set some build vars
export GLIBCXX_USE_CXX11_ABI=1
export USE_CUDA=0

# install some dependancies
conda install -y -c conda-forge libpng jpeg ffmpeg
pip install pillow-simd
pip install https://intel-optimized-pytorch.s3.cn-north-1.amazonaws.com.cn/ipex_stable/xpu/torch-1.13.0a0%2Bgitb1dde16-cp310-cp310-linux_x86_64.whl

# generate fresh wheels
python setup.py bdist_wheel

Now go to vision/dist and you have made yourself some fresh (hopefully) working wheels that can be installed through pip.

jingxu10 commented 1 year ago

@WeizhuoZhang-intel

BA8F0D39 commented 1 year ago

@Sikerdebaard Thanks. Did they just delete the libraries so that they don't give any errors?

Yorizuka commented 11 months ago

I installed pytorch using the instruction given in the readme python -m pip install torch==2.0.1a0 torchvision==0.15.2a0 intel_extension_for_pytorch==2.0.110+xpu --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/

This warning is produced when torch is loaded.

import torch
import intel_extension_for_pytorch as ipex
print(ipex.xpu.get_device_name(0))

UserWarning: Failed to load image Python extension: ''If you don't plan on using image functionality from torchvision.io, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have libjpeg or libpng installed before building torchvision from source?

What steps should I take correct this?