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

Allow users to convert models to Instruct-pix2pix models by supporting merging Instruct-pix2pix models with regular ones in the merge tab #7240

Merged
merged 4 commits into from
Jan 28, 2023

Conversation

Unstackd
Copy link
Contributor

Describe what this pull request is trying to achieve.

This is a simple change which allows users to merge Instruct pix2pix models with normal models.

It's pretty useful for pix2pix because it lets you use the weighted difference trick to convert other models into InstructPix2Pix models in much the same way you can convert any model into an inpainting model.

So that means you can use pix2pix with other models like AnythingV3 or whatever.

This PR is a result of the conversation here: #7010 (comment)

Additional notes and description of your changes

All I did was replicate the same steps that webui already uses merging inpainting models so that it also works for pix2pix models.

The newly merged model has ".pix2pix" appended to the filename in order to conform with the way inpainting models are named and also to conform with how Klace's new pix2pix extension expects pix2pix models to be named.

Environment this was tested in

List the environment you have developed / tested this on. As per the contributing page, changes should be able to work on Windows out of the box.

  • OS: Windows
  • Browser: Chrome
  • Graphics card: NVIDIA GTX 980 TI

Screenshots or videos of your changes

Not applicable.

…h a normal model using weighted sum. Also removed bad print message that interfered with merging progress bar.
modules/extras.py Outdated Show resolved Hide resolved
modules/extras.py Outdated Show resolved Hide resolved
modules/extras.py Outdated Show resolved Hide resolved
…t pix2pix". Also changed extension to instrpix2pix at least for now.
@Unstackd Unstackd changed the title Allow users to convert models to pix2pix models by supporting merging pix2pix models with regular ones in the merge tab Allow users to convert models to Instruct-pix2pix models by supporting merging Instruct-pix2pix models with regular ones in the merge tab Jan 26, 2023
…instruct-pix2pix" for newly generated instruct pix2pix models.
@AUTOMATIC1111 AUTOMATIC1111 merged commit bea31e8 into AUTOMATIC1111:master Jan 28, 2023
@hamin
Copy link

hamin commented Feb 16, 2023

@Unstackd Thank you for adding this. I got latest version with your changes merged but am still not able to merge instrcut-pix2pix with a custom model. Note I've used the same method to merge my custom model with an inpaiting one.

Am I doing this incorrectly?

Thanks in advance!

Screenshot 2023-02-16 at 11 08 10 AM

@Unstackd
Copy link
Contributor Author

Am I doing this incorrectly?

The inputs in your screenshot look fine to me as far as I can tell. I know if you put the exact same thing in but with the Anything model as B it should work.

One thing that's suspicious: The error message looks consistent with what I think you would get if you had a version of webui that was prior to my merge. Are you sure you're running the most recent version? If you go to modules/extras.py you should see line 192 looking something like:

            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

wkpark added a commit to wkpark/sd-webui-supermerger that referenced this pull request Jun 23, 2023
wkpark added a commit to wkpark/sd-webui-supermerger that referenced this pull request Jun 23, 2023
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

Successfully merging this pull request may close these issues.

None yet

5 participants