
RuntimeError: Error(s) in loading state_dict for Resampler:
快速结论:该报错通常在使用 Stable Diffusion WebUI Forge 的 ControlNet(内置)、IP-Adapter 或 Instant-ID 功能时触发,由于模型权重加载时的 key 名称不匹配导致。优先排查模型文件是否完整或版本是否匹配。
问题场景
用户在使用 Stable Diffusion WebUI Forge(版本 f0.0.10-latest-104-g5a7e7555 至 f0.0.11-latest-105-gac94f38d)时,尝试启用 ControlNet(内置)、IP-Adapter 或 Instant-ID 进行图片生成。用户选择 InsightFace(InstantID)模型(control_instant_id_sdxl,hash c5c25a50),添加参考图片并点击生成后,控制台报错,且输出图片未使用参考图像。
报错原文
RuntimeError: Error(s) in loading state_dict for Resampler:
Missing key(s) in state_dict: "k_proj.weight", "k_proj.bias", "v_proj.weight", "v_proj.bias", "q_proj.weight", "q_proj.bias", "out_proj.weight", "out_proj.bias", "layer_norm.weight", "layer_norm.bias", "ln_0.weight", "ln_0.bias", "ln_1.weight", "ln_1.bias", "ln_2.weight", "ln_2.bias"
Unexpected key(s) in state_dict: "k_proj.weight", "k_proj.bias", "v_proj.weight", "v_proj.bias", "q_proj.weight", "q_proj.bias", "out_proj.weight", "out_proj.bias", "layer_norm.weight", "layer_norm.bias", "ln_0.weight", "ln_0.bias", "ln_1.weight", "ln_1.bias", "ln_2.weight", "ln_2.bias"
AttributeError: 'dict' object has no attribute 'clone'
原因分析
可能原因:报错表明 state_dict 中存在一系列 key 不匹配问题,且后续触发 AttributeError: 'dict' object has no attribute 'clone'。在 IP-Adapter 或 Instant-ID 的相关模型加载代码中,Resampler(重采样器)模块期望加载到的 state_dict 是 OrderedDict 或类似字典对象,但实际传入的是一个嵌套字典(dict),导致 .clone() 方法无法调用。这通常是因为模型文件(如 ip-adapter_sd15.safetensors 或 control_instant_id_sdxl.safetensors)的格式或版本与 WebUI Forge 的加载代码不兼容。
环境排查
- Python 版本:3.10.6
- PyTorch 版本:2.1.2+cu121
- WebUI 版本:f0.0.10-latest-104-g5a7e7555 或 f0.0.11-latest-105-gac94f38d
- 显卡:NVIDIA GeForce RTX 4090(VRAM 24 GB)
- 系统:Windows
- 模型文件:需确认使用的 IP-Adapter / Instant-ID 模型文件是否为从 lllyasviel 的 Hugging Face 仓库下载的官方权重。
解决步骤
- 重新下载模型文件。 删除现有位于
models/ControlNet目录下的ip-adapter_sd15.safetensors或control_instant_id_sdxl.safetensors文件,从 lllyasviel 的官方 Hugging Face 仓库(sd_control_collection)重新下载对应模型。确保下载的是完整且未损坏的文件。 - 清理缓存并重启。 删除
stable-diffusion-webui-forge目录下的venv文件夹,重新运行webui.bat或webui-user.bat,让脚本自动重建虚拟环境并重新安装依赖(包括 PyTorch、torchvision 等)。 - 回退到较早的 Forge 版本。 如果以上步骤无效,尝试将 WebUI Forge 回退到 Issue 中提及的未报错版本(如 f0.0.9),或更新到最新版本以检查是否已修复。
验证方法
在 WebUI 中加载一个 SDXL 或 SD1.5 基础模型后,启用 ControlNet,选择 IP-Adapter 或 Instant-ID 预处理器,上传参考图片并点击生成。观察控制台是否无报错,并且输出图像应正确反映参考图片的构图或风格特征。


![[Bug] Desktop 2.2.5 (Windows, Cloud): sign-in loop — /api/auth/get-session returns null while OIDC bearer token is valid → bounces to "Sign](https://www.chat-gpts.plus/wp-content/uploads/2026/06/15931-43eff339-768x403.jpg)
