diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-01-28 07:52:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-28 07:52:28 +0000 |
commit | bea31e849a26c75f621fbac08cc2c7ffd71abfba (patch) | |
tree | 16329776de9a2d433e773df896b6af595c065d84 /modules | |
parent | 60061eb8d44fe6dcbd846167e35b98e4fc113076 (diff) | |
parent | cdc2fa209a3efdc71a90643a5e7a1df49869cd5f (diff) | |
download | stable-diffusion-webui-gfx803-bea31e849a26c75f621fbac08cc2c7ffd71abfba.tar.gz stable-diffusion-webui-gfx803-bea31e849a26c75f621fbac08cc2c7ffd71abfba.tar.bz2 stable-diffusion-webui-gfx803-bea31e849a26c75f621fbac08cc2c7ffd71abfba.zip |
Merge pull request #7240 from Unstackd/master
Allow users to convert models to Instruct-pix2pix models by supporting merging Instruct-pix2pix models with regular ones in the merge tab
Diffstat (limited to 'modules')
-rw-r--r-- | modules/extras.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/modules/extras.py b/modules/extras.py index 4f842be9..d8ece955 100644 --- a/modules/extras.py +++ b/modules/extras.py @@ -132,6 +132,7 @@ def run_modelmerger(id_task, primary_model_name, secondary_model_name, tertiary_ tertiary_model_info = sd_models.checkpoints_list[tertiary_model_name] if theta_func1 else None
result_is_inpainting_model = False
+ result_is_instruct_pix2pix_model = False
if theta_func2:
shared.state.textinfo = f"Loading B"
@@ -185,14 +186,19 @@ def run_modelmerger(id_task, primary_model_name, secondary_model_name, tertiary_ if a.shape != b.shape and a.shape[0:1] + a.shape[2:] == b.shape[0:1] + b.shape[2:]:
if a.shape[1] == 4 and b.shape[1] == 9:
raise RuntimeError("When merging inpainting model with a normal one, A must be the inpainting model.")
+ if a.shape[1] == 4 and b.shape[1] == 8:
+ raise RuntimeError("When merging instruct-pix2pix model with a normal one, A must be the instruct-pix2pix model.")
- assert a.shape[1] == 9 and b.shape[1] == 4, f"Bad dimensions for merged layer {key}: A={a.shape}, B={b.shape}"
-
- theta_0[key][:, 0:4, :, :] = theta_func2(a[:, 0:4, :, :], b, multiplier)
- result_is_inpainting_model = True
+ if a.shape[1] == 8 and b.shape[1] == 4:#If we have an Instruct-Pix2Pix model...
+ theta_0[key][:, 0:4, :, :] = theta_func2(a[:, 0:4, :, :], b, multiplier)#Merge only the vectors the models have in common. Otherwise we get an error due to dimension mismatch.
+ result_is_instruct_pix2pix_model = True
+ else:
+ assert a.shape[1] == 9 and b.shape[1] == 4, f"Bad dimensions for merged layer {key}: A={a.shape}, B={b.shape}"
+ theta_0[key][:, 0:4, :, :] = theta_func2(a[:, 0:4, :, :], b, multiplier)
+ result_is_inpainting_model = True
else:
theta_0[key] = theta_func2(a, b, multiplier)
-
+
theta_0[key] = to_half(theta_0[key], save_as_half)
shared.state.sampling_step += 1
@@ -226,6 +232,7 @@ def run_modelmerger(id_task, primary_model_name, secondary_model_name, tertiary_ filename = filename_generator() if custom_name == '' else custom_name
filename += ".inpainting" if result_is_inpainting_model else ""
+ filename += ".instruct-pix2pix" if result_is_instruct_pix2pix_model else ""
filename += "." + checkpoint_format
output_modelname = os.path.join(ckpt_dir, filename)
|