SegMix: Segmind Mixture of Experts
A Framework to combine multiple Stable Diffusion XL models into a mixture of experts model. Functions simialar to mergekit's mixtral branch but for Stable Diffusion XL models.
Installation
pip install segmix
Usage
from segmix import SegMixPipeline
pipeline = SegMixPipeline("segmind/SegMix-v0", device = "cuda")
prompt = "cosmic canvas, orange city background, painting of a chubby cat"
negative_prompt = "nsfw, bad quality, worse quality"
img = pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
height=1024,
width=1024,
num_inference_steps=25,
guidance_scale=7.5,
).images[0]
img.save(f"image.png")
Creating your Own Model
Create a yaml config file, config.yaml, with the following structure:
base_model: Base Model Path, Model Card or CivitAI Download Link
num_experts: Number of experts to use
moe_layers: Type of Layers to Mix (can be "ff", "attn" or "all"). Defaults to "attn"
experts:
- source_model: Expert 1 Path, Model Card or CivitAI Download Link
positive_prompt: Positive Prompt for computing gate weights
negative_prompt: Negative Prompt for computing gate weights
- source_model: Expert 2 Path, Model Card or CivitAI Download Link
positive_prompt: Positive Prompt for computing gate weights
negative_prompt: Negative Prompt for computing gate weights
- source_model: Expert 3 Path, Model Card or CivitAI Download Link
positive_prompt: Positive Prompt for computing gate weights
negative_prompt: Negative Prompt for computing gate weights
- source_model: Expert 4 Path, Model Card or CivitAI Download Link
positive_prompt: Positive Prompt for computing gate weights
negative_prompt: Negative Prompt for computing gate weights
For detailed information on how to create a config file, please refer to the Config Parameters
Note Both Huggingface Models and CivitAI Models are supported. For CivitAI models, paste the download link of the model, For Example: "https://civitai.com/api/download/models/239306"
Then run the following command:
segmix config.yaml segmix_v0
This will create a folder called segmix_v0 with the following structure:
├── model_index.json
├── scheduler
│ └── scheduler_config.json
├── text_encoder
│ ├── config.json
│ └── model.safetensors
├── text_encoder_2
│ ├── config.json
│ └── model.safetensors
├── tokenizer
│ ├── merges.txt
│ ├── special_tokens_map.json
│ ├── tokenizer_config.json
│ └── vocab.json
├── tokenizer_2
│ ├── merges.txt
│ ├── special_tokens_map.json
│ ├── tokenizer_config.json
│ └── vocab.json
├── unet
│ ├── config.json
│ ├── diffusion_pytorch_model.safetensors
│ └── segmix_config.json
└──vae
├── config.json
└── diffusion_pytorch_model.safetensors
Alternatively, you can also use the following command to create a mixture of experts model:
from segmix import SegMixPipeline
pipeline = SegMixPipeline("config.yaml", device="cuda")
pipeline.save_pretrained("segmix_v0")
Advantages
- Benefits from The Knowledge of Several Finetuned Experts
- Training Free
- Better Adaptability to Data
Limitations
- This is a very early version of the framework and is not yet optimized for speed.
- The framework is not yet optimized for memory usage.
Research Roadmap
- Optimize for Speed
- Optimize for Memory Usage
- Add Support for LoRAs
- Add Support for More Models
- Add Support for Training
Config Parameters
Base Model
The base model is the model that will be used to generate the initial image. It can be a Huggingface model card, a CivitAI model download link.
Number of Experts
The number of experts to use in the mixture of experts model. The number of experts must be greater than 1.
MOE Layers
The type of layers to mix. Can be "ff", "attn" or "all". Defaults to "attn"
Experts
The experts are the models that will be used to generate the final image. Each expert must have a source model, a positive prompt and a negative prompt. The source model can be a Huggingface model card, a CivitAI model download link. The positive prompt and negative prompt are the prompts that will be used to compute the gate weights for each expert.
Citation
@misc{segmix,
author = {Yatharth Gupta, Vishnu V Jaddipal, Harish Prabhala},
title = {SegMix: Segmind Mixture of Experts},
year = {2024},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/segmind/segmix}}
}
Release files for segmix 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| segmix-0.0.1.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| segmix-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:19.8 kB
Release files / segmix-0.0.1.tar.gz
| Download URL | segmix-0.0.1.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9debc2a91ae88e6e30132176bc16a882e8c45835cd9736c50f0dfc33f4b20fb8
|
|
BLAKE2b-256 checksum How to use checksums |
b3a223428b3fc3819e22c698c6b4cda338c7742540925cb221144a5b0827b11c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Release files / segmix-0.0.1-py3-none-any.whl
| Download URL | segmix-0.0.1-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b17b0147db74b94eec70d705525b28100f468426bf13a36f690d0df9cf3c045
|
|
BLAKE2b-256 checksum How to use checksums |
a8d47b4e6b3d9f01defd03054ce18b003175236298824a3182c85f8af2da693d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|