Weights only load failed. This file can still be loaded, to do so you have two options,

在 ComfyUI Impact Pack 的 Ultralytics Detector Provider 节点加载检测模型时,如果 PyTorch 报出 Weights only load failed. This file can still be loaded, to do so you ha

快速结论:在 ComfyUI Impact Pack 的 Ultralytics Detector Provider 节点加载检测模型时,如果 PyTorch 报出 Weights only load failed. This file can still be loaded, to do so you have two options,,通常是因为当前版本的 Impact Subpack 搭配了过旧的 ultralytics 包。优先把 ComfyUI 所在 Python 环境中的 ultralytics 升级到 8.3.162 或更高版本。

适用环境:Issue 中确认涉及 ComfyUI Impact Pack(含 Impact Subpack)、Ultralytics Detector Provider 节点、Python 运行的 ComfyUI 环境,以及 ultralytics 包;其中还提到便携版(portable build)可用 python_embeded\python.exe 执行 pip。Issue 未提供具体的操作系统、Python 版本、PyTorch 版本或显卡型号。

最快修复方案:在运行 ComfyUI 的那个 Python 环境中执行 pip install -U "ultralytics>=8.3.162";便携版可用 python_embeded\python.exe -m pip install -U "ultralytics>=8.3.162"。重装 Impact Subpack 也会重新安装其依赖要求,效果等同。

注意事项:Issue 明确说明无需修改 subcore.py,也无需把模型类加入白名单;把 weights_only 改为 False 不是推荐做法,且会带来任意代码执行风险。升级后需重启 ComfyUI 再验证。

问题场景

用户在 ComfyUI 中使用 Impact Pack 的 Ultralytics Detector Provider 节点加载检测模型时触发该报错。用户曾尝试在若干位置把 weights_only 改为 False,但重启 ComfyUI 后错误仍然出现。

报错原文

Weights only load failed. This file can still be loaded, to do so you have two options,
(1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
(2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
WeightsUnpickler error: Unsupported global: GLOBAL ultralytics.nn.tasks.DetectionModel was not an allowed global by default. Please use `torch.serialization.add_safe_globals([ultralytics.nn.tasks.DetectionModel])` or the `torch.serialization.safe_globals([ultralytics.nn.tasks.DetectionModel])` context manager to allowlist this global if you trust this class/function.

原因分析

根据 Issue 中的回复,这是当前 Impact Subpack 与旧版 ultralytics 包组合导致的问题。自 Subpack V1.3.5 起,需要 ultralytics>=8.3.162;新版本 ultralytics 以自己的方式加载模型,Subpack 会放行这种加载方式;而旧版 ultralytics 的加载方式会经过 Subpack 检查,检查在 ultralytics.nn.tasks.DetectionModel 处被拦截,于是出现上述 WeightsUnpickler 报错。

环境排查

  • 确认运行 ComfyUI 的 Python 解释器是否为实际执行节点的那个环境,避免改错环境。
  • 确认 Impact Subpack 的版本,V1.3.5 及以上要求 ultralytics>=8.3.162。
  • 确认已安装的 ultralytics 版本是否低于 8.3.162。
  • 便携版需确认使用的是 python_embeded\python.exe,而非系统 Python。
  • Issue 未提供 PyTorch、CUDA、Python 与显卡版本,这部分可作为一般性核对项,不作为本问题的直接结论。

解决步骤

  1. 在运行 ComfyUI 的 Python 环境中升级 ultralytics:pip install -U "ultralytics>=8.3.162"。
  2. 若使用便携版,在对应目录执行:python_embeded\python.exe -m pip install -U "ultralytics>=8.3.162"。
  3. 可选替代:重装 Impact Subpack,使其 requirements 再次安装,从而带上新版 ultralytics。
  4. 重启 ComfyUI,使新依赖生效。
  5. 不要通过修改 subcore.py 或添加 ultralytics.nn.tasks.DetectionModel 白名单来绕过;Issue 回复明确表示不需要这样做。

验证方法

重启 ComfyUI 后再次使用 Ultralytics Detector Provider 节点加载模型,确认不再出现 Weights only load failed / WeightsUnpickler error 报错,节点能正常加载检测模型即可。也可在对应 Python 环境中检查 ultralytics 版本是否已达到 8.3.162 或更高。

参考来源

ltdrdata/ComfyUI-Impact-Pack #1159

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 36121

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注