Skip to content

leylahviolet/Violet-Model-Merge

Repository files navigation

πŸ’œ Violet Model Merge

A sophisticated, artist-friendly model merging toolkit for Stable Diffusion and Flux.1

Derived from Chattiori Model Merger by Chattiori

Version Python PyTorch CUDA

Violet Model Merge is a fast, deterministic checkpoint merger for Stable Diffusion (SD1.x/2.x/XL) and Flux.1 models. Built for AI artists who want precise control over model blending with an intuitive interface.


✨ Features

πŸš€ Multiple Merge Algorithms β€” 20+ sophisticated merge modes from simple weighted sums to advanced cosine structure blending
πŸ’» Interactive Notebook β€” Artist-friendly Jupyter interface with comprehensive documentation and clean error handling
πŸ“Š Metadata Editor β€” CSV-based SafeTensors metadata management for batch editing descriptions, authors, and tags
⚑ GPU Acceleration β€” CUDA support for faster merging of large models
πŸ›‘οΈ Robust Error Handling β€” Clear, friendly error messages with detailed logging
🎯 Deterministic Results β€” Consistent, reproducible merges every time
πŸ”§ Flexible I/O β€” Support for .safetensors, .ckpt, and multiple precision formats
πŸ“Š Progress Tracking β€” Real-time progress bars and status updates
🎨 VAE Integration β€” Seamless VAE baking and model pruning

Supported Merge Methods

Method Description Best For
WS (Weighted Sum) Linear interpolation between models Basic style blending
AD (Add Difference) Preserves structure while adding characteristics Advanced style transfer
SIG (Sigmoid) Smooth, non-linear blending curves Natural artistic transitions
DARE Experimental drop-and-rescale algorithm Novel model combinations
FREQ Frequency-domain convolution merging Technical fine-tuning
TIES Structured parameter combination Complex multi-model blends
And 15+ more... Including cosine, sparse, and geometric methods Every creative workflow

πŸš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/leylahviolet/Violet-Model-Merge.git
cd Violet-Model-Merge

# Install dependencies
pip install -r requirements.txt

Choose Your Interface

πŸ““ Interactive Notebook (Recommended)

Perfect for AI artists who want a guided, visual experience:

jupyter lab violet_merge.ipynb

For advanced users who prefer terminal workflows:

python lib/merge_model.py WS models "model_a.safetensors" "model_b.safetensors" --alpha 0.4

CSV-based SafeTensors metadata editing for batch operations:

jupyter lab metadata_manager.ipynb

πŸ“Š Metadata Management

The metadata manager notebook provides a powerful, user-friendly way to edit SafeTensors metadata in bulk using CSV files. Perfect for maintaining clean, consistent metadata across your entire model collection! πŸ’œ

🎯 Metadata Features

  • πŸ“€ Export to CSV β€” Extract metadata from models/VAEs into editable spreadsheets
  • ✏️ Easy Editing β€” Use Excel, Google Sheets, or any CSV editor you prefer
  • πŸ“₯ Safe Import β€” Apply changes back with automatic backups and validation
  • πŸ”’ Non-destructive β€” Original files are backed up before any changes
  • 🎯 Batch Processing β€” Edit hundreds of models at once efficiently

πŸš€ Quick Workflow

  1. πŸ“Š Export β†’ metadata_manager.ipynb creates editable CSV from your models
  2. ✏️ Edit β†’ Open CSV in your favorite editor, update descriptions, authors, tags
  3. πŸ’Ύ Import β†’ Apply changes back to your models with automatic validation

Example Use Cases

  • 🏷️ Bulk Tagging β€” Add consistent tags across model collections
  • πŸ‘€ Author Updates β€” Set proper attribution for all your models
  • πŸ“ Descriptions β€” Add detailed descriptions for better organization
  • πŸ”„ Version Control β€” Track model versions and modifications
  • 🧹 Cleanup β€” Standardize metadata formatting across collections

πŸ“‹ Requirements

Core Dependencies:

  • Python 3.8+ (3.12+ recommended)
  • PyTorch 2.0+ with CUDA support (optional but recommended)
  • safetensors for fast, secure model loading
  • diffusers for modern Stable Diffusion support

Optional Enhancements:

  • CUDA toolkit for GPU acceleration
  • Jupyter Lab for the interactive notebook experience

All dependencies are automatically installed via:

pip install -r requirements.txt

πŸ“ Project Structure

Violet-Model-Merge/
β”œβ”€β”€ πŸ“’ violet_merge.ipynb          # Main interactive notebook
β”œβ”€β”€ οΏ½ metadata_manager.ipynb      # CSV-based metadata editor
β”œβ”€β”€ οΏ½πŸ“ lib/                        # Core Python modules
β”‚   β”œβ”€β”€ merge_model.py             # Main merging engine
β”‚   β”œβ”€β”€ utils.py                   # Utility functions
β”‚   β”œβ”€β”€ metadata_csv.py            # Metadata management
β”‚   └── lora_bake.py              # LoRA integration
β”œβ”€β”€ πŸ“ models/                     # Your model files (.safetensors, .ckpt)
β”œβ”€β”€ πŸ“ vae/                        # VAE files for baking
β”œβ”€β”€ πŸ“„ pyproject.toml             # Modern Python packaging
β”œβ”€β”€ πŸ“„ CHANGELOG.md               # Version history and updates
└── πŸ“„ requirements.txt           # Python dependencies

🎨 Jupyter Notebook Usage (Recommended)

The interactive notebook provides the best experience for AI artists with guided examples, comprehensive documentation, and clean error handling.

Getting Started

  1. Launch Jupyter Lab:

    jupyter lab violet_merge.ipynb
  2. Configure Your Paths (First cell):

    # Set your model and VAE directories
    models_path = "../../ComfyUI/models/checkpoints"
    vae_path = "../../ComfyUI/models/vae"
    
    # Choose your models
    model_1 = "realistic_base.safetensors"
    model_2 = "anime_style.safetensors"
    vae_model = "anything-v4.0.vae.pt"
  3. Run Merges with Beautiful Progress Tracking:

    # Simple weighted merge
    result = run_merge(
        mode="WS",
        model0=model_1,
        model1=model_2,
        alpha=0.3,                        # 70% model_1, 30% model_2
        output_name="realistic_anime_blend"
    )

✨ Notebook Features

  • πŸ“š Comprehensive Documentation β€” Each merge method explained with when/why to use it
  • πŸ”§ Ready-to-Run Examples β€” Copy, paste, and customize for your models
  • πŸ“Š Clean Progress Tracking β€” Real-time updates without technical noise
  • πŸŽ›οΈ Easy Configuration β€” Set paths once, use everywhere
  • πŸ›‘οΈ Friendly Error Handling β€” Clear, non-blocking error messages
  • πŸ“ Detailed Logging β€” Full technical details saved to last_merge.log

Example Workflows

Basic Style Blending

# Blend two artistic styles
result = run_merge(
    mode="SIG",                          # Sigmoid for smooth blending
    model0="photoreal_base.safetensors",
    model1="artistic_style.safetensors", 
    alpha=0.25,                          # Subtle artistic influence
    output_name="photoreal_with_style"
)

Advanced 3-Model Structure Merge

# Preserve base structure, inject style and details
result = run_merge(
    mode="AD",                           # Add Difference
    model0="base_structure.safetensors", # Foundation model
    model1="style_details.safetensors",  # Style characteristics
    model2="fine_details.safetensors",   # Additional features
    alpha=0.3,                           # Style strength
    cosine0=True,                        # Preserve model0 structure
    memo="Complex artistic blend"
)

⚑ Command Line Usage

For advanced users who prefer terminal workflows and automation scripts.

Basic Syntax

python lib/merge_model.py <MODE> <model_path> <model_0> <model_1> [OPTIONS]

Quick Examples

Simple Weighted Merge

python lib/merge_model.py WS models "A.safetensors" "B.safetensors" \
  --alpha 0.45 --output merged_ws --save_safetensors --save_half

Cosine Structure Merge

python lib/merge_model.py WS models "A.safetensors" "B.safetensors" \
  --cosine1 --alpha 0.35 --output merged_cos1

3-Model Advanced Merge

python lib/merge_model.py AD models "A.safetensors" "B.safetensors" \
  --model_2 "C.safetensors" --alpha 0.25 --beta 0.15 --output merged_blend

GPU-Accelerated with VAE

python lib/merge_model.py SIG models "base.safetensors" "style.safetensors" \
  --alpha 0.4 --vae "vae.pt" --device cuda --output gpu_blend

Advanced Examples

Experimental DARE Merge

python lib/merge_model.py DARE models "A.safetensors" "B.safetensors" \
  --alpha 0.4 --beta 0.3 --seed 42 --output dare_experiment

Frequency-Band Blending

python lib/merge_model.py FREQ models "A.safetensors" "B.safetensors" \
  --model_2 "C.safetensors" --alpha 0.4 --output freq_blend

No Interpolation + Finetuning

python lib/merge_model.py NoIn models "FluxModel.safetensors" "dummy.safetensors" \
  --fine "2,0,1,0,0,5" --output flux_finetuned

Metadata Reading

python lib/merge_model.py RM models "A.safetensors" "dummy.safetensors" --output meta_dump

πŸ”§ Merge Methods Reference

Core Methods

  • WS (Weighted Sum): Basic linear interpolation
  • AD (Add Difference): A + (B - C) structure preservation
  • SIG (Sigmoid): Non-linear smooth blending
  • INV (Inverse Sigmoid): Reverse sigmoid curves

Advanced Algorithms

  • DARE: Drop and Re-scale experimental method
  • TIES: Task Interference-aware merging
  • FREQ: Frequency domain convolution
  • SPRSE: Sparse top-k parameter selection

Structure Control

  • Cosine: Preserve model structure while blending parameters
  • Tensors: Fine-grained layer-wise control
  • Block Weight: Precision control over UNet blocks

Special Operations

  • NoIn: No interpolation (finetuning only)
  • RM: Read metadata without merging
  • PINS: Pin specific parameters during merge

πŸŽ›οΈ Configuration Options

Alpha/Beta Blending

  • --alpha: Primary blend ratio (0.0 = model0, 1.0 = model1)
  • --beta: Secondary ratio for 3-model merges
  • --gamma: Tertiary ratio for complex algorithms

Structure Preservation

  • --cosine0, --cosine1, --cosine2: Preserve specific model structure
  • --use_dif_10, --use_dif_20, --use_dif_21: Reuse model diffs internally

Output Control

  • --output: Output filename (without extension)
  • --save_safetensors: Save in safetensors format
  • --save_half: Use fp16 precision
  • --save_quarter: Use fp8 precision (experimental)

Performance

  • ⚑ Optimized Execution β€” Dramatically faster processing with streamlined merge logic
  • πŸš€ Real Performance β€” 3-model merges complete in seconds, not hours
  • πŸ’Ύ Memory Efficient β€” Optimized for large model handling with reduced memory footprint
  • --device: Choose cpu/cuda/auto for processing
  • --vae: Bake VAE into the merged model
  • --prune: Remove unnecessary parameters

Performance Note: Version 1.2.1 includes major performance optimizations resulting in dramatically faster merge times. What used to take hours now completes in seconds! πŸŽ‰


VAE, Pruning & DTypes

  • VAE bake: --vae path/to/vae.safetensors replaces first_stage_model.*
  • Pruning: --prune (with --keep_ema) to slim the checkpoint; architecture-aware
  • DTypes: --save_half (fp16) is widely supported; --save_quarter (fp8) is experimental

πŸ“ Changelog

See CHANGELOG.md for detailed version history and updates.

Latest highlights:

  • ✨ v1.2.1 β€” Major performance boost! Optimized merge execution with dramatically faster processing
  • ✨ v1.2.0 β€” Interactive Jupyter notebook with artist-friendly interface
  • πŸ›‘οΈ v1.1.0 β€” Enhanced error handling and progress tracking
  • πŸ”§ v1.0.0 β€” Project restructure with modern packaging

πŸ™ Acknowledgments

The Violet Model Merge builds upon the incredible work of the open-source AI community. Special thanks to:

πŸ’œ Chattiori β€” Original Architect

The brilliant mind behind the core merging algorithms and mathematical foundations that make this tool possible

🌟 Core Contributors

  • eyriewow β€” Original merge-models architecture
  • hako-mikan β€” Advanced merge algorithms and cosine methods
  • lopho & arenasys β€” Model pruning techniques
  • idelairre β€” Geometric, Sigmoid, and Max merge implementations
  • s1dlx β€” Multiply Difference and Similarity Add Difference algorithms
  • bbc-mc β€” Block-weighted merging interface
  • martyn β€” DARE algorithm implementation
  • mlfoundations/wise-ft β€” Theoretical foundation for DARE method
  • LatteLeopard - Merge method descriptions

This project stands on the shoulders of giants. πŸ’œ


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Built with πŸ’œ by the AI art community β€” For artists, by artists

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •