{"record":{"id":"dd23be714a69a261","repo":"invoke-ai/InvokeAI","slug":"pid-checkpoint-has-len-mismatched-weights-whose","errorCode":null,"errorMessage":"PiD checkpoint has {len(mismatched)} weights whose shape PidNet cannot accept (e.g. {k}: {got}, expected {want}); loading it would fail with a size mismatch","messagePattern":"PiD checkpoint has (.+?) weights whose shape PidNet cannot accept \\(e\\.g\\. (.+?): (.+?), expected (.+?)\\); loading it would fail with a size mismatch","errorType":"exception","errorClass":"InvalidMatchError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/pid_decoder.py","lineNumber":171,"sourceCode":"    # the `Unknown_Config` registration these checks exist to prevent, so the crash fails as a silent\n    # accept rather than loudly. Only `unexpected` can hold one today; sorting both the same way keeps\n    # that from depending on which set is on which side of the subtraction.\n    if missing := sorted(contract.keys() - shapes.keys(), key=str):\n        raise InvalidMatchError(\n            f\"PiD checkpoint is missing {len(missing)} of the weights required by PidNet; the file is \"\n            f\"incomplete and cannot be used as a PiD decoder: {missing[:5]}{_and_more(missing)}\"\n        )\n\n    if unexpected := sorted(shapes.keys() - contract.keys(), key=str):\n        raise InvalidMatchError(\n            f\"PiD checkpoint has {len(unexpected)} keys PidNet does not expect, which `load_pid_decoder` \"\n            f\"rejects too: {unexpected[:5]}{_and_more(unexpected)}\"\n        )\n\n    mismatched = [(k, shapes[k], want) for k, want in contract.items() if k != _LATENT_PROJ_KEY and shapes[k] != want]\n    if mismatched:\n        k, got, want = mismatched[0]\n        raise InvalidMatchError(\n            f\"PiD checkpoint has {len(mismatched)} weights whose shape PidNet cannot accept \"\n            f\"(e.g. {k}: {got}, expected {want}); loading it would fail with a size mismatch\"\n        )\n\n\ndef _name_components(mod: ModelOnDisk, override_fields: dict[str, Any]) -> tuple[str, ...]:\n    \"\"\"The name evidence for backbone and variant, most specific first.\n\n    NVIDIA distributes PiD checkpoints as\n    ``PiD_res2k_sr4x_official_<backbone>_distill_4step/model_ema_bf16.pth``, so the backbone and the\n    preset usually live in the *directory* name rather than the weights filename. A direct\n    single-file install stores the checkpoint as ``<uuid>/model_ema_bf16.pth`` and drops that\n    directory, which is why the install source is consulted at all: for an HF or URL install it still\n    carries NVIDIA's name.\n\n    These used to be concatenated into one string and substring-matched, which let a fixed backbone\n    precedence decide cases the name had already answered — `/flux/model_sd3.pth` matched `flux`\n    first and was registered as FLUX although the file itself says sd3. Matching component by","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/pid_decoder.py#L153-L189","documentation":"Beyond key presence, each weight's shape is compared to the contract; `lq_proj.latent_proj.0.weight` is excluded because its shape legitimately varies by backbone (it has its own dedicated checks). Any other mismatch means `load_pid_decoder` would fail with a torch size-mismatch error, so identification raises `InvalidMatchError` naming an example key, its got shape, and the expected shape.","triggerScenarios":"`_raise_if_pid_net_contract_unmet` in `from_model_on_disk` finds contract keys present with wrong shapes — e.g. a decoder trained with modified PidNet hyperparameters, or a spliced checkpoint mixing tensors from different releases.","commonSituations":"Third-party fine-tunes of PidNet with changed dims; checkpoints converted between formats incorrectly; mixing weights from different PiD releases into one file.","solutions":["Obtain the unmodified official checkpoint matching InvokeAI's `build_pid_net` legacy configuration","If it's a fine-tune with different dims, it is incompatible — request support or use the original architecture","Re-download; compare the reported example shape against the official file to confirm corruption vs intentional change"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from invokeai.backend.pid.decode import required_pid_net_shapes\nfrom invokeai.backend.pid.state_dict_utils import pid_net_shapes\nimport torch\nsd = torch.load(ckpt_path, map_location='cpu')\ncontract = required_pid_net_shapes(); shapes = pid_net_shapes(sd)\nbad = [(k, shapes[k], w) for k, w in contract.items()\n       if k != 'lq_proj.latent_proj.0.weight' and shapes[k] != w]\nif bad:\n    raise SystemExit(f'Shape mismatches, e.g. {bad[0]}')","typeGuard":"def shapes_match_pid_net(sd: dict) -> bool:\n    from invokeai.backend.pid.decode import required_pid_net_shapes\n    from invokeai.backend.pid.state_dict_utils import pid_net_shapes\n    shapes = pid_net_shapes(sd)\n    return all(shapes[k] == w for k, w in required_pid_net_shapes().items()\n               if k != 'lq_proj.latent_proj.0.weight')","tryCatchPattern":"try:\n    install_model(path)\nexcept InvalidMatchError as e:\n    if 'whose shape PidNet cannot accept' in str(e):\n        logger.error('Incompatible/fine-tuned PidNet dims: %s', e)\n    else:\n        raise","preventionTips":["Avoid third-party PidNet fine-tunes with modified dimensions","Compare reported shapes against the official release when diagnosing","Never splice weights from different PiD releases into one file"],"tags":["checkpoint","shape-mismatch","model-loader"],"backgroundTag":"checkpoint-shape-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}