Skip to main content

Package for Mixing Stable Diffusiion XL Models by Segmind

Project description

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}}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

segmix-0.0.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

segmix-0.0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file segmix-0.0.1.tar.gz.

File metadata

  • Download URL: segmix-0.0.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for segmix-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9debc2a91ae88e6e30132176bc16a882e8c45835cd9736c50f0dfc33f4b20fb8
MD5 c13846ffc819697def145407d5f48b92
BLAKE2b-256 b3a223428b3fc3819e22c698c6b4cda338c7742540925cb221144a5b0827b11c

See more details on using hashes here.

File details

Details for the file segmix-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: segmix-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for segmix-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b17b0147db74b94eec70d705525b28100f468426bf13a36f690d0df9cf3c045
MD5 3380512febb2d4e0677484d612de9a4f
BLAKE2b-256 a8d47b4e6b3d9f01defd03054ce18b003175236298824a3182c85f8af2da693d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page