Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the c

用户在 ComfyUI 环境中使用 Impact Pack 或 Impact Subpack 节点加载 YOLO 模型(例如通过 subcore.load_yolo 或 YOLO 节点)时触发报错。问题与 PyTorch 2.6+ 的安全加载机制变更相关。Issue 中用户使用的具体版本为 torc

Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the c

Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.

快速结论:该报错通常出现在 ComfyUI Impact Pack / Subpack 加载 YOLO 模型或其他 PyTorch checkpoint 时,原因是 PyTorch 2.6+ 将 torch.loadweights_only 默认值由 False 改为 True,而模型加载过程使用了 getattr 等不被默认白名单允许的操作。优先排查是否使用了较新的 PyTorch 版本(如 torch-2.7.0+cu128),并确认模型来源是否可信。

问题场景

用户在 ComfyUI 环境中使用 Impact Pack 或 Impact Subpack 节点加载 YOLO 模型(例如通过 subcore.load_yolo 或 YOLO 节点)时触发报错。问题与 PyTorch 2.6+ 的安全加载机制变更相关。Issue 中用户使用的具体版本为 torch-2.7.0+cu128,运行于 ComfyUI 便携版环境。

报错原文

Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.
        (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 getattr was not an allowed global by default. Please use `torch.serialization.add_safe_globals([getattr])` or the `torch.serialization.safe_globals([getattr])` context manager to allowlist this global if you trust this class/function.

原因分析

可能原因:PyTorch 2.6 及以上版本调整了 torch.loadweights_only 默认行为,从 False 改为 True,以增强安全性。加载的模型(如某些 YOLO 或自定义 checkpoint)在 unpickling 过程中使用了 getattr 等不被默认安全白名单允许的操作,导致加载失败。Subpack 作者明确表示 “Subpack will not support a bypass for this model”,即不会为使用 getattr 的模型提供绕过方案。解决方式需要用户自行承担风险并修改加载行为。

环境排查

  • PyTorch 版本:确认是否为 2.6.0 及以上版本(如 torch-2.7.0+cu128)。
  • ComfyUI Impact Pack / Subpack 版本:确认 Subpack 版本(如 nightly 1.3.1)。
  • Python 及 CUDA 版本:记录环境配置。
  • 模型文件来源:确认模型是否为可信来源。

解决步骤

  1. 方法一(可优先尝试 — 使用官方推荐的 unsafe-torch 节点):

    • 安装 comfyui-unsafe-torch 自定义节点。
    • 该节点会全局禁用 PyTorch 的 weights_only 安全检查,加载模型时将回退到不安全模式。注意:仅在信任模型来源时使用。
  2. 方法二(直接修改 Subpack 代码 — 仅作为临时方案,需自行承担风险):

    • 打开 ComfyUI/custom_nodes/ComfyUI-Impact-Subpack/modules/subcore.py 文件。
    • 找到涉及 weights_only 的代码段。在不同版本中行号可能不同:
    • 对于较早版本:找到第 141-144 行附近的逻辑,强制将 weights_only 的值设为 False
    • 对于 Subpack nightly 1.3.1 版本:找到类似 load_kwargs['weights_only'] = True 的行(约第 269 行),将其改为 load_kwargs['weights_only'] = False
    • 保存文件后重启 ComfyUI。
  3. 方法三(使用模型白名单功能 — 但 Issue 中反馈该方法未完全解决问题):

    • 参考 Subpack 官方文档 关于 model-whitelist.txt 的配置说明。
    • 将模型名称(可能需完整路径或带扩展名)添加到白名单文件中。
    • 注意:Issue 中有用户反馈即使添加后控制台显示 “Loaded 1 model(s) from whitelist”,仍然会报错并回退到安全模式,实际仍需修改 subcore.py。

验证方法

重启 ComfyUI 后,再次运行加载该模型的节点工作流。观察是否不再弹出 “Weights only load failed” 错误,模型正常加载并参与后续推理。注意:若使用 code 修改方式,每次更新 Subpack 节点后可能需要重新修改。

参考来源

ltdrdata/ComfyUI-Impact-Pack #931

GamsGo AI

AI 工具推荐

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

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

了解 GamsGo AI

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

celebrityanime
celebrityanime
文章: 8011

发表回复

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