快速结论:这个报错通常出现在 SwarmUI 生成图片时,自定义节点 SwarmComfyCommon 的 SwarmKSampler 调用了 ComfyUI 旧接口 comfy.model_management.directml_enabled,而上游 ComfyUI 已删除该属性。优先排查 ComfyUI 与 SwarmUI 内置扩展版本是否不匹配,以及 SwarmKSampler.py 是否还在使用旧写法。
适用环境:Issue 中用户以 Docker 容器运行 SwarmUI,容器启动时会同时更新 SwarmUI 和 ComfyUI 到最新版本;讨论中已确认问题与 ComfyUI 提交 c5751c81abe131202eea9e4c66d000589013dd0b 删除 directml 引用相关。Issue 未提供操作系统、Python、CUDA 和显卡型号等具体信息。
最快修复方案:更新 SwarmUI 到包含修复的版本;Issue 中 SwarmUI 维护者已移除 directml 引用并说明“update swarm and you should be good”。如果暂时无法更新,可优先尝试把 SwarmUI\src\BuiltinExtensions\ComfyUIBackend\ExtraNodes\SwarmComfyCommon\SwarmKSampler.py 第 29 行改为 if getattr(comfy.model_management, "directml_enabled", False):。
注意事项:手动改文件的方案已在 Issue 中被多名用户验证,但 Docker 容器每次启动会更新并还原手动修改,因此不是长期方案;应尽量通过更新 SwarmUI 获得持久修复。
问题场景
用户在 Docker 中启动 SwarmUI,容器启动时自动将 SwarmUI 与 ComfyUI 更新到最新版本。此前生成图片正常,更新后每次在 SwarmUI 中尝试生成图片都会触发该报错。用户还提到,在 Comfy 标签页直接加载“MOSS-Image: Text to Image”模板并运行示例提示词可以正常出图,说明问题更可能出在 SwarmUI 侧的自定义节点调用,问题并非出在 ComfyUI 基础生成链路上。
报错原文
module 'comfy.model_management' has no attribute 'directml_enabled'
原因分析
根据 Issue 讨论,可能原因是 ComfyUI 上游提交 c5751c81abe131202eea9e4c66d000589013dd0b 删除了 directml_enabled 相关引用,而 SwarmUI 内置扩展中的 SwarmKSampler.py 仍在直接访问 comfy.model_management.directml_enabled。用户将 ComfyUI 回退到提交 a592c0a654af22f75d97f214d6e3e34eb13cd9db 后报错消失,进一步支持了版本不匹配的判断。维护者随后说明已移除 directml 引用并更新 SwarmUI。
环境排查
- 确认 SwarmUI 是否为包含 directml 引用移除修复的最新版本。
- 确认 ComfyUI 版本,重点检查是否包含提交 c5751c81abe131202eea9e4c66d000589013dd0b 的变更。
- 检查
SwarmUI\src\BuiltinExtensions\ComfyUIBackend\ExtraNodes\SwarmComfyCommon\SwarmKSampler.py第 29 行是否仍为直接访问comfy.model_management.directml_enabled的旧写法。 - Docker 用户需确认容器启动时是否会自动更新 SwarmUI 和 ComfyUI,并覆盖手动修改的文件。
- Issue 未提供 Python、CUDA、PyTorch 和显卡型号,暂无相关版本证据可核对。
解决步骤
- 优先更新 SwarmUI 到包含修复的版本。Issue 中维护者已说明 directml 引用被移除,更新后应恢复生成。
- 如果更新后仍报错,检查
SwarmUI\src\BuiltinExtensions\ComfyUIBackend\ExtraNodes\SwarmComfyCommon\SwarmKSampler.py第 29 行。 - 可优先尝试将该行改为:
if getattr(comfy.model_management, "directml_enabled", False): - 如果使用 Docker 且容器启动会自动更新,需注意手动修改会被还原;应在更新 SwarmUI 后重新检查该文件,必要时再次应用修改或使用可持久化的挂载方式。
- 不建议长期依赖回退 ComfyUI 提交作为方案;Issue 中回退仅用于确认原因。
验证方法
重新在 SwarmUI 中提交一次生图任务,确认不再出现 module 'comfy.model_management' has no attribute 'directml_enabled',且图片可以正常生成。Issue 中有用户反馈应用 aoleg 给出的 getattr 修改后问题解决,可作为验证该修改生效的依据。
参考来源
mcmonkeyprojects/SwarmUI #1593
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。
![[Question]: Welcome to nginx when launching from source](https://www.chat-gpts.plus/wp-content/uploads/2026/11/7401-7e19626b-768x403.jpg)
![[Question]: The retrieval testing of the knowledge base encountered an issue when flipping through the retrieved results.](https://www.chat-gpts.plus/wp-content/uploads/2026/11/8555-c8061813-768x403.jpg)
![[Bug]: KeyError: 'results'](https://www.chat-gpts.plus/wp-content/uploads/2026/11/6157-6e18c3a5-768x403.jpg)