Conversation
… cache-clear dispatch (Comfy-Org#193) Adds tests-unit/comfy_test/test_seedvr_clear_vae_memory_soft_empty_cache.py: asserts comfy_extras.nodes_seedvr.clear_vae_memory dispatches its cache clear via comfy.model_management.soft_empty_cache (the canonical per-backend helper at comfy/model_management.py:1780) rather than calling torch.cuda.empty_cache() directly. Test forces comfy.cli_args.args.cpu = True before importing comfy.model_management / comfy_extras.nodes_seedvr so the path under test is soft_empty_cache's CPU-mode short-circuit at comfy/model_management.py:1781 — deterministic regardless of host CUDA availability. Stub is a bare torch.nn.Module so .modules() iteration is well-defined. Pre-fix probe (this commit, against issue_101 HEAD without fix applied): pytest exits 1 with AssertionError "torch.cuda.empty_cache was called 1 times; expected 0". Production line-84 fix and post-fix probe land in Slice 2.
…ear via soft_empty_cache (Comfy-Org#193) Replace the unguarded torch.cuda.empty_cache() call at comfy_extras/nodes_seedvr.py:84 with comfy.model_management.soft_empty_cache(). The canonical helper at comfy/model_management.py:1780 short-circuits via cpu_mode() and dispatches per backend (MPS / XPU / NPU / MLU / CUDA), so it is the only correct call shape on non-CUDA backends and on managed- device hosts where comfy.cli_args.args.cpu is True. The comfy.model_management module is already imported at line 8; no new import is required. The for-loop that nulls module.memory and the gc.collect() call are unchanged — both are CUDA-agnostic and out of scope. Slice 2 post-fix probe (this commit) runs tests-unit/comfy_test/test_seedvr_clear_vae_memory_soft_empty_cache.py to PASS; Slice 1 had it failing against pre-fix HEAD with "torch.cuda.empty_cache was called 1 times; expected 0".
…ar_vae_memory_uses_soft_empty_cache (Comfy-Org#193) Rename the regression test function from test_clear_vae_memory_dispatches_via_soft_empty_cache to test_clear_vae_memory_uses_soft_empty_cache to match the slice contract test ID. Test body, fixtures, imports, and module-level args.cpu flip are unchanged.
There was a problem hiding this comment.
Pull request overview
This PR fixes SeedVR2 VAE memory clearing to use ComfyUI’s cross-backend cache clearing helper instead of calling CUDA directly, and adds a regression test to prevent reintroducing the CUDA-only call shape.
Changes:
- Replace
torch.cuda.empty_cache()withcomfy.model_management.soft_empty_cache()inclear_vae_memory. - Add a CPU-mode regression test asserting
clear_vae_memorydispatches viasoft_empty_cacheand does not directly calltorch.cuda.empty_cache.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
comfy_extras/nodes_seedvr.py |
Switches VAE cache clearing to model_management.soft_empty_cache() for backend-aware behavior. |
tests-unit/comfy_test/test_seedvr_clear_vae_memory_soft_empty_cache.py |
Adds a regression test guarding against direct torch.cuda.empty_cache() calls from clear_vae_memory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+34
| from comfy.cli_args import args as _cli_args | ||
|
|
||
| _cli_args.cpu = True | ||
|
|
||
| import comfy.model_management # noqa: E402 | ||
| import comfy_extras.nodes_seedvr as nodes_seedvr # noqa: E402 |
Comment on lines
+53
to
+57
| f"times; expected 0. clear_vae_memory must dispatch via " | ||
| f"comfy.model_management.soft_empty_cache, which short-circuits in " | ||
| f"CPU mode (cpu_mode() check at comfy/model_management.py:1781). " | ||
| f"The unguarded torch.cuda.empty_cache() call at " | ||
| f"comfy_extras/nodes_seedvr.py:84 is the regression this test locks." |
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.
Summary
comfy_extras/nodes_seedvr.py:84:torch.cuda.empty_cache()→comfy.model_management.soft_empty_cache(). The canonical helper atcomfy/model_management.py:1780short-circuits viacpu_mode()and dispatches per-backend (MPS / XPU / NPU / MLU / CUDA), so it is the only correct call shape on non-CUDA hosts and on managed-device hosts wherecomfy.cli_args.args.cpuis True.tests-unit/comfy_test/test_seedvr_clear_vae_memory_soft_empty_cache.pythat flipsargs.cpu = Truebefore importing anycomfy.ldm.*/comfy_extras.*symbol, then assertsclear_vae_memory(stub)invokessoft_empty_cacheexactly once andtorch.cuda.empty_cachezero times.Scope
comfy_extras/nodes_seedvr.py— 1 line replaced (line 84). Thefor module in vae_model.modules(): if hasattr(module, "memory"): module.memory = Noneloop andgc.collect()are unchanged — both are CUDA-agnostic and out of scope.tests-unit/comfy_test/test_seedvr_clear_vae_memory_soft_empty_cache.py— new file (64 lines).git diff --name-only origin/issue_101..issue_193lists exactly two paths.comfy.model_managementis already imported atcomfy_extras/nodes_seedvr.py:8.Test plan
origin/issue_101comfy_extras/nodes_seedvr.py): pytest exit 1,AssertionError: torch.cuda.empty_cache was called 1 times; expected 0.issue_193HEAD): pytest exit 0,1 passed in 1.88s.comfy.model_management.soft_empty_cache(); literaltorch.cuda.empty_cache()no longer appears inclear_vae_memory.args.cpu = True.comfy_extras/nodes_seedvr.py+ new test module)._cli_args.cpu = True(line 31) precedescomfy.model_management(line 33) andcomfy_extras.nodes_seedvr(line 34) imports.