{"record":{"id":"c08216397f078e85","repo":"Comfy-Org/ComfyUI","slug":"output-dims-output-shape-don-t-match-x-dims-x-s","errorCode":null,"errorMessage":"Output dims {output.shape} don't match x dims {x.shape} - this is no good","messagePattern":"Output dims (.+?) don't match x dims (.+?) - this is no good","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_easycache.py","lineNumber":302,"sourceCode":"                        skip_this_dim = False\n                        continue\n                    if dim_u != dim_x:\n                        if self.cut_from_start:\n                            slicing.append(slice(dim_x-dim_u, None))\n                        else:\n                            slicing.append(slice(None, dim_u))\n                    else:\n                        slicing.append(slice(None))\n                batch_slice = batch_slice + slicing\n            x[tuple(batch_slice)] += cache_diffs[uuid].to(x.device)\n        return x\n\n    def update_cache_diff(self, output: torch.Tensor, x: torch.Tensor, uuids: list[UUID], is_audio: bool = False):\n        cache_diffs = self.uuid_cache_diffs_audio if is_audio else self.uuid_cache_diffs\n        # if output dims don't match x dims, cut off excess and hope for the best (cosmos world2video)\n        if output.shape[1:] != x.shape[1:]:\n            if not self.allow_mismatch:\n                raise ValueError(f\"Output dims {output.shape} don't match x dims {x.shape} - this is no good\")\n            slicing = []\n            skip_dim = True\n            for dim_o, dim_x in zip(output.shape, x.shape):\n                if not skip_dim and dim_o != dim_x:\n                    if self.cut_from_start:\n                        slicing.append(slice(dim_x-dim_o, None))\n                    else:\n                        slicing.append(slice(None, dim_o))\n                else:\n                    slicing.append(slice(None))\n                skip_dim = False\n            x = x[tuple(slicing)]\n        diff = output - x\n        batch_offset = diff.shape[0] // len(uuids)\n        for i, uuid in enumerate(uuids):\n            cache_diffs[uuid] = diff[i*batch_offset:(i+1)*batch_offset, ...]\n\n    def has_first_cond_uuid(self, uuids: list[UUID]) -> bool:","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_easycache.py#L284-L320","documentation":"EasyCache update_cache_diff raises this when the block output tensor's trailing dims differ from the input x dims while writing the cache diff. As with apply_cache_diff, mismatched dims can be sliced (cosmos world2video), but only with allow_mismatch=True; otherwise the node treats the inconsistency as fatal rather than caching a misaligned residual.","triggerScenarios":"A model block whose output sequence length differs from its input (variable-length/video transformers); caching enabled on such a block with allow_mismatch at its default false.","commonSituations":"Enabling EasyCache on Cosmos world2video or other models with input/output length changes; resolution or frame-count changes between steps; first adoption of the cache node without configuring allow_mismatch.","solutions":["Set allow_mismatch=True on the cache node so x is sliced to the output shape before the diff is stored (use cut_from_start to control which side is kept).","If the model should have matching dims, verify resolution/frame settings are unchanged across steps.","Recompute caches from scratch after any shape-affecting change."],"exampleFix":"// before\nnode.allow_mismatch = False\n// after\nnode.allow_mismatch = True\nnode.cut_from_start = True  # keep the tail of x that matches the output","handlingStrategy":"validation","validationCode":"if output.shape[1:] != x.shape[1:] and not cache.allow_mismatch:\n    raise ValueError(\n        f'block output {output.shape} differs from input {x.shape}; '\n        'enable allow_mismatch to slice, or stop caching this block')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not attach the cache to blocks whose output length differs from input length unless allow_mismatch is on.","Keep resolution/frame settings fixed for the duration of a cached run.","Use cut_from_start to control which end of x is kept when slicing to the output shape."],"tags":["comfyui","easycache","tensor-shape","caching"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}