Comfy-Org/ComfyUI · error · ValueError
keyframe_idxs holds {keyframe_idxs.shape[2]} tokens, which i
Error message
keyframe_idxs holds {keyframe_idxs.shape[2]} tokens, which is not a whole number of {tokens_per_frame}-token latent frames. The appended frames were recorded against a different spatial resolution than the latent being sampled, so their positions would land on the wrong tokens. Crop the guides and separate the generated keyframes before upscaling the latent. What it means
During keyframe-conditioned LTX sampling, the recorded keyframe token indices must decompose into whole latent frames at the CURRENT latent resolution (tokens_per_latent_frame of the tensor being sampled). A non-multiple means the keyframes were logged against a different spatial resolution (e.g. pre-upscale), so their token positions would be misaligned.
Source
Thrown at comfy/ldm/lightricks/model.py:1122
)
self.proj_out = self.operations.Linear(self.inner_dim, self.out_channels, dtype=dtype, device=device)
self.patchifier = SymmetricPatchifier(1, start_end=True)
def _process_input(self, x, keyframe_idxs, denoise_mask, **kwargs):
"""Process input for LTXV."""
additional_args = {"orig_shape": list(x.shape)}
x, latent_coords = self.patchifier.patchify(x)
pixel_coords = latent_to_pixel_coords(
latent_coords=latent_coords,
scale_factors=self.vae_scale_factors,
causal_fix=self.causal_temporal_positioning,
)
grid_mask = None
if keyframe_idxs is not None and keyframe_idxs.shape[2] > 0:
tokens_per_frame = self.tokens_per_latent_frame(additional_args["orig_shape"])
if keyframe_idxs.shape[2] % tokens_per_frame != 0:
raise ValueError(
f"keyframe_idxs holds {keyframe_idxs.shape[2]} tokens, which is not a whole number of "
f"{tokens_per_frame}-token latent frames. The appended frames were recorded against a "
"different spatial resolution than the latent being sampled, so their positions would land "
"on the wrong tokens. Crop the guides and separate the generated keyframes before "
"upscaling the latent."
)
additional_args.update({ "orig_patchified_shape": list(x.shape)})
denoise_mask = self.patchifier.patchify(denoise_mask)[0]
grid_mask = ~torch.any(denoise_mask < 0, dim=-1)[0]
additional_args.update({"grid_mask": grid_mask})
x = x[:, grid_mask, :]
pixel_coords = pixel_coords[:, :, grid_mask, ...]
kf_grid_mask = grid_mask[-keyframe_idxs.shape[2]:]
# Compute per-guide surviving token counts from guide_attention_entries.
# Each entry tracks one guide reference; they are appended in order and
# their pre_filter_counts partition the kf_grid_mask.View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Crop the guide latent and detach the generated keyframes before upscaling, as the message says
- Re-record keyframe_idxs against the new resolution if you intentionally re-scale guides
- Keep all keyframe bookkeeping and the sampled latent at the same spatial resolution
Defensive patterns
Strategy: validation
Validate before calling
tpf = model.tokens_per_latent_frame(list(latent.shape)) assert keyframe_idxs.shape[2] % tpf == 0, (keyframe_idxs.shape[2], tpf)
Prevention
- Separate generated keyframes from guides before any latent upscale
- Keep keyframe_idxs and the sampled latent at one resolution for the whole chain
When it happens
Trigger: Feeding keyframe_idxs recorded on the base latent into an upscaled sampling pass (2x spatial -> 4x tokens per frame), or mixing guides from one resolution with a latent of another.
Common situations: Two-pass workflows: generate keyframes at low res, then upscale the latent while keeping the guide/keyframe conditioning attached instead of separating it first.
Related errors
- The generated keyframes were recorded at {generated_keyframe
- Either spatial_upsample or temporal_upsample must be True
- guide pre_filter_counts ({total_pfc}) != keyframe grid mask
- Unrecognized interpolation method '{method}'.
- DurationHead requires at least one of video_tokens / audio_t
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/7ce7f08ff03e9025.
Report an issue: GitHub.