Harden latent upscale GPU cleanup

This commit is contained in:
2026-09-04 10:05:24 +00:00
parent cbabcf8208
commit 618a48e4d9
2 changed files with 45 additions and 16 deletions
+35 -13
View File
@@ -6055,7 +6055,7 @@ def quant_accel_note(model):
def _evict_all_but(keep_model):
def _evict_all_but(keep_model):
"""Unload every model EXCEPT the diffusion model from the GPU.
This is the fix for VRAM ratcheting across a long chain. soft_empty_cache()
@@ -6081,15 +6081,38 @@ def _evict_all_but(keep_model):
except Exception:
try:
mm.soft_empty_cache(True)
except Exception:
pass
class H3LongVideos:
except Exception:
pass
def _evict_for_latent_upscale(model):
"""Clear the sampler model before loading the auxiliary latent upscaler."""
try:
unload_clones = getattr(mm, "unload_model_and_clones", None)
if callable(unload_clones):
try:
unload_clones(model, unload_additional_models=False)
mm.soft_empty_cache()
return
except Exception:
pass
mm.unload_all_models()
except Exception:
pass
try:
mm.soft_empty_cache(True)
except Exception:
try:
mm.soft_empty_cache()
except Exception:
pass
class H3LongVideos:
CATEGORY = "Dumas/MiniMax"
FUNCTION = "run"
# fps is emitted as BOTH types on purpose: ComfyUI does not coerce between them,
@@ -6662,9 +6685,8 @@ class H3LongVideos:
parts = _nested_tensor_parts(out_samples)
if not getattr(out_samples, "is_nested", False) or len(parts) < 2:
raise RuntimeError("latent upscale expects a nested AV latent")
if latent_upscale_mode == "model" and str(latent_upscale_param.get("device", "cuda")) == "cuda" and hasattr(model, "clone_base_uuid"):
mm.unload_model_and_clones(model, unload_additional_models=False)
mm.soft_empty_cache()
if latent_upscale_mode == "model" and str(latent_upscale_param.get("device", "cuda")) == "cuda":
_evict_for_latent_upscale(model)
upscaled_video, up_h, up_w = _upscale_latent_video(parts[0], latent_upscale_param)
full_audio = parts[1]
# Drop the first-pass sampling state before we start the refinement