
RuntimeError: Device type privateuseone is not supported for torch.Generator() api.
快速结论:该报错通常发生在使用 AMD GPU 并安装了 torch-directml 的 Fooocus 用户中,核心原因是 torch.Generator() API 不兼容 DirectML 后端。优先排查是否使用了正确的 PyTorch 版本和 DirectML 依赖。
问题场景
用户运行 Fooocus(一款基于 Stable Diffusion 的 WebUI 工具)时,在 Windows 系统上使用 AMD GPU 并按照官方指南配置了 torch-directml。执行图像生成操作后,终端输出报错,无法生成任何图像。
报错原文
RuntimeError: Device type privateuseone is not supported for torch.Generator() api.
完整日志中还包含以下关键信息:
File "C:\Fooocus_win64_2-1-25\python_embeded\Lib\site-packages\torch\autograd\__init__.py", line 251, in generator
return torch.Generator(device)
RuntimeError: Device type privateuseone is not supported for torch.Generator() api.
原因分析
可能原因:
- torch-directml 不兼容:
torch.Generator()在 PyTorch 中仅支持标准设备(如 CPU 或 CUDA),而 DirectML 将设备注册为privateuseone,该设备类型未被torch.Generator()API 支持,导致运行时错误。 - PyTorch 版本冲突: 用户日志显示安装了 torch-directml 0.2.0.dev230426,但其依赖的 PyTorch 2.0.0 与 Fooocus 的预期版本可能存在差异。
- AMD GPU 驱动或适配问题: 部分 AMD GPU(如 8GB 显存型号)可能不完全支持 torch-directml 的所有操作。
环境排查
- 确认 Windows 系统版本(用户日志显示 Windows 10+)。
- 检查 AMD GPU 型号和驱动版本(用户提及 AMD 8GB 显存)。
- 验证 PyTorch 版本:
.\python_embeded\python.exe -c "import torch; print(torch.__version__)" - 验证 torch-directml 版本:
.\python_embeded\python.exe -m pip show torch-directml - 确认 Fooocus 版本(用户日志显示 Fooocus_win64_2-1-25)。
- 检查
run.bat修改是否符合官方 AMD Windows 配置指南。
解决步骤
- (可优先尝试) 卸载现有 torch-directml,并安装官方推荐的特定版本:
.\python_embeded\python.exe -m pip uninstall torch torchvision torchaudio torchtext functorch xformers -y
.\python_embeded\python.exe -m pip install torch-directml
确保安装过程中网络稳定,避免超时。 - 检查 Fooocus 官方文档是否有 AMD GPU 的更新适配方案(截至 Issue 关闭时,官方可能已修复)。
- 如果问题持续,尝试使用 CPU 模式作为临时方案:修改
run.bat,强制设置环境变量PYTORCH_ENABLE_MPS_FALLBACK=1或直接指定--cpu参数。 - 考虑回退到已知兼容的 Fooocus 版本,或等待社区更新。
注意: Issue 中未给出官方解决方案,以上步骤基于社区讨论推断,尤其是步骤 1 需确保安装完整。
验证方法
重新运行 Fooocus 并尝试生成一张图像。如果终端不再输出 RuntimeError: Device type privateuseone is not supported for torch.Generator() api. 错误,并且图像成功生成,则问题已解决。若仍有错误,请检查上述环境项。



