{"record":{"id":"66e10e35dda1e17e","repo":"Comfy-Org/ComfyUI","slug":"seedvr2-vae-cache-size-cache-size-exceeds-input","errorCode":null,"errorMessage":"SeedVR2 VAE cache size {cache_size} exceeds input length {input[i].size(2)}.","messagePattern":"SeedVR2 VAE cache size (.+?) exceeds input length (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/seedvr/vae.py","lineNumber":653,"sourceCode":"            if cache_size > input[-1].size(2) and cache is not None and len(input) == 1:\n                input[0] = torch.cat([cache, input[0]], dim=2)\n                cache = None\n            if cache_size <= input[-1].size(2):\n                memory_cache[self] = input[-1][:, :, -cache_size:].detach().contiguous()\n\n        padding = tuple(x for x in reversed(self.padding) for _ in range(2))\n        for i in range(len(input)):\n            next_cache = None\n            cache_size = 0\n            if i < len(input) - 1:\n                cache_len = cache.size(2) if cache is not None else 0\n                cache_size = get_cache_size(self, input[i].size(2) + cache_len, pad_len=0)\n            if cache_size != 0:\n                if cache_size > input[i].size(2) and cache is not None:\n                    input[i] = torch.cat([cache, input[i]], dim=2)\n                    cache = None\n                if cache_size > input[i].size(2):\n                    raise ValueError(f\"SeedVR2 VAE cache size {cache_size} exceeds input length {input[i].size(2)}.\")\n                next_cache = input[i][:, :, -cache_size:]\n\n            input[i] = self.memory_limit_conv(\n                input[i],\n                padding=padding,\n                prev_cache=cache\n            )\n\n            cache = next_cache\n\n        return input[0] if squeeze_out else input\n\ndef remove_head(tensor: Tensor, times: int = 1) -> Tensor:\n    if times == 0:\n        return tensor\n    return torch.cat(tensors=(tensor[:, :, :1], tensor[:, :, times + 1 :]), dim=2)\n\nclass Upsample3D(nn.Module):","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/seedvr/vae.py#L635-L671","documentation":"In basic (non-memory-limited) forward with multiple input slices, the conv keeps an overlap cache between slices. get_cache_size computes the required overlap from kernel/stride/dilation; if that cache is bigger than the current input slice (even after prepending the previous cache), the loop cannot proceed and raises. The cause is slices smaller than the conv's receptive-field overlap — typically from a caller that chunked the input too finely.","triggerScenarios":"Calling the multi-slice conv forward with input chunks shorter than dilated_kernel - stride + 1; extremely short video inputs split across slices; upstream code splitting temporal dimension into 1-2 frame chunks for stride-2 temporal convs.","commonSituations":"Processing 1-2 frame clips through a video VAE with temporal kernel 3; custom batchers that split by arbitrary frame counts; trimming videos to very short lengths.","solutions":["Feed larger chunks: at minimum dilated_kernel_size frames per slice in the temporal dimension.","Avoid slicing for short inputs — pass the whole clip in one slice.","Pad the temporal dimension (repeat first/last frame) to reach a valid length before the conv.","Audit upstream code that performs manual temporal chunking and align chunk size to conv kernel."],"exampleFix":"# before\nchunks = torch.split(vid, 2, dim=2)  # kernel 3 -> cache exceeds slice\n# after\nchunks = torch.split(vid, 8, dim=2)  # chunk >= dilated kernel size","handlingStrategy":"validation","validationCode":"def validate_chunks(chunks, conv):\n    dilated = conv.dilation[0] * (conv.kernel_size[0] - 1) + 1\n    min_len = dilated - conv.stride[0] + 1\n    for c in chunks:\n        if c.size(2) < min_len:\n            raise ValueError(f\"chunk len {c.size(2)} < minimum {min_len} for this conv\")\n    return chunks","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chunk temporal inputs in sizes of at least the dilated kernel length.","Do not slice very short clips at all.","Pad short clips by repeating boundary frames to a valid length."],"tags":["seedvr2","vae","slicing","convolution","temporal"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}