Giter Club home page Giter Club logo

merge-models's Introduction

Merge Models

This script combines two stable-diffusion models at a user-defined ratio.

The ratio works as follows:

  • 0.5 is a 50/50 mix of model0 and model1
  • 0.3 is a 70/30 mix with more influence from model0 than model1

Running it

Bat file Method for Windows Users

If you are using Windows and Automatics Webui, which I highly recommend, the easiest way to use this script is to use the .bat file.

  • Download this repo as a zip file
  • Extract the folder and place it in the main folder of your stable-diffusion install
    • Copy the two models you want to merge into the folder you just created
    • Run merge.bat
    • The .bat file should guide you through the merge process

Running merge.py Directly

If you aren't using Automatic's web UI or are comfortable with the command line, you can also run merge.py directly. Just like with the .bat method, I'd recommend creating a folder within your stable-diffusion installation's main folder. This script requires torch to be installed, which you most likely will have installed in a venv inside your stable-diffusion webui install.

  • Navigate to the merge folder in your terminal
  • Activate the venv
    • For users of Automatic's Webui use
      • ..\venv\Scripts\activate
    • For users of sd-webui (formerly known as HLKY) you should just be able to do
      • conda activate ldm
  • run merge.py with arguments
    • py merge.py model0 model1 --alpha 0.5 --output merged
      • Optional: --alpha controls how much weight is put on the second model. Defaults to 0.5, if omitted
      • Optional: --output is the filename of the merged file, without file extension. Defaults to "merged", if omitted
      • Optional: --device is the device that's going to be used to merge the models. Unless you have a ton of VRAM, you should probably just ignore this. Defaults to 'cpu', if omitted.
        • Required VRAM seems to be roughly equivalent to the size of (size of both models) * 1.15. Merging 2 models at 3.76GB resulted in rougly 8.6GB of VRAM usage on top of everything else going on.
        • If you have enough VRAM to merge on your GPU you can use --device "cuda:x" where x is the card corresponding to the output of nvidia-smi -L

Potential Problems & Troubleshooting

  • Depending on your operating system and specific installation of python you might need to replace py with python, python3, conda or something else entirely.

Credits

  • Thanks to Automatic and his fantastic Webui, I stole some of the code for the merge.bat from him.
  • I got the merging logic in merge.py from this post by r_Sh4d0w, who seems to have gotten it from mlfoundations/wise-ft

merge-models's People

Contributors

eyriewow avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.