invoke-ai/InvokeAI · error · RuntimeError
{source} is missing {key} after prefix strip and key convers
Error message
{source} is missing {key} after prefix strip and key conversion What it means
_build_wan_transformer_config probes specific tensor keys (starting with patch_embedding.weight) to infer architecture parameters. If, after stripping diffusers prefixes and converting key names, a required tensor is absent from the state dict, the local `require` closure raises RuntimeError naming the missing key.
Source
Thrown at invokeai/backend/model_manager/load/model_loaders/wan.py:342
release is described by its own weights rather than by a hard-coded table of
known repos.
``source`` only flavours the error messages.
"""
num_layers = 0
for key in sd.keys():
if isinstance(key, str) and key.startswith("blocks."):
parts = key.split(".")
if len(parts) >= 2:
try:
num_layers = max(num_layers, int(parts[1]) + 1)
except ValueError:
pass
def require(key: str) -> tuple[int, ...]:
tensor = sd.get(key)
if tensor is None:
raise RuntimeError(f"{source} is missing {key} after prefix strip and key conversion")
return _tensor_shape(tensor)
# Patch embedding gives us in_channels (16/36=A14B, 48=TI2V-5B) and inner dim.
patch_shape = require("patch_embedding.weight")
inner_dim = patch_shape[0]
in_channels = patch_shape[1]
# Wan uses head_dim=128 throughout the family; num_heads = inner_dim / 128.
attention_head_dim = 128
num_attention_heads = inner_dim // attention_head_dim
ffn_dim = require("blocks.0.ffn.net.0.proj.weight")[0]
text_w = sd.get("condition_embedder.text_embedder.linear_1.weight")
text_dim = _tensor_shape(text_w)[1] if text_w is not None else 4096
# out_channels is read from proj_out.weight directly rather than assumed
# equal to in_channels: I2V-A14B has in_channels=36 (16 noise + 16View on GitHub (pinned to 0b6a024f2f)
Solutions
- Verify the file actually contains Wan transformer weights (not a VAE/text-encoder or unrelated model).
- Re-download the checkpoint; a truncated file can lose early tensors.
- Compare the file's key names against expected Wan keys; if naming is nonstandard, use a repackaged diffusers-compatible checkpoint.
- Update InvokeAI so the latest prefix-strip/key-conversion rules apply.
Example fix
// before: wrong file registered as transformer path = "wan_vae.safetensors" # no patch_embedding.weight // after path = "wan2.1_t2v_1.3b_transformer.safetensors"
Defensive patterns
Strategy: validation
Validate before calling
from safetensors import safe_open
def validate_has_patch_embedding(path):
with safe_open(path, framework='pt') as f:
keys = set(f.keys())
if not any('patch_embedding.weight' in k for k in keys):
raise ValueError(f"{path} is not a Wan transformer checkpoint (no patch_embedding.weight)") Try / catch
try:
model = loader.load_model(config, SubModelType.Transformer)
except RuntimeError as e:
if 'after prefix strip and key conversion' in str(e):
verify_file_is_wan_transformer(config.path) # correct the record or re-download
else:
raise Prevention
- Ensure model records point at transformer checkpoints, not VAE/T5 files.
- Re-download files whose size differs from the published size.
- Prefer diffusers-standard key naming repackaging for community checkpoints.
- Update InvokeAI for the newest key-mapping rules.
When it happens
Trigger: Loading a single-file Wan checkpoint whose state dict lacks expected keys like patch_embedding.weight — e.g., a non-transformer file, a checkpoint with entirely different naming conventions, or a GGUF/compressed file misdetected as a standard checkpoint.
Common situations: Pointing a Wan checkpoint model record at a VAE or T5 encoder file by mistake; exotic community repackaging with unfamiliar key layout; corrupt or partially written safetensors file.
Related errors
- {source} is missing model parameters: {sorted(incompatible_k
- {source} has {len(unexpected)} weights that WanTransformer3D
- Expected Main_Checkpoint_Wan_Config, got {type(config).__nam
- Only the Transformer submodel is available from a single-fil
- PiD checkpoint has unexpected keys not present in PidNet: {u
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/54ffe594351cc634.
Report an issue: GitHub.