{"record":{"id":"943cce831da6d8ae","repo":"invoke-ai/InvokeAI","slug":"krea-2-conditioning-mask-shape-tuple-mask-shape","errorCode":null,"errorMessage":"Krea-2 conditioning mask shape {tuple(mask.shape)} does not match prompt embedding shape {tuple(embeds.shape[:2])}.","messagePattern":"Krea-2 conditioning mask shape (.+?) does not match prompt embedding shape (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/krea2_denoise.py","lineNumber":164,"sourceCode":"    ) -> Krea2RegionalPromptingExtension:\n        conditioning_fields = (\n            [conditioning_field] if isinstance(conditioning_field, Krea2ConditioningField) else conditioning_field\n        )\n        if not conditioning_fields:\n            raise ValueError(\"At least one Krea-2 conditioning is required.\")\n\n        text_conditionings: list[Krea2TextConditioning] = []\n        for field in conditioning_fields:\n            cond_data = context.conditioning.load(field.conditioning_name)\n            assert len(cond_data.conditionings) == 1\n            conditioning = cond_data.conditionings[0]\n            assert isinstance(conditioning, Krea2ConditioningInfo)\n            conditioning = conditioning.to(dtype=dtype, device=device)\n            embeds = conditioning.prompt_embeds\n            if conditioning.prompt_embeds_mask is not None:\n                mask = conditioning.prompt_embeds_mask.to(device=device, dtype=torch.bool)\n                if mask.shape != embeds.shape[:2]:\n                    raise ValueError(\n                        f\"Krea-2 conditioning mask shape {tuple(mask.shape)} does not match \"\n                        f\"prompt embedding shape {tuple(embeds.shape[:2])}.\"\n                    )\n                valid_token_counts = mask.sum(dim=1)\n                if not torch.equal(valid_token_counts, valid_token_counts[:1].expand_as(valid_token_counts)):\n                    raise ValueError(\"All Krea-2 conditioning batch items must have the same valid token count.\")\n                embeds = torch.stack(\n                    [batch_embeds[batch_mask] for batch_embeds, batch_mask in zip(embeds, mask, strict=True)]\n                )\n            regional_mask = None\n            if field.mask is not None:\n                mask = context.tensors.load(field.mask.tensor_name)\n                regional_mask = Krea2RegionalPromptingExtension.preprocess_regional_prompt_mask(\n                    mask=mask,\n                    grid_height=grid_height,\n                    grid_width=grid_width,\n                    dtype=dtype,\n                    device=device,","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/krea2_denoise.py#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: mask with wrong seq_len\nKrea2ConditioningInfo(prompt_embeds=embeds, prompt_embeds_mask=mask[:, :embeds.shape[1]-1])\n// after: mask matches embeds' (batch, seq) dims\nassert mask.shape == embeds.shape[:2]\nKrea2ConditioningInfo(prompt_embeds=embeds, prompt_embeds_mask=mask)","handlingStrategy":"validation","validationCode":"if cond.prompt_embeds_mask is not None:\n    assert cond.prompt_embeds_mask.shape == cond.prompt_embeds.shape[:2], \\\n        f\"mask {tuple(cond.prompt_embeds_mask.shape)} != embeds {tuple(cond.prompt_embeds.shape[:2])}\"","typeGuard":"def has_consistent_mask(cond: Krea2ConditioningInfo) -> bool:\n    if cond.prompt_embeds_mask is None:\n        return True\n    return tuple(cond.prompt_embeds_mask.shape) == tuple(cond.prompt_embeds.shape[:2])","tryCatchPattern":"try:\n    out = invoke_krea2_denoise(...)\nexcept ValueError as e:\n    if \"mask shape\" in str(e) and \"prompt embedding shape\" in str(e):\n        cond = regenerate_conditioning_with_current_text_encoder()\n        out = invoke_krea2_denoise(...)\n    else:\n        raise","preventionTips":["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."],"tags":["invokeai","krea2","shape-mismatch","validation"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}