From 4a83a9bc0e6da93af2fe75457768fc1e2a0238ad Mon Sep 17 00:00:00 2001 From: Rattus Date: Tue, 18 Nov 2025 09:17:10 +1000 Subject: [PATCH] sd: Free RAM on main model load --- comfy/model_base.py | 1 + comfy/sd.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/comfy/model_base.py b/comfy/model_base.py index 9b76c285e..76dc3e370 100644 --- a/comfy/model_base.py +++ b/comfy/model_base.py @@ -304,6 +304,7 @@ class BaseModel(torch.nn.Module): to_load[k[len(unet_prefix):]] = sd.pop(k) to_load = self.model_config.process_unet_state_dict(to_load) + comfy.model_management.free_ram(state_dict=to_load) m, u = self.diffusion_model.load_state_dict(to_load, strict=False) if len(m) > 0: logging.warning("unet missing: {}".format(m)) diff --git a/comfy/sd.py b/comfy/sd.py index f9e5efab5..bfa63debc 100644 --- a/comfy/sd.py +++ b/comfy/sd.py @@ -260,6 +260,7 @@ class CLIP: def load_sd(self, sd, full_model=False): if full_model: + comfy.model_management.free_ram(state_dict=sd) return self.cond_stage_model.load_state_dict(sd, strict=False) else: return self.cond_stage_model.load_sd(sd) @@ -625,6 +626,7 @@ class VAE: self.first_stage_model = AutoencoderKL(**(config['params'])) self.first_stage_model = self.first_stage_model.eval() + comfy.model_management.free_ram(state_dict=sd) m, u = self.first_stage_model.load_state_dict(sd, strict=False) if len(m) > 0: logging.warning("Missing VAE keys {}".format(m)) @@ -933,6 +935,7 @@ def load_style_model(ckpt_path): model = comfy.ldm.flux.redux.ReduxImageEncoder() else: raise Exception("invalid style model {}".format(ckpt_path)) + comfy.model_management.free_ram(state_dict=model_data) model.load_state_dict(model_data) return StyleModel(model)