{"record":{"id":"d486dea07993c446","repo":"Comfy-Org/ComfyUI","slug":"guide-pre-filter-counts-total-pfc-keyframe","errorCode":null,"errorMessage":"guide pre_filter_counts ({total_pfc}) != keyframe grid mask length ({len(kf_grid_mask)})","messagePattern":"guide pre_filter_counts \\((.+?)\\) != keyframe grid mask length \\((.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/lightricks/model.py","lineNumber":1145,"sourceCode":"                    \"upscaling the latent.\"\n                )\n            additional_args.update({ \"orig_patchified_shape\": list(x.shape)})\n            denoise_mask = self.patchifier.patchify(denoise_mask)[0]\n            grid_mask = ~torch.any(denoise_mask < 0, dim=-1)[0]\n            additional_args.update({\"grid_mask\": grid_mask})\n            x = x[:, grid_mask, :]\n            pixel_coords = pixel_coords[:, :, grid_mask, ...]\n\n            kf_grid_mask = grid_mask[-keyframe_idxs.shape[2]:]\n\n            # Compute per-guide surviving token counts from guide_attention_entries.\n            # Each entry tracks one guide reference; they are appended in order and\n            # their pre_filter_counts partition the kf_grid_mask.\n            guide_entries = kwargs.get(\"guide_attention_entries\", None)\n            if guide_entries:\n                total_pfc = sum(e[\"pre_filter_count\"] for e in guide_entries)\n                if total_pfc != len(kf_grid_mask):\n                    raise ValueError(\n                        f\"guide pre_filter_counts ({total_pfc}) != \"\n                        f\"keyframe grid mask length ({len(kf_grid_mask)})\"\n                    )\n                resolved_entries = []\n                offset = 0\n                for entry in guide_entries:\n                    pfc = entry[\"pre_filter_count\"]\n                    entry_mask = kf_grid_mask[offset:offset + pfc]\n                    surviving = int(entry_mask.sum().item())\n                    resolved_entries.append({\n                        **entry,\n                        \"surviving_count\": surviving,\n                    })\n                    offset += pfc\n                additional_args[\"resolved_guide_entries\"] = resolved_entries\n\n            keyframe_idxs = keyframe_idxs[..., kf_grid_mask, :]\n","sourceCodeStart":1127,"sourceCodeEnd":1163,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/lightricks/model.py#L1127-L1163","documentation":"After the keyframe grid mask is sliced, the sum of each guide entry's recorded pre_filter_count must exactly equal the sliced mask length. If it does not, guide_attention_entries were built against a different token layout than the current mask, and per-guide slice boundaries would be wrong.","triggerScenarios":"Passing guide_attention_entries whose pre_filter_counts cover more/fewer tokens than keyframe_idxs.shape[2] surviving after grid_mask filtering; e.g. entries recorded before a mask change or a resolution change in the same pass as error 174.","commonSituations":"Reusing guide entries cached from a prior step while the denoise/grid mask evolved, or mixing guides appended at different resolutions.","solutions":["Recompute guide_attention_entries in the same pass that rebuilds keyframe_idxs and grid_mask","Ensure sum(pre_filter_count) == keyframe_idxs.shape[2] before calling forward","Separate stale guide conditioning before changing masks or resolutions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"total = sum(e['pre_filter_count'] for e in guide_entries)\nassert total == keyframe_idxs.shape[2], (total, keyframe_idxs.shape[2])","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rebuild guide_attention_entries in the same pass as keyframe_idxs/grid_mask","Never cache guide entries across mask or resolution changes"],"tags":["ltx","guides","keyframes","consistency"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}