Skip to content

Add slice_cond and per-model context window cond resizing#12645

Merged
Kosinkadink merged 6 commits intoComfy-Org:masterfrom
drozbay:20260225a_slice_cond
Mar 20, 2026
Merged

Add slice_cond and per-model context window cond resizing#12645
Kosinkadink merged 6 commits intoComfy-Org:masterfrom
drozbay:20260225a_slice_cond

Conversation

@drozbay
Copy link
Copy Markdown
Contributor

@drozbay drozbay commented Feb 26, 2026

Adds a slice_cond() helper in context_windows.py and a new resize_cond_for_context_window() method on BaseModel that lets each model subclass declare how its conditionings should be sliced during context windowing.

The context window handler calls the model method before falling back to the existing generic slicing logic, so models with non-standard temporal dimensions or offsets can handle them explicitly:

# to use this slicing mechanism, implement this method in the BaseModel subclass in model_base.py:
def resize_cond_for_context_window(self, cond_key, cond_value, window, x_in, device, retain_index_list=[]):
    if cond_key == "my_cond":
        import comfy.context_windows
        return comfy.context_windows.slice_cond(cond_value, window, x_in, device, temporal_dim=2, temporal_offset=1)
    return super().resize_cond_for_context_window(cond_key, cond_value, window, x_in, device, retain_index_list=retain_index_list)

Implements overrides for WAN21_Vace, WAN21_HuMo, WAN22_Animate, and WAN22_S2V.


Also fixed a small mostly benign bug: cond_value(self.dim) to cond_value.size(self.dim)

@drozbay drozbay marked this pull request as ready for review February 26, 2026 05:17
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 027567fe-47b1-4717-b9c9-dd6af6182542

📥 Commits

Reviewing files that changed from the base of the PR and between ac6b8a9 and 2c1d0fa.

📒 Files selected for processing (1)
  • comfy/model_base.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • comfy/model_base.py

📝 Walkthrough

Walkthrough

Adds slice_cond() to comfy/context_windows.py and caches the provided model in ContextWindows.execute (self._model = model). Updates get_resized_cond to use cond_value.size(self.dim) and to delegate to BaseModel.resize_cond_for_context_window(...) when applicable, passing retain_index_list. Adds resize_cond_for_context_window overrides for WAN21, WAN21_Vace, WAN21_Camera, WAN21_HuMo, WAN22, WAN22_S2V, and WAN22_Animate. Adds cond_retain_index_list and split_conds_to_windows inputs to ContextWindowsManualNode schema.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding slice_cond helper and per-model context window conditioning resizing functionality.
Description check ✅ Passed The description clearly relates to the changeset, explaining the new slice_cond helper, resize_cond_for_context_window method, model overrides, and the bugfix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

Flake8 can be used to improve the quality of Python code reviews.

Flake8 is a Python linter that wraps PyFlakes, pycodestyle and Ned Batchelder's McCabe script.

To configure Flake8, add a '.flake8' or 'setup.cfg' file to your project root.

See Flake8 Documentation for more details.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@comfy/context_windows.py`:
- Around line 224-230: Initialize self._model to None in the
IndexListContextHandler.__init__ so get_resized_cond won't raise AttributeError
when called before execute(); specifically, add self._model = None in the
constructor of IndexListContextHandler (the class that defines get_resized_cond)
and ensure any code paths that later set the model in execute() continue to
assign to the same attribute, which will allow the guard "self._model is not
None" to work correctly when calling resize_cond_for_context_window.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 907e5dc and 83f11a8.

📒 Files selected for processing (2)
  • comfy/context_windows.py
  • comfy/model_base.py

@comfy-pr-bot
Copy link
Copy Markdown
Member

Test Evidence Check

⚠️ Warning: Test Explanation Missing

If this PR modifies behavior that requires testing, a test explanation is required. PRs lacking applicable test explanations may not be reviewed until added. Please add test explanations to ensure code quality and prevent regressions.

⚠️ Warning: Visual Documentation Missing

If this PR changes user-facing behavior, visual proof (screen recording or screenshot) is required. PRs without applicable visual documentation may not be reviewed until provided.

You can add it by:

  • GitHub: Drag & drop media directly into the PR description
  • YouTube: Include a link to a short demo

Necessary for WanAnimate context windows workflow, which needs cond_retain_index_list = 0 to work properly with its reference input.
@drozbay
Copy link
Copy Markdown
Contributor Author

drozbay commented Mar 2, 2026

I had to update the Context Windows (Manual) node to expose cond_retain_index_list, which must be set to 0 to maintain the reference image for WanAnimate.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
comfy_extras/nodes_context_windows.py (1)

30-31: Consider adding advanced=True for consistency with the commit description.

The commit message mentions "Expose additional advanced inputs," but these new inputs are not marked as advanced=True. Other similar configuration inputs in this schema (e.g., context_length, context_overlap, context_stride) use advanced=True. If these are intended to be advanced/power-user inputs, adding the flag would keep them consistent with the existing pattern and reduce UI clutter for casual users.

If they're intentionally non-advanced for discoverability, the current implementation is fine.

✨ Optional: mark as advanced inputs
-                io.String.Input("cond_retain_index_list", default="", tooltip="List of latent indices to retain in the conditioning tensors for each window, for example setting this to '0' will use the initial start image for each window."),
-                io.Boolean.Input("split_conds_to_windows", default=False, tooltip="Whether to split multiple conditionings (created by ConditionCombine) to each window based on region index."),
+                io.String.Input("cond_retain_index_list", default="", tooltip="List of latent indices to retain in the conditioning tensors for each window, for example setting this to '0' will use the initial start image for each window.", advanced=True),
+                io.Boolean.Input("split_conds_to_windows", default=False, tooltip="Whether to split multiple conditionings (created by ConditionCombine) to each window based on region index.", advanced=True),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@comfy_extras/nodes_context_windows.py` around lines 30 - 31, The new inputs
"cond_retain_index_list" (io.String.Input) and "split_conds_to_windows"
(io.Boolean.Input) should be marked as advanced to match the pattern used for
other context parameters; update the Input declarations for
cond_retain_index_list and split_conds_to_windows to include advanced=True so
they appear in the advanced UI group like
context_length/context_overlap/context_stride.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@comfy_extras/nodes_context_windows.py`:
- Around line 30-31: The new inputs "cond_retain_index_list" (io.String.Input)
and "split_conds_to_windows" (io.Boolean.Input) should be marked as advanced to
match the pattern used for other context parameters; update the Input
declarations for cond_retain_index_list and split_conds_to_windows to include
advanced=True so they appear in the advanced UI group like
context_length/context_overlap/context_stride.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83f11a8 and f0f05e9.

📒 Files selected for processing (1)
  • comfy_extras/nodes_context_windows.py

@drozbay
Copy link
Copy Markdown
Contributor Author

drozbay commented Mar 2, 2026

Here is a workflow that demonstrates this functionality with WanAnimate.

droz_Wan22_Animate_ContextWindows_Native_vs_Wrapper.json

The source video can be found here: https://www.pexels.com/video/woman-performing-choreograph-6616345/

Reference image:
ForestWoman_FullBodyPortrait

Output example:
https://github.com/user-attachments/assets/e75cd0da-4eb7-4741-95b3-198a354ce0d3

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@comfy/model_base.py`:
- Around line 1437-1442: The override resize_cond_for_context_window is dropping
the retain_index_list when delegating audio_embed (and other model-specific)
keys to comfy.context_windows.slice_cond; update the calls in
resize_cond_for_context_window (for cond_key "audio_embed" and the other
model-specific branches at the referenced locations) to pass the
retain_index_list through to comfy.context_windows.slice_cond (add
retain_index_list=retain_index_list or positional arg as appropriate) so that
cond_retain_index_list behavior is preserved and matches the superclass path.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0f05e9 and ac6b8a9.

📒 Files selected for processing (2)
  • comfy/context_windows.py
  • comfy/model_base.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • comfy/context_windows.py

@Kosinkadink Kosinkadink merged commit 589228e into Comfy-Org:master Mar 20, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants