Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix meta tensor issue #29

Merged
merged 2 commits into from
Oct 12, 2023
Merged

Fix meta tensor issue #29

merged 2 commits into from
Oct 12, 2023

Conversation

wkpark
Copy link
Owner

@wkpark wkpark commented Oct 12, 2023

sd_models.load_model() call with already_loaded_state_dict=state_dict makes current sd_model state "meta" by line https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/v1.6.0/modules/sd_models.py#L563-L577

...
    if model_data.sd_model:
        send_model_to_trash(model_data.sd_model) # this line
        model_data.sd_model = None
        devices.torch_gc()
...

workaround this issue before calling sd_models.load_model() add the follows

diff --git a/scripts/model_mixer.py b/scripts/model_mixer.py
index 1981557..ef9a17d 100644
--- a/scripts/model_mixer.py
+++ b/scripts/model_mixer.py
@@ -2122,6 +2122,12 @@ class ModelMixerScript(scripts.Script):
             print("WARN: lowvram/medvram load_model() with minor workaround")
             sd_models.unload_model_weights()
             #sd_models.model_data.__init__()
+
+        if sd_models.model_data.sd_model:
+            sd_models.send_model_to_cpu(sd_models.model_data.sd_model) # this line.
+            sd_models.model_data.sd_model = None
+            devices.torch_gc()
+
         sd_models.load_model(checkpoint_info=checkpoint_info, already_loaded_state_dict=state_dict)
         del state_dict
         devices.torch_gc()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working workaround
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant