Add ImageBatchListCombineWithOverlap - new Node to allow for more RAM efficient Video Generation - #691
Open
Nihongasuki wants to merge 1 commit into
Open
Add ImageBatchListCombineWithOverlap - new Node to allow for more RAM efficient Video Generation#691Nihongasuki wants to merge 1 commit into
Nihongasuki wants to merge 1 commit into
Conversation
|
I have run into this memory issue as well with SVI in a loop with the ImageBatchExtendWithOverlap node. The memory bloat increases every iteration non-linearly and gets out of hand fast. Was not sure what was causing it inside the node. Hope this fixes it. |
Closed
|
I've implemented a more robust version of this in my little repo, which does the same except there is another node which can also merge audio at the same time - compatible with all the existing blending methods. https://github.com/altoiddealer/comfyui_essential-er
|
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
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.

Problem
When generating videos in multiple sampler steps (e.g. WAN SVI workflows), each step generates a rather large image tensor. With each application of the Image Batch Extend With Overlap Node, this image tensor needs to be cached as port of that nodes outputs. This causes unneccesary RAM bloat and can lead to cache busting if enough steps are performed.
For example in this case, the image tensor from the first step is copied 3 times (and thus uses 3 times as much RAM as is required.

This is especially problematic since the increase is not linear - each added step adds the weight of itself + all previous steps to RAM.
Fix
Introduce a new Node, that takes a list of image batches instead of only two at a time. I chose a list input over dynamic inputs because this allows cleaner workflows or workflows with dynamic generation steps (the workflow I am building uses Loop Nodes to theoretically extend the video forever). Also, it is pretty easy to create a list from a fixed number of Inputs.
For example here, the image tensor is only copied once. Rebatch Latents creates a list of batches with one latent each (one WAN latent = x frames). This is turned into a list of image batches of size x by VAE Decode, and this list is then combined in a single step via the new node.

This setup still copies Latents more then required, but since those are way smaller the impact is negligable. A complete solution would be a Node that also included the VAE Decode step, however that was too complicated and specialized for my tastes.
The code in the Node is basically identical to the existing Node, it just loops within the node and not within the workflow. In fact, the actual execution code could easily be shared between the two nodes, however I was unsure if you want your nodes to always be completely independent from each other.
In my workflow, this Node reduces RAM usage for 4 WAN 2.2 segments of 81 frames @ 0.7 MP each from multiple GB to under 1. (After models are unloaded)