aboutsummaryrefslogtreecommitdiffstats
path: root/modules/sd_models.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-07-29 04:43:04 +0000
committerGitHub <noreply@github.com>2023-07-29 04:43:04 +0000
commitac81c1dd1f0887a891b190e5755f283a82bd2655 (patch)
tree511bd4963d5af3458da012fd2ebec0cc36567d39 /modules/sd_models.py
parent25004d4eeef015d8f886c537d3a5a9f54d07898e (diff)
parent0a89cd1a584b1584a0609c0ba27fb35c434b0b68 (diff)
downloadstable-diffusion-webui-gfx803-ac81c1dd1f0887a891b190e5755f283a82bd2655.tar.gz
stable-diffusion-webui-gfx803-ac81c1dd1f0887a891b190e5755f283a82bd2655.tar.bz2
stable-diffusion-webui-gfx803-ac81c1dd1f0887a891b190e5755f283a82bd2655.zip
Merge pull request #11958 from AUTOMATIC1111/conserve-ram
Use less RAM when creating models
Diffstat (limited to 'modules/sd_models.py')
-rw-r--r--modules/sd_models.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/modules/sd_models.py b/modules/sd_models.py
index fb31a793..acb1e817 100644
--- a/modules/sd_models.py
+++ b/modules/sd_models.py
@@ -460,7 +460,6 @@ def get_empty_cond(sd_model):
return sd_model.cond_stage_model([""])
-
def load_model(checkpoint_info=None, already_loaded_state_dict=None):
from modules import lowvram, sd_hijack
checkpoint_info = checkpoint_info or select_checkpoint()
@@ -495,19 +494,24 @@ def load_model(checkpoint_info=None, already_loaded_state_dict=None):
sd_model = None
try:
with sd_disable_initialization.DisableInitialization(disable_clip=clip_is_included_into_sd or shared.cmd_opts.do_not_download_clip):
- sd_model = instantiate_from_config(sd_config.model)
- except Exception:
- pass
+ with sd_disable_initialization.InitializeOnMeta():
+ sd_model = instantiate_from_config(sd_config.model)
+
+ except Exception as e:
+ errors.display(e, "creating model quickly", full_traceback=True)
if sd_model is None:
print('Failed to create model quickly; will retry using slow method.', file=sys.stderr)
- sd_model = instantiate_from_config(sd_config.model)
+
+ with sd_disable_initialization.InitializeOnMeta():
+ sd_model = instantiate_from_config(sd_config.model)
sd_model.used_config = checkpoint_config
timer.record("create model")
- load_model_weights(sd_model, checkpoint_info, state_dict, timer)
+ with sd_disable_initialization.LoadStateDictOnMeta(state_dict, devices.cpu):
+ load_model_weights(sd_model, checkpoint_info, state_dict, timer)
if shared.cmd_opts.lowvram or shared.cmd_opts.medvram:
lowvram.setup_for_low_vram(sd_model, shared.cmd_opts.medvram)