shape '[11520, 3840]' is invalid for input of size 20086739 File "F:\ComfyUI_win...
🚨 错误信息
RuntimeError: shape '[11520, 3840]' is invalid for input of size 20086739
File "F:\ComfyUI_windows_portable\ComfyUI\execution.py", line 525, in execute
output_data, output_ui, has_subgraph, has_pending_tasks = await get_output_data(prompt_id, unique_id, obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\ComfyUI_windows_portable\ComfyUI\execution.py", line 334, in get_output_data
return_values = await _async_map_node_over_list(prompt_id, unique_id, obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\ComfyUI_windows_portable\ComfyUI\execution.py", line 308, in _async_map_node_over_list
await process_inputs(input_dict, i)
File "F:\ComfyUI_windows_portable\ComfyUI\execution.py", line 296, in process_inputs
result = f(**inputs)
File "F:\ComfyUI_windows_portable\ComfyUI\nodes.py", line 973, in load_unet
model = comfy.sd.load_diffusion_model(unet_path, model_options=model_options)
File "F:\ComfyUI_windows_portable\ComfyUI\comfy\sd.py", line 1793, in load_diffusion_model
sd, metadata = comfy.utils.load_torch_file(unet_path, return_metadata=True)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\ComfyUI_windows_portable\ComfyUI\comfy\utils.py", line 149, in load_torch_file
raise e
File "F:\ComfyUI_windows_portable\ComfyUI\comfy\utils.py", line 129, in load_torch_file
sd, metadata = load_safetensors(ckpt)
~~~~~~~~~~~~~~~~^^^^^^
File "F:\ComfyUI_windows_portable\ComfyUI\comfy\utils.py", line 110, in load_safetensors
tensor = torch.frombuffer(mv[start:end], dtype=_TYPES[info["dtype"]]).view(info["shape"])
🤖 AI解决方案
报错分析报告
1.错误翻译
原文:RuntimeError: shape '[11520, 3840]' is invalid for input of size 20086739
译文:运行时错误:形状'[11520, 3840]'对大小为20086739的输入无效
2. 原因分析
[11520, 3840]需11520×3840=44,236,800个元素,但实际输入仅20,086,739个元素,尺寸不匹配。 comfy/utils.py的load_safetensors函数中,torch.frombuffer(...).view(info["shape"])试图将缓冲区视图为无效形状。 load_unet节点)时,读取safetensors文件的元数据与实际文件内容冲突(模型文件损坏/不完整)。3.解决方案
python
步骤1:验证模型文件完整性(以Windows为例)
import hashlib
def verify_model(file_path, expected_hash):
with open(file_path, 'rb') as f:
actual_hash = hashlib.sha256(f.read()).hexdigest()
return actual_hash == expected_hash使用示例(替换为你的模型路径和官方哈希值)
unet_path = "F:\\ComfyUI_windows_portable\\ComfyUI\\models\\unet\\your_model.safetensors"
expected_sha256 = "官方提供的模型SHA256哈希值" # 从模型来源处获取
if not verify_model(unet_path, expected_sha256):
print("模型文件损坏,请重新下载!")步骤2:重新下载完整的UNet模型(优先方案)
从官方渠道(如Hugging Face)重新获取与当前ComfyUI版本兼容的UNet模型
4.️ 预防措施
safetensors库的verify命令(终端执行:safetensors verify your_model.safetensors)、[HashTab](https://implbits.com/products/hashtab/)(Windows文件哈希查看器)。