{"record":{"id":"54df064d16015d68","repo":"Comfy-Org/ComfyUI","slug":"seedvr2-patch-input-temporal-size-must-satisfy-t","errorCode":null,"errorMessage":"SeedVR2 patch input temporal size must satisfy T % {t} == 1, got {vid.size(2)}.","messagePattern":"SeedVR2 patch input temporal size must satisfy T % (.+?) == 1, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/seedvr/model.py","lineNumber":951,"sourceCode":"        self,\n        in_channels: int,\n        patch_size: Union[int, Tuple[int, int, int]],\n        dim: int,\n        device, dtype, operations\n    ):\n        super().__init__()\n        t, h, w = _triple(patch_size)\n        self.patch_size = t, h, w\n        self.proj = operations.Linear(in_channels * t * h * w, dim, device=device, dtype=dtype)\n\n    def forward(\n        self,\n        vid: torch.Tensor,\n    ) -> torch.Tensor:\n        t, h, w = self.patch_size\n        if t > 1:\n            if vid.size(2) % t != 1:\n                raise ValueError(\n                    f\"SeedVR2 patch input temporal size must satisfy T % {t} == 1, got {vid.size(2)}.\"\n                )\n            vid = torch.cat([vid[:, :, :1]] * (t - 1) + [vid], dim=2)\n        b, c, Tt, Hh, Ww = vid.shape\n        vid = vid.view(b, c, Tt // t, t, Hh // h, h, Ww // w, w).permute(0, 2, 4, 6, 3, 5, 7, 1).reshape(b, Tt // t, Hh // h, Ww // w, t * h * w * c)\n        vid = self.proj(vid)\n        return vid\n\nclass NaPatchIn(PatchIn):\n    def forward(\n        self,\n        vid: torch.Tensor,  # l c\n        vid_shape: torch.LongTensor,\n        cache: Optional[Cache] = None,\n    ) -> torch.Tensor:\n        if cache is None:\n            cache = Cache(disable=True)\n        cache = cache.namespace(\"patch\")","sourceCodeStart":933,"sourceCodeEnd":969,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/seedvr/model.py#L933-L969","documentation":"SeedVR2's PatchIn keeps the very first frame unpatched and patches groups of t consecutive frames (it duplicates frame 0 t-1 times before reshaping), so the input temporal length T must satisfy T % t == 1. A video whose frame count does not leave remainder 1 modulo the temporal patch size cannot be reshaped, hence the ValueError. This is an input-length contract on the video latent frames.","triggerScenarios":"Feeding SeedVR2 a video latent with a frame count that is a multiple of t (or arbitrary) — e.g. T=16 frames with temporal patch size 2 (16 % 2 == 0, not 1). Common with arbitrary frame counts produced by trimming, looping, or frame-interpolation preprocessing.","commonSituations":"Loading a video with an even frame count into a model with temporal patch size 2; trimming frames to a round number like 32; frame-count arithmetic in a preprocessing pipeline that ignores the model's T % t == 1 contract.","solutions":["Adjust the frame count so T % t == 1 (for t=2 that means an odd frame count: 1, 3, 5, ...).","Drop or duplicate trailing frames in preprocessing to reach a valid length, e.g. keep the first (T // t) * t + 1 frames.","Check the model config's patch_size triple to learn t and validate before loading the video.","If frames come from a VAE encode of raw video, fix the count before encoding so latent frames align."],"exampleFix":"# before\nvid = load_video(path)  # T=16, t=2 -> raises\n# after\nt = 2\nT_valid = (vid.size(2) // t) * t + 1  # 17 -> still even split issue; instead trim to odd\nvid = vid[:, :, :T_valid] if T_valid <= vid.size(2) else torch.cat([vid, vid[:, :, -1:].repeat(1, 1, T_valid - vid.size(2), 1, 1)], dim=2)","handlingStrategy":"validation","validationCode":"def validate_seedvr2_temporal(vid, patch_t):\n    T = vid.size(2)\n    if T % patch_t != 1:\n        target = (T // patch_t) * patch_t + 1\n        raise ValueError(f\"frame count {T} invalid for patch_t={patch_t}; trim/pad to {target} frames\")\n    return vid","typeGuard":"def temporal_ok(T, t) -> bool:\n    return T % t == 1","tryCatchPattern":null,"preventionTips":["Compute the valid frame count ((T // t) * t + 1) in preprocessing, before VAE encode.","Read patch_size from the model config and assert the contract in pipeline code.","Prefer trimming trailing frames over duplicating when adjusting counts."],"tags":["seedvr2","video","temporal","shape-mismatch","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}