Comfy-Org/ComfyUI · critical · Exception

CORRUPTED MODEL: one of the q-k-v values for the text encode

Error message

CORRUPTED MODEL: one of the q-k-v values for the text encoder was missing

What it means

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).

Source

Thrown at comfy/diffusers_convert.py:175

                or k.endswith(".self_attn.v_proj.bias")
        ):
            k_pre = k[: -len(".q_proj.bias")]
            k_code = k[-len("q_proj.bias")]
            if k_pre not in capture_qkv_bias:
                capture_qkv_bias[k_pre] = [None, None, None]
            capture_qkv_bias[k_pre][code2idx[k_code]] = v
            continue

        text_proj = "transformer.text_projection.weight"
        if k.endswith(text_proj):
            new_state_dict[k.replace(text_proj, "text_projection")] = v.transpose(0, 1).contiguous()
        else:
            relabelled_key = textenc_pattern.sub(lambda m: protected[re.escape(m.group(0))], k)
            new_state_dict[relabelled_key] = v

    for k_pre, tensors in capture_qkv_weight.items():
        if None in tensors:
            raise Exception("CORRUPTED MODEL: one of the q-k-v values for the text encoder was missing")
        relabelled_key = textenc_pattern.sub(lambda m: protected[re.escape(m.group(0))], k_pre)
        new_state_dict[relabelled_key + ".in_proj_weight"] = cat_tensors(tensors)

    for k_pre, tensors in capture_qkv_bias.items():
        if None in tensors:
            raise Exception("CORRUPTED MODEL: one of the q-k-v values for the text encoder was missing")
        relabelled_key = textenc_pattern.sub(lambda m: protected[re.escape(m.group(0))], k_pre)
        new_state_dict[relabelled_key + ".in_proj_bias"] = cat_tensors(tensors)

    return new_state_dict


def convert_text_enc_state_dict(text_enc_dict):
    return text_enc_dict

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Re-download the model from a trusted source and verify its size/SHA.
  2. Load the file with safetensors/transformers independently and confirm every text-encoder attention layer has all q/k/v tensors.
  3. If it's your own export, fix the export to include the full text_encoder state dict.
Defensive patterns

Strategy: try-catch

Validate before calling

sd = comfy.utils.load_torch_file(path)
for k in sd:
    if k.endswith("self_attn_layer_norm.weight") and "text_encoder" in k:
        layer = k.rsplit("self_attn", 1)[0]
        parts = [f"{layer}{'q' if False else p}_proj.weight" for p in ("q", "k", "v")]
        if not all(p in sd or p.replace(".text_encoder.", ".") in sd for p in parts):
            raise SystemExit("checkpoint text encoder incomplete: missing q/k/v")
            break
        break

Try / catch

from comfy import diffusers_convert
try:
    out = diffusers_convert.convert_diffusers_sdxl_checkpoint(sd)
except Exception as e:
    if "CORRUPTED MODEL" in str(e):
        raise SystemExit("model file incomplete — re-download from the original source") from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: Interrupted model download producing a partial file; community re-uploads that dropped tensors; conversion scripts renaming keys inconsistently between transformers versions.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/f145991dba74c602. Report an issue: GitHub.