{"record":{"id":"a5034aa6fc12e184","repo":"lllyasviel/Fooocus","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":"ldm_patched/modules/diffusers_convert.py","lineNumber":245,"sourceCode":"\n        if (\n                k.endswith(\".self_attn.q_proj.bias\")\n                or k.endswith(\".self_attn.k_proj.bias\")\n                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        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\"] = torch.cat(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\"] = torch.cat(tensors)\n\n    return new_state_dict\n\n\ndef convert_text_enc_state_dict(text_enc_dict):\n    return text_enc_dict\n\n\n","sourceCodeStart":227,"sourceCodeEnd":262,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/modules/diffusers_convert.py#L227-L262","documentation":"diffusers_convert.convert_text_enc_state_dict collects q_proj/k_proj/v_proj weights for the CLIP text encoder and merges them into a single in_proj_weight tensor. If, for any captured prefix, one of the three projection weights is still None (i.e. one of q/k/v was never seen in the state dict), the checkpoint is considered structurally broken and this exception is raised. It protects against building a malformed in_proj_weight full of holes.","triggerScenarios":"Calling load_checkpoint_guess_config (or any path that converts an SD2.x-style text encoder) on a .safetensors/.ckpt whose text encoder section contains q_proj.weight but is missing k_proj.weight or v_proj.weight (or vice versa). Happens when a checkpoint was pruned, hand-edited, merged incorrectly, or truncated during download.","commonSituations":"Users re-saving a checkpoint with a script that filters keys by substring and accidentally drops one projection; interrupted downloads (file parses but keys incomplete); mixing SD1.5 CLIP weights into an SD2.1 checkpoint manually.","solutions":["Re-download the checkpoint from the original source and verify its file size/SHA","If the file was self-merged or pruned, re-export it keeping ALL text encoder q/k/v projection keys","Inspect keys: torch / safetensors load and list keys matching *.q_proj.* / *.k_proj.* / *.v_proj.* to find which projection is missing","As a workaround, load the model without the text encoder and pair it with a separate standalone CLIP file"],"exampleFix":"from safetensors import safe_open\n\nwith safe_open('model.safetensors', framework='pt') as f:\n    keys = list(f.keys())\nqkv = {p: [k for k in keys if p in k] for p in ('q_proj', 'k_proj', 'v_proj')}\n# before: one of the lists empty -> 'CORRUPTED MODEL' at conversion\n# after: all three non-empty -> conversion succeeds\nassert all(len(v) > 0 for v in qkv.values()), qkv","handlingStrategy":"validation","validationCode":"from safetensors import safe_open\n\ndef has_full_qkv_weights(path):\n    with safe_open(path, framework='pt') as f:\n        keys = [k for k in f.keys() if k.endswith(('.q_proj.weight', '.k_proj.weight', '.v_proj.weight'))]\n    prefixes = {k.rsplit('.', 2)[0] for k in keys}\n    ok = {k.rsplit('.', 2)[0] for k in keys if k.endswith('.q_proj.weight')}\n    # every prefix that has any projection must have all three weights\n    have = {}\n    for k in keys:\n        have.setdefault(k.rsplit('.', 2)[0], set()).add(k.rsplit('.', 1)[1])\n    return all(v == {'weight'} and p in ok for p, v in have.items()) and len(ok) == len(prefixes)","typeGuard":null,"tryCatchPattern":"try:\n    sd_out = ldm_patched.modules.diffusers_convert.convert_text_enc_state_dict(sd)\nexcept Exception as e:\n    if 'CORRUPTED MODEL' in str(e):\n        raise SystemExit('Checkpoint text encoder is incomplete (missing q/k/v projection); re-download it') from e\n    raise","preventionTips":["Verify file size/SHA against the publisher after every download","Never filter text-encoder keys by substring when re-saving checkpoints","Scan for the q/k/v weight triple before invoking any conversion pipeline"],"tags":["corruption","checkpoint","text-encoder","clip","conversion","safetensors"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}