mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-09 05:40:49 +08:00
sd: Free RAM on main model load
This commit is contained in:
parent
f190744f62
commit
3f4ee9174c
@ -305,6 +305,7 @@ class BaseModel(torch.nn.Module):
|
|||||||
to_load[k[len(unet_prefix):]] = sd.pop(k)
|
to_load[k[len(unet_prefix):]] = sd.pop(k)
|
||||||
|
|
||||||
to_load = self.model_config.process_unet_state_dict(to_load)
|
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)
|
m, u = self.diffusion_model.load_state_dict(to_load, strict=False)
|
||||||
if len(m) > 0:
|
if len(m) > 0:
|
||||||
logging.warning("unet missing: {}".format(m))
|
logging.warning("unet missing: {}".format(m))
|
||||||
|
|||||||
@ -286,6 +286,7 @@ class CLIP:
|
|||||||
|
|
||||||
def load_sd(self, sd, full_model=False):
|
def load_sd(self, sd, full_model=False):
|
||||||
if full_model:
|
if full_model:
|
||||||
|
comfy.model_management.free_ram(state_dict=sd)
|
||||||
return self.cond_stage_model.load_state_dict(sd, strict=False)
|
return self.cond_stage_model.load_state_dict(sd, strict=False)
|
||||||
else:
|
else:
|
||||||
return self.cond_stage_model.load_sd(sd)
|
return self.cond_stage_model.load_sd(sd)
|
||||||
@ -660,6 +661,7 @@ class VAE:
|
|||||||
self.first_stage_model = AutoencoderKL(**(config['params']))
|
self.first_stage_model = AutoencoderKL(**(config['params']))
|
||||||
self.first_stage_model = self.first_stage_model.eval()
|
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)
|
m, u = self.first_stage_model.load_state_dict(sd, strict=False)
|
||||||
if len(m) > 0:
|
if len(m) > 0:
|
||||||
logging.warning("Missing VAE keys {}".format(m))
|
logging.warning("Missing VAE keys {}".format(m))
|
||||||
@ -981,6 +983,7 @@ def load_style_model(ckpt_path):
|
|||||||
model = comfy.ldm.flux.redux.ReduxImageEncoder()
|
model = comfy.ldm.flux.redux.ReduxImageEncoder()
|
||||||
else:
|
else:
|
||||||
raise Exception("invalid style model {}".format(ckpt_path))
|
raise Exception("invalid style model {}".format(ckpt_path))
|
||||||
|
comfy.model_management.free_ram(state_dict=model_data)
|
||||||
model.load_state_dict(model_data)
|
model.load_state_dict(model_data)
|
||||||
return StyleModel(model)
|
return StyleModel(model)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user