{"record":{"id":"e334ad3165c78ddc","repo":"invoke-ai/InvokeAI","slug":"missing-keys-after-fp8-load-missing-10","errorCode":null,"errorMessage":"missing keys after fp8 load: {missing[:10]}","messagePattern":"missing keys after fp8 load: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/ideogram4/quantized_loading.py","lineNumber":279,"sourceCode":"    ``transformers`` model resolves itself); unexpected keys always raise.\n    \"\"\"\n    prepared: dict[str, torch.Tensor] = {}\n    for k, v in state_dict.items():\n        if v.dtype == FP8_WEIGHT_DTYPE:\n            prepared[k] = v.to(device=device)\n        elif k.endswith(FP8_SCALE_SUFFIX):\n            prepared[k] = v.to(device=device, dtype=torch.float32)\n        elif v.is_floating_point():\n            prepared[k] = v.to(device=device, dtype=dtype)\n        else:\n            prepared[k] = v.to(device=device)\n\n    missing, unexpected = model.load_state_dict(prepared, strict=False, assign=assign)\n    if unexpected:\n        raise RuntimeError(f\"unexpected keys after fp8 load: {unexpected[:10]}\")\n    if missing:\n        if strict:\n            raise RuntimeError(f\"missing keys after fp8 load: {missing[:10]}\")\n        warnings.warn(f\"missing keys after fp8 load: {missing[:10]}\", stacklevel=2)\n\n    model.to(device)\n","sourceCodeStart":261,"sourceCodeEnd":283,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/ideogram4/quantized_loading.py#L261-L283","documentation":"Raised by load_fp8_state_dict after a non-strict load_state_dict of an FP8-quantized checkpoint. When keys expected by the model are absent from the prepared state dict and strict mode is requested, it fails loudly instead of silently leaving weights randomly initialized.","triggerScenarios":"Loading an FP8 checkpoint whose key names don't match the model (renamed modules, older/newer checkpoint layout, partial checkpoint), with strict=True via _load_one_transformer or _load_text_encoder.","commonSituations":"Checkpoint saved from a different model revision, quantization script stripped keys, transformers version renamed attention/projection layers, loading a text-encoder checkpoint into a mismatched config.","solutions":["Print the full `missing` list and compare against model.state_dict().keys() to identify the naming mismatch","Re-export or re-quantize the checkpoint from the matching model version","Pass strict=False (only if the missing keys are intentionally absent, e.g. buffers computed at runtime)","Update the loading code's key-remapping/preparation step to translate old key names to new ones"],"exampleFix":"# before\nload_fp8_state_dict(model, checkpoint, strict=True)\n# after\n# fix the checkpoint keys or remap before loading\nprepared = {remap(k): v for k, v in checkpoint.items() if remap(k) in model.state_dict()}\nload_fp8_state_dict(model, prepared, strict=True)","handlingStrategy":"validation","validationCode":"ckpt_keys = set(checkpoint.keys())\nmodel_keys = set(model.state_dict().keys())\nmissing = model_keys - ckpt_keys\nif missing:\n    raise ValueError(f\"checkpoint lacks {len(missing)} model keys, e.g. {sorted(missing)[:5]}\")\nload_fp8_state_dict(model, prepared, strict=True)","typeGuard":"def is_complete_state_dict(model, sd) -> bool:\n    return set(model.state_dict().keys()).issubset(sd.keys())","tryCatchPattern":"try:\n    load_fp8_state_dict(model, prepared, strict=True)\nexcept RuntimeError as e:\n    if \"missing keys after fp8 load\" in str(e):\n        logger.error(\"checkpoint/model mismatch: %s\", e)\n        raise\n    raise","preventionTips":["Save and load checkpoints with the same model revision and transformers version","Sanity-check key sets before loading in production pipelines","Keep a key-remapping table when checkpoints change layout"],"tags":["pytorch","state-dict","checkpoint","quantization"],"backgroundTag":"state-dict-key-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}