运行
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 加速
需要设置两个环境变量:
可能需要安装C++运行时
下载
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