AMD Vega11核显运行Stable Diffusion遇torch.dml属性错误,求解决方法
解决Stable Diffusion运行时
AttributeError: module 'torch' has no attribute 'dml'问题 卸载并重新安装适配的torch-directml套件
- 打开Stable Diffusion WebUI所在目录的终端,执行卸载命令:
pip uninstall torch torchvision torchaudio -y - 根据你的Python版本安装对应版本的torch-directml(以Python 3.10为例):
pip install torch-directml==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 - 验证安装:在终端输入以下命令,能输出设备信息则说明安装成功:
python -c "import torch_directml; dml_device = torch_directml.device(); print(dml_device)"
- 打开Stable Diffusion WebUI所在目录的终端,执行卸载命令:
调整WebUI启动参数
修改webui-user.bat中的命令行参数,移除--backend directml,修改后的参数为:--autolaunch --precision full --no-half --skip-torch-cuda-test --opt-sub-quad-attention --lowvram --lowram --disable-nan-check部分WebUI版本无需手动指定directml后端,会自动识别已安装的torch-directml。
确认虚拟环境一致性
如果WebUI使用自带的虚拟环境,需先激活环境再安装torch-directml:- 进入WebUI目录,执行激活命令:
venv\Scripts\activate - 再执行前面的卸载和安装命令。
- 进入WebUI目录,执行激活命令:
适配WebUI设备初始化代码(可选)
若上述步骤无效,可修改modules/devices.py中的设备初始化逻辑:找到原有的cuda设备初始化代码,替换为directml相关逻辑:
import torch_directml device = torch_directml.device()
内容的提问来源于stack exchange,提问作者matt1452
相关产品推荐
相关产品推荐

