安装支持Intel GPU的pytorch扩展

https://pytorch-extension.intel.com/installation?platform=gpu&version=v2.5.10%2Bxpu&os=windows&package=pip

运行

conda install libuv
python -m pip install torch==2.5.1+cxx11.abi torchvision==0.20.1+cxx11.abi torchaudio==2.5.1+cxx11.abi intel-extension-for-pytorch==2.5.10+xpu --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/cn/

注:可以用 -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple 加速

需要设置两个环境变量:

1736903966955

可能需要安装C++运行时

https://answers.microsoft.com/zh-hans/windows/forum/all/win11-23h2-%E7%BC%BA%E5%B0%91%E4%BA%86api-ms-win/1d8fe152-6f44-4af1-a106-7f4b9ab57aee

下载

https://aka.ms/vs/17/release/vc_redist.x86.exe https://aka.ms/vs/17/release/vc_redist.x64.exe

安装结束,import torch看看会不会出错


然后把pytorch代码中所有cuda改成xpu

>>> torch.xpu.device_count()
1
>>> torch.xpu.is_available()
True
>>> device = torch.device("xpu:0" if torch.xpu.is_available() else "cpu")
>>> device
device(type='xpu', index=0)
>>>

也可以直接用

https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/examples.html#training

评论

暂无评论