invoke-ai/InvokeAI · error · ValueError
Malformed Krea-2 LoRA: layer '{layer_key}' has lora_A.weight
Error message
Malformed Krea-2 LoRA: layer '{layer_key}' has lora_A.weight but no matching lora_B.weight. The LoRA file is incomplete or corrupt. What it means
PEFT-format Krea-2 LoRA layers store the low-rank factorization as lora_A.weight plus lora_B.weight. This error means a layer has lora_A.weight but the required matching lora_B.weight is missing, so the pair cannot be converted to lora_down/lora_up format. The file is treated as incomplete or corrupt.
Source
Thrown at invokeai/backend/patches/lora_conversions/krea2_lora_conversion_utils.py:320
# the mixed-layout adapter explicitly instead.
if final_key in layers:
raise ValueError(
f"Krea-2 LoRA has conflicting layers that normalize to the same target '{final_key}' "
"(e.g. both a 'transformer.' and a 'diffusion_model.' alias for one logical layer). "
"This mixed layout is unsupported - refusing to silently drop one of the layers."
)
layers[final_key] = any_lora_layer_from_state_dict(values)
return ModelPatchRaw(layers=layers)
def _get_lora_layer_values(
layer_key: str, layer_dict: dict[str, torch.Tensor], alpha: float | None
) -> dict[str, torch.Tensor]:
"""Convert PEFT (lora_A/lora_B) layer values to internal (lora_down/lora_up) format."""
if "lora_A.weight" in layer_dict:
if "lora_B.weight" not in layer_dict:
raise ValueError(
f"Malformed Krea-2 LoRA: layer '{layer_key}' has lora_A.weight but no matching lora_B.weight. "
"The LoRA file is incomplete or corrupt."
)
values = {
"lora_down.weight": layer_dict["lora_A.weight"],
"lora_up.weight": layer_dict["lora_B.weight"],
}
if "dora_scale" in layer_dict:
values["dora_scale"] = layer_dict["dora_scale"]
if "alpha" in layer_dict:
values["alpha"] = layer_dict["alpha"]
if alpha is not None:
values["alpha"] = torch.tensor(alpha)
return values
return layer_dict
# Maps each recognized weight-key suffix to the canonical value-key used downstream. The PEFT/diffusers DoRAView on GitHub (pinned to 0b6a024f2f)
Solutions
- Re-download or re-export the LoRA file completely and verify both lora_A.weight and lora_B.weight exist for every layer.
- Check the file's keys and rename any misspelled lora_B tensors (e.g. 'lora_b.weight') to the expected 'lora_B.weight'.
- If the source is a training run, finish saving the adapter (PEFT writes A and B together) and retry.
Example fix
// before (corrupt layer) 'transformer.blocks.0.attn.qkv.lora_A.weight': a // after (complete PEFT pair) 'transformer.blocks.0.attn.qkv.lora_A.weight': a 'transformer.blocks.0.attn.qkv.lora_B.weight': b
Defensive patterns
Strategy: validation
Validate before calling
layer_keys = {k.rsplit('.', 2)[0] for k in state_dict if '.lora_A.weight' in k or '.lora_B.weight' in k}
for lk in layer_keys:
has_a = f'{lk}.lora_A.weight' in state_dict
has_b = f'{lk}.lora_B.weight' in state_dict
if has_a != has_b:
raise ValueError(f'incomplete PEFT pair at {lk}') Type guard
def is_complete_peft_layer(layer_dict: dict[str, object]) -> bool:
return ('lora_A.weight' in layer_dict) == ('lora_B.weight' in layer_dict) Try / catch
try:
model = lora_model_from_krea2_state_dict(state_dict)
except ValueError as e:
if 'lora_A.weight but no matching lora_B.weight' in str(e):
logger.error('Corrupt/incomplete LoRA file: %s', e)
# re-download or repair the file before retrying
else:
raise Prevention
- Verify checksums/file sizes after downloading LoRA files.
- Check both lora_A.weight and lora_B.weight exist for every PEFT layer before loading.
- Never hand-trim state dicts without keeping A/B pairs together.
When it happens
Trigger: lora_model_from_krea2_state_dict -> _get_lora_layer_values with a layer_dict containing 'lora_A.weight' but not 'lora_B.weight' for a given layer_key (e.g. a truncated download or a partially saved PEFT adapter).
Common situations: Interrupted downloads or incomplete checkpoint saves; PEFT adapters where only rank-A tensors were exported; manual slicing of state dicts that dropped lora_B tensors; mixed-format files where the B tensors use a different key spelling.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- model does not match Krea-2 LoRA heuristics (no complete lor
- Krea-2 LoRA has an incomplete lora_A/B (or lora_down/up) wei
- model does not look like a Krea-2 LoRA
- Krea-2 LoRA has conflicting layers that normalize to the sam
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/eabbbf08a3eac0c4.
Report an issue: GitHub.