-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Added context window support to core sampling code #9238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+639
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…timate latent memory requirements, fixed merging wrappers/callbacks dicts in prepare_model_patcher
…WAN, but results are bad
…_patcher in sampler_helpers.py
…ensions of behavior without the need to rewrite code
…ler instead of needing to be registered in core code to be found
…schema.inputs definition for WAN Context Windows less annoying
oluwayemigift73-coder
approved these changes
Aug 8, 2025
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds two nodes:
Context Windows (Manual)
andWAN 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; usingContext 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:
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.