{"record":{"id":"257bb2d4c7b646e0","repo":"Comfy-Org/ComfyUI","slug":"the-generated-keyframes-were-recorded-at-generate","errorCode":null,"errorMessage":"The generated keyframes were recorded at {generated_keyframes['tokens_per_frame']} tokens per latent frame but this latent has {tokens_per_frame}. Separate the generated keyframes before upscaling the latent.","messagePattern":"The generated keyframes were recorded at (.+?) tokens per latent frame but this latent has (.+?)\\. Separate the generated keyframes before upscaling the latent\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/lightricks/model.py","lineNumber":1202,"sourceCode":"        return (orig_shape[3] // patch_size[1]) * (orig_shape[4] // patch_size[2])\n\n    def keyframes_abs_pos_mask(self, pixel_coords, orig_shape, grid_mask, num_guide_tokens, generated_keyframes):\n        \"\"\"Per-token mask selecting the latents that encode a single standalone pixel frame.\n\n        Returns a (batch, tokens) boolean mask over the already grid-filtered token sequence.\n        \"\"\"\n        temporal_start = pixel_coords[:, 0]\n        if temporal_start.ndim == 3:  # (batch, tokens, [start, end])\n            temporal_start = temporal_start[..., 0]\n        mask = temporal_start == 0\n        if num_guide_tokens > 0:\n            mask[:, -num_guide_tokens:] = False\n\n        if generated_keyframes is not None:\n            # The temporal patch size is always 1, so one latent frame is one row of tokens.\n            tokens_per_frame = self.tokens_per_latent_frame(orig_shape)\n            if generated_keyframes[\"tokens_per_frame\"] != tokens_per_frame:\n                raise ValueError(\n                    f\"The generated keyframes were recorded at {generated_keyframes['tokens_per_frame']} tokens \"\n                    f\"per latent frame but this latent has {tokens_per_frame}. Separate the generated keyframes \"\n                    \"before upscaling the latent.\"\n                )\n            first_token = generated_keyframes[\"first_latent_frame\"] * tokens_per_frame\n            num_slot_tokens = generated_keyframes[\"num_keyframes\"] * tokens_per_frame\n            slots = torch.zeros(orig_shape[2] * tokens_per_frame, dtype=torch.bool, device=mask.device)\n            slots[first_token:first_token + num_slot_tokens] = True\n            if grid_mask is not None:\n                slots = slots[grid_mask]\n            mask = mask | slots\n\n        return mask\n\n    def apply_keyframes_abs_pos_embedding(self, x, pixel_coords, orig_shape, grid_mask, num_guide_tokens, generated_keyframes):\n        \"\"\"Add the learned keyframe marker to the single-pixel-frame tokens.\n\n        A no-op for every checkpoint built without the parameter.","sourceCodeStart":1184,"sourceCodeEnd":1220,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/lightricks/model.py#L1184-L1220","documentation":"generated_keyframes carries the tokens_per_frame it was recorded with; when the current latent's tokens_per_latent_frame differs (different spatial resolution), the frame-slot boolean built from it would mark wrong token ranges, so the model refuses. Same family as errors 174/175: keyframe bookkeeping is resolution-bound.","triggerScenarios":"Passing generated_keyframes from a base-resolution pass into an upsampled pass where each latent frame has 4x the tokens (2x spatial upscale).","commonSituations":"LTX upscale pipelines that keep generated-keyframe conditioning wired across the resolution boundary.","solutions":["Remove generated_keyframes (separate them) before the upscaling sampling pass","Or regenerate the generated_keyframes dict against the upscaled latent's resolution, with first_latent_frame/num_keyframes recomputed","Keep a single resolution for the whole keyframe-conditioned chain"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"tpf = model.tokens_per_latent_frame(orig_shape)\nassert generated_keyframes['tokens_per_frame'] == tpf, (generated_keyframes['tokens_per_frame'], tpf)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Drop generated_keyframes when crossing a resolution boundary (upscaling)","Recompute keyframe bookkeeping if you deliberately re-res guides"],"tags":["ltx","keyframes","resolution-mismatch","upsample"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}