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

Recent commits broke merging #1359

Closed
cluder opened this issue Aug 21, 2024 · 1 comment
Closed

Recent commits broke merging #1359

cluder opened this issue Aug 21, 2024 · 1 comment

Comments

@cluder
Copy link
Contributor

cluder commented Aug 21, 2024

trying to merge models fails now because of multiple methods being called which have been removed (pass) or commented out

c1b23bd
bccf9fb

  1. sd_models.read_state_dict() has been removed (pass), but its still called during merging
    see extras.py: run_modelmerger()

  2. AttributeError: module 'modules.sd_models_config' has no attribute 'find_checkpoint_config_near_filename'
    find_checkpoint_config_near_filename has been commented out in: bccf9fb

the following changes seems to work for me, not sure if create_config() is needed at all after merging?

diff --git a/modules/extras.py b/modules/extras.py
index 2a310ae3..af0e2cfd 100644
--- a/modules/extras.py
+++ b/modules/extras.py
@@ -179,7 +179,7 @@ def run_modelmerger(id_task, primary_model_name, secondary_model_name, tertiary_

     shared.state.textinfo = f"Loading {primary_model_info.filename}..."
     print(f"Loading {primary_model_info.filename}...")
-    theta_0 = sd_models.read_state_dict(primary_model_info.filename, map_location='cpu')
+    theta_0 = sd_models.load_torch_file(primary_model_info.filename)^M

     print("Merging...")
     shared.state.textinfo = 'Merging A and B'
@@ -222,7 +222,7 @@ def run_modelmerger(id_task, primary_model_name, secondary_model_name, tertiary_
     if bake_in_vae_filename is not None:
         print(f"Baking in VAE from {bake_in_vae_filename}")
         shared.state.textinfo = 'Baking in VAE'
-        vae_dict = sd_vae.load_vae_dict(bake_in_vae_filename, map_location='cpu')
+        vae_dict = sd_vae.load_torch_file(bake_in_vae_filename)^M

         for key in vae_dict.keys():
             theta_0_key = 'first_stage_model.' + key
@@ -321,7 +321,7 @@ def run_modelmerger(id_task, primary_model_name, secondary_model_name, tertiary_
     if created_model:
         created_model.calculate_shorthash()

-    create_config(output_modelname, config_source, primary_model_info, secondary_model_info, tertiary_model_info)
+    #create_config(output_modelname, config_source, primary_model_info, secondary_model_info, tertiary_model_info)^M

     print(f"Checkpoint saved to {output_modelname}.")
     shared.state.textinfo = "Checkpoint saved"```
@cluder
Copy link
Contributor Author

cluder commented Aug 23, 2024

when the checkpoints list is populated initially, it does not contain a hash value, and a merge works.
after we close webui and run it again, the hash has been calculated, the checkpoint list now contains the checkpoint name + hash e.g. now we always get a KeyError because 'checkpoint.safetensor' cannot match 'checkpoint.safetensor [hash]'

image

To solve that problem, we can get the checkpoint into from the checkpoint_aliases which contains all possible key's (has only, name+hash, name only etc) for a specific model instead from the checkpoint_list:

image

cluder added a commit to cluder/stable-diffusion-webui-forge that referenced this issue Aug 23, 2024
- checkpoint_list[] contains the CheckpointInfo.title which is "checkpointname.safetensor [hash]"
  when a checkpoint is selected to be loaded during merge, we try to match it with just "checkpointname.safetensor".
  -> use checkpoint_aliases[] which already contains the checkpoint key in all possible variants.
- replaced removed sd_models.read_state_dict() with sd_models.load_torch_file()
- replaced removed sd_vae.load_vae_dict() with sd_vae.load_torch_file()
- uncommented create_config() for now, since it calls a removed method: sd_models_config.find_checkpoint_config_near_filename()
lllyasviel pushed a commit that referenced this issue Aug 26, 2024
- checkpoint_list[] contains the CheckpointInfo.title which is "checkpointname.safetensor [hash]"
  when a checkpoint is selected to be loaded during merge, we try to match it with just "checkpointname.safetensor".
  -> use checkpoint_aliases[] which already contains the checkpoint key in all possible variants.
- replaced removed sd_models.read_state_dict() with sd_models.load_torch_file()
- replaced removed sd_vae.load_vae_dict() with sd_vae.load_torch_file()
- uncommented create_config() for now, since it calls a removed method: sd_models_config.find_checkpoint_config_near_filename()
@cluder cluder closed this as completed Aug 27, 2024
cluder added a commit to cluder/stable-diffusion-webui-forge that referenced this issue Aug 31, 2024
- read_state_dict() does nothing, replaced 2 occurrences with load_torch_file()
- now merging actually merges again
lllyasviel pushed a commit that referenced this issue Sep 1, 2024
* Fix Checkpoint Merging #1359,#1095

- checkpoint_list[] contains the CheckpointInfo.title which is "checkpointname.safetensor [hash]"
  when a checkpoint is selected to be loaded during merge, we try to match it with just "checkpointname.safetensor".
  -> use checkpoint_aliases[] which already contains the checkpoint key in all possible variants.
- replaced removed sd_models.read_state_dict() with sd_models.load_torch_file()
- replaced removed sd_vae.load_vae_dict() with sd_vae.load_torch_file()
- uncommented create_config() for now, since it calls a removed method: sd_models_config.find_checkpoint_config_near_filename()

* Follow up merge fix for #1359 #1095

- read_state_dict() does nothing, replaced 2 occurrences with load_torch_file()
- now merging actually merges again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant