invoke-ai/InvokeAI · error · ValueError
Krea-2 conditioning mask shape
Error message
Krea-2 conditioning mask shape {tuple(mask.shape)} does not match prompt embedding shape {tuple(embeds.shape[:2])}. What it means
Each Krea-2 conditioning carries prompt embeddings and a boolean attention mask. The mask must have shape (batch, seq_len), i.e. exactly the first two dims of the prompt embedding tensor. This ValueError fires when the loaded mask shape is inconsistent with its embeddings, indicating corrupted or mismatched conditioning data.
Solutions
- Regenerate the conditioning with the current Krea-2 text encoder instead of reusing cached/saved conditioning data.
- If constructing Krea2ConditioningInfo manually, slice or pad prompt_embeds_mask so its shape equals prompt_embeds.shape[:2].
- Verify the text-encoder/model version that produced the conditioning matches the one used at denoise time.
Example fix
// before: mask with wrong seq_len Krea2ConditioningInfo(prompt_embeds=embeds, prompt_embeds_mask=mask[:, :embeds.shape[1]-1]) // after: mask matches embeds' (batch, seq) dims assert mask.shape == embeds.shape[:2] Krea2ConditioningInfo(prompt_embeds=embeds, prompt_embeds_mask=mask)
Defensive patterns
Strategy: validation
Validate before calling
if cond.prompt_embeds_mask is not None:
assert cond.prompt_embeds_mask.shape == cond.prompt_embeds.shape[:2], \
f"mask {tuple(cond.prompt_embeds_mask.shape)} != embeds {tuple(cond.prompt_embeds.shape[:2])}" Type guard
def has_consistent_mask(cond: Krea2ConditioningInfo) -> bool:
if cond.prompt_embeds_mask is None:
return True
return tuple(cond.prompt_embeds_mask.shape) == tuple(cond.prompt_embeds.shape[:2]) Try / catch
try:
out = invoke_krea2_denoise(...)
except ValueError as e:
if "mask shape" in str(e) and "prompt embedding shape" in str(e):
cond = regenerate_conditioning_with_current_text_encoder()
out = invoke_krea2_denoise(...)
else:
raise Prevention
- Regenerate cached conditioning after text-encoder or InvokeAI version upgrades.
- Never construct Krea2ConditioningInfo without asserting mask/embed shape agreement.
- Keep the tokenizer max_length consistent between mask creation and embedding creation.
When it happens
Trigger: Loading a Krea2ConditioningInfo via context.conditioning.load where prompt_embeds_mask.shape != prompt_embeds.shape[:2] — e.g. a conditioning object saved with embeddings from one tokenizer config and a mask from another, or a manually constructed Krea2ConditioningInfo with mismatched tensors.
Common situations: Custom nodes constructing Krea2ConditioningInfo by hand with wrong mask dimensions; conditioning data persisted by an older InvokeAI version whose embedding width/token count changed after a model or library update; truncated/corrupted saved conditioning files.
Understand the failure class
Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.
Related errors
- All Krea-2 conditioning batch items must have the same…
- At least one Krea-2 conditioning is required.
- cfg_scale list has values but the model is configured for…
- cfg_scale values must be finite.
- denoising_start must be less than denoising_end.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/943cce831da6d8ae.
Report an issue: GitHub.
Appendix: source
Thrown at invokeai/app/invocations/krea2_denoise.py:164
) -> Krea2RegionalPromptingExtension:
conditioning_fields = (
[conditioning_field] if isinstance(conditioning_field, Krea2ConditioningField) else conditioning_field
)
if not conditioning_fields:
raise ValueError("At least one Krea-2 conditioning is required.")
text_conditionings: list[Krea2TextConditioning] = []
for field in conditioning_fields:
cond_data = context.conditioning.load(field.conditioning_name)
assert len(cond_data.conditionings) == 1
conditioning = cond_data.conditionings[0]
assert isinstance(conditioning, Krea2ConditioningInfo)
conditioning = conditioning.to(dtype=dtype, device=device)
embeds = conditioning.prompt_embeds
if conditioning.prompt_embeds_mask is not None:
mask = conditioning.prompt_embeds_mask.to(device=device, dtype=torch.bool)
if mask.shape != embeds.shape[:2]:
raise ValueError(
f"Krea-2 conditioning mask shape {tuple(mask.shape)} does not match "
f"prompt embedding shape {tuple(embeds.shape[:2])}."
)
valid_token_counts = mask.sum(dim=1)
if not torch.equal(valid_token_counts, valid_token_counts[:1].expand_as(valid_token_counts)):
raise ValueError("All Krea-2 conditioning batch items must have the same valid token count.")
embeds = torch.stack(
[batch_embeds[batch_mask] for batch_embeds, batch_mask in zip(embeds, mask, strict=True)]
)
regional_mask = None
if field.mask is not None:
mask = context.tensors.load(field.mask.tensor_name)
regional_mask = Krea2RegionalPromptingExtension.preprocess_regional_prompt_mask(
mask=mask,
grid_height=grid_height,
grid_width=grid_width,
dtype=dtype,
device=device,View on GitHub (pinned to 0b6a024f2f)