{"record":{"id":"173ac887ff7f954f","repo":"Comfy-Org/ComfyUI","slug":"seedvr2preprocess-failed-to-pad-video-length-to-4n","errorCode":null,"errorMessage":"SeedVR2Preprocess failed to pad video length to 4n+1; got {videos.size(1)} frames.","messagePattern":"SeedVR2Preprocess failed to pad video length to 4n\\+1; got (.+?) frames\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_seedvr.py","lineNumber":89,"sourceCode":"\n    padding = (0, pad_width, 0, pad_height)\n    return torch.nn.functional.pad(image, padding, mode='constant', value=0.0)\n\ndef cut_videos(videos):\n    t = videos.size(1)\n    if t < 1:\n        raise ValueError(\"SeedVR2Preprocess expected at least one frame.\")\n    if t == 1:\n        return videos\n    if t <= 4:\n        padding = videos[:, -1:].repeat(1, 4 - t + 1, 1, 1, 1)\n        return torch.cat([videos, padding], dim=1)\n    if (t - 1) % 4 == 0:\n        return videos\n    padding = videos[:, -1:].repeat(1, 4 - ((t - 1) % 4), 1, 1, 1)\n    videos = torch.cat([videos, padding], dim=1)\n    if (videos.size(1) - 1) % 4 != 0:\n        raise ValueError(f\"SeedVR2Preprocess failed to pad video length to 4n+1; got {videos.size(1)} frames.\")\n    return videos\n\ndef _seedvr2_input_shorter_edge(images, node_name):\n    if images.dim() == 4:\n        return min(images.shape[1], images.shape[2])\n    if images.dim() == 5:\n        return min(images.shape[2], images.shape[3])\n    raise ValueError(\n        f\"{node_name}: expected 4-D or 5-D IMAGE tensor, \"\n        f\"got shape {tuple(images.shape)}\"\n    )\n\n\ndef _seedvr2_pad(images, upscaled_shorter_edge, node_name):\n    if upscaled_shorter_edge < 2:\n        raise ValueError(\n            f\"{node_name}: input shorter edge must be at least 2 pixels; \"\n            f\"got {upscaled_shorter_edge}.\"","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_seedvr.py#L71-L107","documentation":"cut_videos pads the temporal dimension so the frame count satisfies t = 4n+1 (the SeedVR2 causal VAE layout). After concatenating the computed padding, it re-verifies the invariant; this error fires only if that post-condition somehow fails. In practice the arithmetic (padding by 4 - ((t-1) % 4)) always restores 4n+1, so this is a defensive assertion that should be unreachable.","triggerScenarios":"Requires (t - 1) % 4 != 0 after appending exactly 4 - ((t-1) % 4) copies of the last frame — mathematically impossible for integer t >= 5. Could only fire from a corrupted torch build or a mutation of videos between the cat and the check.","commonSituations":"Not seen in normal use; would indicate a non-standard torch environment or a monkey-patched tensor. Report as a bug against ComfyUI if it ever appears.","solutions":["Treat occurrence as a bug: report the ComfyUI version, torch version, and input frame count to the maintainers.","Verify torch is a standard release (pip check torch) and no custom tensor subclass or patching is active.","As a workaround, pre-pad the video yourself to a 4n+1 frame count and bypass cut_videos."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    videos = cut_videos(videos)\nexcept ValueError as e:\n    if 'failed to pad video length' in str(e):\n        raise RuntimeError('SeedVR2 padding invariant broken; report as a bug with torch version') from e\n    raise","preventionTips":["Keep torch at a standard ComfyUI-supported release.","Avoid monkey-patching tensor ops in custom nodes.","Report occurrences with the exact input frame count."],"tags":["seedvr","video","assertion","unreachable"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}