{"record":{"id":"3a07d1382b2af6e9","repo":"invoke-ai/InvokeAI","slug":"pid-checkpoint-is-missing-len-missing-keys-requ","errorCode":null,"errorMessage":"PiD checkpoint is missing {len(missing)} keys required by PidNet{detail}: {missing[:5]}","messagePattern":"PiD checkpoint is missing (.+?) keys required by PidNet(.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/pid/decode.py","lineNumber":289,"sourceCode":"    # strict=False so we can report missing and unexpected keys separately; both are fatal. The model\n    # cache builds loaders under `skip_torch_weight_init()`, which no-ops every `reset_parameters()`,\n    # so a key the checkpoint does not supply is left as uninitialised memory rather than a sane\n    # default — a partial checkpoint would decode to garbage / NaNs instead of failing.\n    missing, unexpected = net.load_state_dict(state_dict, strict=False)\n    if unexpected:\n        raise RuntimeError(\n            f\"PiD checkpoint has unexpected keys not present in PidNet: {unexpected[:5]}\"\n            + (f\" (+ {len(unexpected) - 5} more)\" if len(unexpected) > 5 else \"\")\n        )\n    if missing:\n        lq = [k for k in missing if k.startswith(\"lq_proj.\")]\n        detail = (\n            \" (the LQ projection is incomplete — this looks like a base PixDiT_T2I checkpoint rather than a \"\n            \"PiD super-resolution decoder)\"\n            if lq and len(lq) == len(missing)\n            else \"\"\n        )\n        raise RuntimeError(\n            f\"PiD checkpoint is missing {len(missing)} keys required by PidNet{detail}: {missing[:5]}\"\n            + (f\" (+ {len(missing) - 5} more)\" if len(missing) > 5 else \"\")\n        )\n    return net\n\n\n# ---------------------------------------------------------------------------\n# Sampling\n# ---------------------------------------------------------------------------\n\n\ndef _get_t_list(device: torch.device, *, num_steps: Optional[int] = None) -> Tensor:\n    \"\"\"Distill-student sigma schedule.\n\n    When *num_steps* differs from the trained 4 steps, linearly sub-sample\n    the canonical 5-point list (mirrors `PidDistillModel._get_t_list`).\n    \"\"\"\n    full = torch.tensor(_STUDENT_T_LIST, device=device, dtype=torch.float32)","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/pid/decode.py#L271-L307","documentation":"After a strict=False load, load_pid_decoder checks the reported missing keys. If the checkpoint lacks any parameter the PidNet requires, it raises RuntimeError with the count and first 5 missing keys. If every missing key is part of lq_proj, the message additionally explains that the file looks like a base PixDiT_T2I checkpoint rather than a PiD super-resolution decoder — since the model cache skips weight init, missing keys would otherwise leave uninitialized garbage weights.","triggerScenarios":"Calling load_pid_decoder with a checkpoint that omits required parameters: an incomplete save, a base PixDiT_T2I checkpoint lacking lq_proj.*, or a backbone mismatch that changes the expected parameter set.","commonSituations":"Downloading a truncated/partial file, confusing the base model checkpoint with the PiD SR decoder checkpoint, or loading a checkpoint saved before a module was added.","solutions":["Use the correct PiD super-resolution decoder checkpoint (one containing lq_proj.* keys), not the base PixDiT_T2I checkpoint","Re-download the checkpoint if the file is truncated; verify its size/checksum","Match the backbone argument to the checkpoint so the expected key set aligns"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"sd = torch.load(path, map_location=\"cpu\")\nmissing = set(build_pid_net(backbone).state_dict()) - set(sd)\nassert not missing, f\"missing keys: {sorted(missing)[:5]}\"","typeGuard":null,"tryCatchPattern":"try:\n    net = load_pid_decoder(path, backbone=backbone)\nexcept RuntimeError as e:\n    if \"missing\" in str(e):\n        logger.error(f\"Incomplete checkpoint: {e}\")\n    raise","preventionTips":["Verify file size/checksum after download","Keep base and SR-decoder checkpoints distinct","Record expected key sets with assets"],"tags":["checkpoint","state-dict","missing-keys","model-loading"],"backgroundTag":"state-dict-key-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}