Skip to content

Conversation

Kosinkadink
Copy link
Collaborator

@Kosinkadink Kosinkadink commented Aug 8, 2025

This PR adds two nodes: Context Windows (Manual) and WAN Context Windows (Manual) that will cause sampling to occur in sliding context windows instead of all at once.

The difference between the two nodes is that WAN Context Windows (Manual) will automatically convert context_length and context_overlap to be WAN-ified; using Context Windows (Manual) for WAN requires converting length and overlap the same way the latents are: ((context_length - 1) // 4) + 1

Left off to be supported in future PRs:

  • Nodes that are not fully manual, with values that correspond to particular schedules/fuse methods
    • Once dynamic inputs are supported, would only require one or two nodes to pull off
  • Proper ControlNet support - currently, will always pull the first context_length inputs instead of adjusting to context window.

No third party nodes will properly support this yet, but I will make AnimateDiff-Evolved and Advanced-ControlNet make use of the new context_handler/context_window model_options/tranformer_options keys so that my custom and this built-in solutions can coexist.

WAN2.2 5B does not work well with context windows as there is a component that should be readjusted per frame to likely make it passable, but WAN2.1/2.2 other models at least produce non-artifacted results. For most schedules though, the results are basically a 'fade' effect between one context to the next instead of borrowing content. Custom nodes can easily implement their own context windows, so there is a lot of room for experimentation.

@comfyanonymous comfyanonymous merged commit e4f7ea1 into master Aug 14, 2025
7 checks passed
@comfyanonymous comfyanonymous deleted the context-windows branch August 14, 2025 01:33
zhangp365 pushed a commit to zhangp365/ComfyUI that referenced this pull request Aug 14, 2025
* Added initial support for basic context windows - in progress

* Add prepare_sampling wrapper for context window to more accurately estimate latent memory requirements, fixed merging wrappers/callbacks dicts in prepare_model_patcher

* Made context windows compatible with different dimensions; works for WAN, but results are bad

* Fix comfy.patcher_extension.merge_nested_dicts calls in prepare_model_patcher in sampler_helpers.py

* Considering adding some callbacks to context window code to allow extensions of behavior without the need to rewrite code

* Made dim slicing cleaner

* Add Wan Context WIndows node for testing

* Made context schedule and fuse method functions be stored on the handler instead of needing to be registered in core code to be found

* Moved some code around between node_context_windows.py and context_windows.py

* Change manual context window nodes names/ids

* Added callbacks to IndexListContexHandler

* Adjusted default values for context_length and context_overlap, made schema.inputs definition for WAN Context Windows less annoying

* Make get_resized_cond more robust for various dim sizes

* Fix typo

* Another small fix
@TingTingin
Copy link

Does this not work with i2v i cant seem to get it to work?

Vander-Bilt pushed a commit to Vander-Bilt/ComfyUI that referenced this pull request Aug 26, 2025
* Added initial support for basic context windows - in progress

* Add prepare_sampling wrapper for context window to more accurately estimate latent memory requirements, fixed merging wrappers/callbacks dicts in prepare_model_patcher

* Made context windows compatible with different dimensions; works for WAN, but results are bad

* Fix comfy.patcher_extension.merge_nested_dicts calls in prepare_model_patcher in sampler_helpers.py

* Considering adding some callbacks to context window code to allow extensions of behavior without the need to rewrite code

* Made dim slicing cleaner

* Add Wan Context WIndows node for testing

* Made context schedule and fuse method functions be stored on the handler instead of needing to be registered in core code to be found

* Moved some code around between node_context_windows.py and context_windows.py

* Change manual context window nodes names/ids

* Added callbacks to IndexListContexHandler

* Adjusted default values for context_length and context_overlap, made schema.inputs definition for WAN Context Windows less annoying

* Make get_resized_cond more robust for various dim sizes

* Fix typo

* Another small fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Core team dependency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants