Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

rattus128
Copy link
Contributor

If this suffers an exception (such as a VRAM oom) it will leave the encode() and decode() methods which skips the cleanup of the WAN feature cache. The comfy node cache then ultimately keeps a reference this object which is in turn reffing large tensors from the failed execution.

The feature cache is currently setup at a class variable on the encoder/decoder however, the encode and decode functions always clear it on both entry and exit of normal execution.

Its likely the design intent is this is usable as a streaming encoder where the input comes in batches, however the functions as they are today don't support that.

So simplify by bringing the cache back to local variable, so that if it does VRAM OOM the cache itself is properly garbage collected when the encode()/decode() functions disappear from the stack.

Example Test conditions:
NVIDIA GeForce GTX 1660 SUPER (6GB)
Tiled VAE Encode 608x608x13f as one large tile (no acutal tiling)

This gives me the OOM I deserve, but VRAM then leaks. See the RHS of the nvtop trace where it does not come down to baseline after the exception.

oom

With this change, VRAM will now return to baseline:

oom-fixed

If this suffers an exception (such as a VRAM oom) it will leave the
encode() and decode() methods which skips the cleanup of the WAN
feature cache. The comfy node cache then ultimately keeps a reference
this object which is in turn reffing large tensors from the failed
execution.

The feature cache is currently setup at a class variable on the
encoder/decoder however, the encode and decode functions always clear
it on both entry and exit of normal execution.

Its likely the design intent is this is usable as a streaming encoder
where the input comes in batches, however the functions as they are
today don't support that.

So simplify by bringing the cache back to local variable, so that if
it does VRAM OOM the cache itself is properly garbage when the
encode()/decode() functions dissappear from the stack.
@rattus128 rattus128 requested a review from Kosinkadink as a code owner October 1, 2025 09:53
@Kosinkadink Kosinkadink added the Good PR This PR looks good to go, it needs comfy's final review. label Oct 1, 2025
@comfyanonymous comfyanonymous merged commit 4965c0e into comfyanonymous:master Oct 1, 2025
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good PR This PR looks good to go, it needs comfy's final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants