You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Stable Diffusion中LyCORIS模型报错:张量维度768与1024不匹配

问题描述
  • 系统:Windows 10
  • 硬件:Intel Core i9、64GB内存、Nvidia RTX 3060
  • 工具环境:AUTOMATIC1111/stable-diffusion-webui,已安装LoRA和LyCORIS扩展(二者均在Extra Networks标签页显示)

从civiai.com下载的所有LoRA模型均可正常运行,但10个LyCORIS模型仅colouredglazecd-000006.safetensors可用——在img2img模式下,以粉色玫瑰图为底,搭配提示词lyco:colouredglazecd-000006:1.0 rose可生成正常图像。使用其余9个LyCORIS模型(如lyco:CenturyBotanicalIllustration:1.0 rose)时,触发以下错误:

RuntimeError: The size of tensor a (768) must match the size of tensor b (1024) at non-singleton dimension 1

调整输出图像宽高无法解决问题,附webui-user.bat的日志片段:

日志片段(启动阶段)

key failed to match: lora_te_text_model_encoder_layers_12_mlp_fc1.alpha████████████████| 16/16 [00:06<00:00,  3.09it/s]
key failed to match: lora_te_text_model_encoder_layers_12_mlp_fc1.lora_down.weight
key failed to match: lora_te_text_model_encoder_layers_12_mlp_fc1.lora_up.weight
key failed to match: lora_te_text_model_encoder_layers_12_mlp_fc2.alpha
key failed to match: lora_te_text_model_encoder_layers_12_mlp_fc2.lora_down.weight
key failed to match: lora_te_text_model_encoder_layers_12_mlp_fc2.lora_up.weight
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_k_proj.alpha
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_k_proj.lora_down.weight
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_k_proj.lora_up.weight
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_out_proj.alpha
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_out_proj.lora_down.weight
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_out_proj.lora_up.weight
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_q_proj.alpha
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_q_proj.lora_down.weight
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_q_proj.lora_up.weight
key failed to match: lora_te_text_model_encoder_layers_12_self_attn_v_proj.alpha

日志片段(报错阶段)

File "G:\GenAI\venv\lib\site-packages\transformers\models\clip\modeling_clip.py", line 268, in forward
        query_states = self.q_proj(hidden_states) * self.scale
      File "G:\GenAI\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "G:\GenAI\extensions-builtin\Lora\lora.py", line 400, in lora_Linear_forward
        return torch.nn.Linear_forward_before_lora(self, input)
      File "G:\GenAI\extensions\a1111-sd-webui-lycoris\lycoris.py", line 739, in lyco_Linear_forward
        lyco_apply_weights(self)
      File "G:\GenAI\extensions\a1111-sd-webui-lycoris\lycoris.py", line 706, in lyco_apply_weights
        self.weight += updown
    RuntimeError: The size of tensor a (768) must match the size of tensor b (1024) at non-singleton dimension 1
解决方法
  • 核心原因:报错的LyCORIS模型基于1024维度的CLIP文本编码器训练(对应SD 2.x系列模型),而当前加载的主模型使用的是768维度的CLIP(对应SD 1.x系列模型),两者维度不匹配导致张量运算失败。
  • 具体解决步骤:
    1. 确认模型适配版本:查看对应LyCORIS模型的页面描述,确认它是为SD 1.x还是SD 2.x训练的。
    2. 切换对应主模型:如果模型适配SD 2.x,就加载SD 2.x系列的主模型(如v2-1_768-ema-pruned.safetensors或v2-1_1024-ema-pruned.safetensors)后再使用该LyCORIS。
    3. 转换模型维度(可选):若需要在SD 1.x下使用,可借助webui的模型转换扩展将1024维度的LyCORIS转换为768维度,转换完成后放入LyCORIS目录即可使用。
    4. 更新LyCORIS扩展:确保LyCORIS扩展为最新版本,在webui的扩展页面点击「检查更新」,更新完成后重启webui重试。

内容的提问来源于stack exchange,提问作者Zaffer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 14:35:45