invoke-ai/InvokeAI · error · RuntimeError
Checkpoint contains {len(load_result.unexpected_keys)} unexp
Error message
Checkpoint contains {len(load_result.unexpected_keys)} unexpected keys. This may indicate a corrupted or incompatible checkpoint. First 5 unexpected keys: {load_result.unexpected_keys[:5]} What it means
When loading an Anima model from a single-file checkpoint, the loader calls model.load_state_dict(sd, assign=True, strict=False) and inspects load_result. Any unexpected keys — weights in the file that do not correspond to any parameter in the constructed model — indicate the checkpoint does not match the expected Anima architecture, so the loader raises RuntimeError instead of silently dropping weights.
Source
Thrown at invokeai/backend/model_manager/load/model_loaders/anima.py:179
with accelerate.init_empty_weights():
model = AnimaTransformer(**ANIMA_TRANSFORMER_CONFIG)
# Determine safe dtype
target_device = TorchDevice.choose_torch_device()
model_dtype = TorchDevice.choose_anima_inference_dtype(target_device)
# Handle memory management
new_sd_size = sum(ten.nelement() * model_dtype.itemsize for ten in sd.values())
self._ram_cache.make_room(new_sd_size)
# Convert to target dtype (skip non-float tensors like embedding indices)
for k in sd.keys():
if sd[k].is_floating_point():
sd[k] = sd[k].to(model_dtype)
load_result = model.load_state_dict(sd, assign=True, strict=False)
if load_result.unexpected_keys:
raise RuntimeError(
f"Checkpoint contains {len(load_result.unexpected_keys)} unexpected keys. "
f"This may indicate a corrupted or incompatible checkpoint. "
f"First 5 unexpected keys: {load_result.unexpected_keys[:5]}"
)
if load_result.missing_keys:
logger.warning(
f"Checkpoint is missing {len(load_result.missing_keys)} keys "
f"(expected for inv_freq buffers). First 5: {load_result.missing_keys[:5]}"
)
# Without this the `fp8_storage` toggle is shown for Anima models but does nothing. The
# state dict was cast to a single `model_dtype` above, so the layerwise cast has one
# unambiguous compute dtype to restore to. AnimaTransformer is a plain nn.Module, so this
# takes the hook-based path in `_apply_fp8_to_nn_module`.
model = self._apply_fp8_layerwise_casting(model, config, SubModelType.Transformer)
return model
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Re-download the official Anima single-file checkpoint from the original source.
- Confirm the checkpoint is actually Anima and the right revision; if it is another family, import it under the correct model type.
- Inspect the printed unexpected keys and strip/rename them if the checkpoint is a known-compatible variant.
Example fix
// before: trusting any .safetensors as Anima
model = loader._load_from_singlefile(path, dtype)
// after: sanity-check keys against expected names first
from safetensors import safe_open
with safe_open(path, framework="pt") as f:
keys = list(f.keys())
if not any(k.startswith("expected_prefix") for k in keys):
raise RuntimeError("Checkpoint does not look like an Anima single-file model")
model = loader._load_from_singlefile(path, dtype) Defensive patterns
Strategy: validation
Validate before calling
from safetensors import safe_open
with safe_open(checkpoint_path, framework="pt") as f:
keys = list(f.keys())
print("first keys:", keys[:5]) # confirm prefixes match the Anima architecture before loading Type guard
def looks_like_anima_checkpoint(keys: list[str]) -> bool:
return any(k.startswith("transformer") or k.startswith("model") for k in keys) Try / catch
try:
model = loader._load_from_singlefile(path, dtype)
except RuntimeError as e:
if "unexpected keys" in str(e):
raise RuntimeError(f"Checkpoint {path} is not a compatible Anima file; re-download it") from e
raise Prevention
- Download single-file checkpoints only from trusted official sources
- Verify file hashes/checksums after download
- Do not rename keys or hand-modify checkpoints
When it happens
Trigger: _load_from_singlefile is given a single-file checkpoint whose key names/prefixes differ from the instantiated Anima model (wrong variant, renamed layers, or an entirely different architecture saved in a compatible-looking file).
Common situations: Downloading a renamed or community-modified Anima checkpoint; using a checkpoint from a different model family saved as single-file; a corrupted or partially updated checkpoint.
Related errors
- Unexpected key: {k}
- missing keys after fp8 load: {missing[:10]}
- unable to determine base type from state dict
- unable to determine model variant from state dict
- state dict does not look like a main model
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/2620f9505210ce80.
Report an issue: GitHub.