{"record":{"id":"8dce87bc2a3d5b74","repo":"Comfy-Org/ComfyUI","slug":"cached-dims-self-uuid-cache-diffs-uuid-shape-do","errorCode":null,"errorMessage":"Cached dims {self.uuid_cache_diffs[uuid].shape} don't match x dims {x.shape} - this is no good","messagePattern":"Cached 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":279,"sourceCode":"        if clone:\n            return to_return.clone()\n        return to_return\n\n    def can_apply_cache_diff(self, uuids: list[UUID]) -> bool:\n        return all(uuid in self.uuid_cache_diffs for uuid in uuids)\n\n    def apply_cache_diff(self, x: torch.Tensor, uuids: list[UUID], is_audio: bool = False):\n        if self.first_cond_uuid in uuids and not is_audio:\n            self.total_steps_skipped += 1\n        cache_diffs = self.uuid_cache_diffs_audio if is_audio else self.uuid_cache_diffs\n        batch_offset = x.shape[0] // len(uuids)\n        for i, uuid in enumerate(uuids):\n            # slice out only what is relevant to this cond\n            batch_slice = [slice(i*batch_offset,(i+1)*batch_offset)]\n            # if cached dims don't match x dims, cut off excess and hope for the best (cosmos world2video)\n            if x.shape[1:] != cache_diffs[uuid].shape[1:]:\n                if not self.allow_mismatch:\n                    raise ValueError(f\"Cached dims {self.uuid_cache_diffs[uuid].shape} don't match x dims {x.shape} - this is no good\")\n                slicing = []\n                skip_this_dim = True\n                for dim_u, dim_x in zip(cache_diffs[uuid].shape, x.shape):\n                    if skip_this_dim:\n                        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):","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_easycache.py#L261-L297","documentation":"EasyCache apply_cache_diff raises this when a cached residual (cache diff) stored for a cond UUID has trailing dims that no longer match the incoming tensor x. Normally the node can slice off excess dims ('cosmos world2video' case), but only when the allow_mismatch option is enabled; otherwise a dim mismatch is fatal because adding misaligned tensors is numerically wrong.","triggerScenarios":"Applying cached attention/cond diffs to an x whose sequence length (or other non-batch dim) differs from when the cache was written — e.g. changing resolution, frame count, or conditioning length mid-run while reusing cache entries keyed by UUID; typical with Cosmos world2video-style workloads.","commonSituations":"Changing video resolution/frame count between cached and non-cached passes; stale caches surviving UUID reuse after a workflow edit; mixing audio and non-audio cond streams with mismatched shapes; allow_mismatch left at default false.","solutions":["Enable the node's allow_mismatch option so excess dims are sliced off (the documented cosmos world2video path; pair with cut_from_start to choose which side is trimmed).","If shapes should genuinely match, find what changed x's dims (resolution/frame count) between cache write and apply, and revert it.","Clear/reset the cache (new UUIDs / re-run from step 0) so diffs are recomputed for the current shape."],"exampleFix":"// before\nnode.allow_mismatch = False\n// after (accept trimmed application, cosmos world2video style)\nnode.allow_mismatch = True\nnode.cut_from_start = False  # trim from the end of x","handlingStrategy":"validation","validationCode":"if x.shape[1:] != cache.uuid_cache_diffs[uuid].shape[1:]:\n    if not cache.allow_mismatch:\n        raise ValueError(\n            f'shape drift detected for {uuid}: cached {cache.uuid_cache_diffs[uuid].shape} vs x {x.shape}; '\n            'enable allow_mismatch or reset the cache')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable allow_mismatch (and set cut_from_start deliberately) when caching models whose sequence length changes, e.g. Cosmos world2video.","Never change resolution/frame count between cached and applied passes — reset caches after any such change.","Watch the total_steps_skipped counter as a canary for cache misalignment."],"tags":["comfyui","easycache","tensor-shape","caching"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}