{"record":{"id":"f145991dba74c602","repo":"Comfy-Org/ComfyUI","slug":"corrupted-model-one-of-the-q-k-v-values-for-the-t","errorCode":null,"errorMessage":"CORRUPTED MODEL: one of the q-k-v values for the text encoder was missing","messagePattern":"CORRUPTED MODEL: one of the q-k-v values for the text encoder was missing","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"comfy/diffusers_convert.py","lineNumber":175,"sourceCode":"                or k.endswith(\".self_attn.v_proj.bias\")\n        ):\n            k_pre = k[: -len(\".q_proj.bias\")]\n            k_code = k[-len(\"q_proj.bias\")]\n            if k_pre not in capture_qkv_bias:\n                capture_qkv_bias[k_pre] = [None, None, None]\n            capture_qkv_bias[k_pre][code2idx[k_code]] = v\n            continue\n\n        text_proj = \"transformer.text_projection.weight\"\n        if k.endswith(text_proj):\n            new_state_dict[k.replace(text_proj, \"text_projection\")] = v.transpose(0, 1).contiguous()\n        else:\n            relabelled_key = textenc_pattern.sub(lambda m: protected[re.escape(m.group(0))], k)\n            new_state_dict[relabelled_key] = v\n\n    for k_pre, tensors in capture_qkv_weight.items():\n        if None in tensors:\n            raise Exception(\"CORRUPTED MODEL: one of the q-k-v values for the text encoder was missing\")\n        relabelled_key = textenc_pattern.sub(lambda m: protected[re.escape(m.group(0))], k_pre)\n        new_state_dict[relabelled_key + \".in_proj_weight\"] = cat_tensors(tensors)\n\n    for k_pre, tensors in capture_qkv_bias.items():\n        if None in tensors:\n            raise Exception(\"CORRUPTED MODEL: one of the q-k-v values for the text encoder was missing\")\n        relabelled_key = textenc_pattern.sub(lambda m: protected[re.escape(m.group(0))], k_pre)\n        new_state_dict[relabelled_key + \".in_proj_bias\"] = cat_tensors(tensors)\n\n    return new_state_dict\n\n\ndef convert_text_enc_state_dict(text_enc_dict):\n    return text_enc_dict\n","sourceCodeStart":157,"sourceCodeEnd":190,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/diffusers_convert.py#L157-L190","documentation":"convert_diffusers_sdxl_checkpoint (diffusers→ComfyUI text-encoder conversion) collects the three q/k/v in_proj weight tensors for each CLIP attention layer. If any of the three slots is still None at flush time, the checkpoint did not contain a complete q-k-v triple, and the loader raises this Exception rather than concatenating a hole. The same corruption check exists for biases (line 181).","triggerScenarios":"Loading a diffusers-format SDXL checkpoint whose text_encoder sub-dict is missing one of in_proj_query/.../key weights for any layer; a safetensors file truncated mid-export; a checkpoint that stored qkv fused under unexpected key names so one slot never matches.","commonSituations":"Interrupted model download producing a partial file; community re-uploads that dropped tensors; conversion scripts renaming keys inconsistently between transformers versions.","solutions":["Re-download the model from a trusted source and verify its size/SHA.","Load the file with safetensors/transformers independently and confirm every text-encoder attention layer has all q/k/v tensors.","If it's your own export, fix the export to include the full text_encoder state dict."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"sd = comfy.utils.load_torch_file(path)\nfor k in sd:\n    if k.endswith(\"self_attn_layer_norm.weight\") and \"text_encoder\" in k:\n        layer = k.rsplit(\"self_attn\", 1)[0]\n        parts = [f\"{layer}{'q' if False else p}_proj.weight\" for p in (\"q\", \"k\", \"v\")]\n        if not all(p in sd or p.replace(\".text_encoder.\", \".\") in sd for p in parts):\n            raise SystemExit(\"checkpoint text encoder incomplete: missing q/k/v\")\n            break\n        break","typeGuard":null,"tryCatchPattern":"from comfy import diffusers_convert\ntry:\n    out = diffusers_convert.convert_diffusers_sdxl_checkpoint(sd)\nexcept Exception as e:\n    if \"CORRUPTED MODEL\" in str(e):\n        raise SystemExit(\"model file incomplete — re-download from the original source\") from e\n    raise","preventionTips":["Verify downloaded checkpoint size/SHA against the source repo.","Prefer safetensors originals; avoid re-serialized community copies for SDXL diffusers checkpoints."],"tags":["model-loading","diffusers","sdxl","corruption"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}