Comfy-Org/ComfyUI · error · ValueError
Cached dims {self.uuid_cache_diffs[uuid].shape} don't match
Error message
Cached dims {self.uuid_cache_diffs[uuid].shape} don't match x dims {x.shape} - this is no good What it means
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.
Source
Thrown at comfy_extras/nodes_easycache.py:279
if clone:
return to_return.clone()
return to_return
def can_apply_cache_diff(self, uuids: list[UUID]) -> bool:
return all(uuid in self.uuid_cache_diffs for uuid in uuids)
def apply_cache_diff(self, x: torch.Tensor, uuids: list[UUID], is_audio: bool = False):
if self.first_cond_uuid in uuids and not is_audio:
self.total_steps_skipped += 1
cache_diffs = self.uuid_cache_diffs_audio if is_audio else self.uuid_cache_diffs
batch_offset = x.shape[0] // len(uuids)
for i, uuid in enumerate(uuids):
# slice out only what is relevant to this cond
batch_slice = [slice(i*batch_offset,(i+1)*batch_offset)]
# if cached dims don't match x dims, cut off excess and hope for the best (cosmos world2video)
if x.shape[1:] != cache_diffs[uuid].shape[1:]:
if not self.allow_mismatch:
raise ValueError(f"Cached dims {self.uuid_cache_diffs[uuid].shape} don't match x dims {x.shape} - this is no good")
slicing = []
skip_this_dim = True
for dim_u, dim_x in zip(cache_diffs[uuid].shape, x.shape):
if skip_this_dim:
skip_this_dim = False
continue
if dim_u != dim_x:
if self.cut_from_start:
slicing.append(slice(dim_x-dim_u, None))
else:
slicing.append(slice(None, dim_u))
else:
slicing.append(slice(None))
batch_slice = batch_slice + slicing
x[tuple(batch_slice)] += cache_diffs[uuid].to(x.device)
return x
def update_cache_diff(self, output: torch.Tensor, x: torch.Tensor, uuids: list[UUID], is_audio: bool = False):View on GitHub (pinned to 1c6d8d45b3)
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.
Example fix
// before node.allow_mismatch = False // after (accept trimmed application, cosmos world2video style) node.allow_mismatch = True node.cut_from_start = False # trim from the end of x
Defensive patterns
Strategy: validation
Validate before calling
if x.shape[1:] != cache.uuid_cache_diffs[uuid].shape[1:]:
if not cache.allow_mismatch:
raise ValueError(
f'shape drift detected for {uuid}: cached {cache.uuid_cache_diffs[uuid].shape} vs x {x.shape}; '
'enable allow_mismatch or reset the cache') Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Output dims {output.shape} don't match x dims {x.shape} - th
- Expected 4D image tensor, got shape {tuple(images.shape)}
- Expected 4D image tensor, got {type(item).__name__} shape {g
- INVALID_TAG_FILTER
- INVALID_QUERY
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/8dce87bc2a3d5b74.
Report an issue: GitHub.