| title | SDXL Model Merger |
|---|---|
| emoji | 🎨 |
| colorFrom | blue |
| colorTo | purple |
| sdk | gradio |
| sdk_version | 4.31.0 |
| app_file | app.py |
| pinned | false |
| license | mit |
- Python 3.8 or higher
- CUDA-compatible GPU (recommended) or CPU
- Approximately 100+ GB of free disk space
Create the following directory structure in your project:
asaas/
├── merge.py
├── models/
│ ├── juggernautXL_v8.safetensors
│ ├── realvisxlV40.safetensors
│ └── zavy_mix_xl.safetensors
└── requirements.txt
- In VS Code, open the terminal: Ctrl + ` (backtick)
- Run this command:
New-Item -ItemType Directory -Path "models" -Force-
Download the three models:
- Juggernaut XL v8: Download
juggernautXL_v8.safetensors - RealVisXL V4: Download
realvisxlV40.safetensors - ZavyMix XL: Download
zavy_mix_xl.safetensors
- Juggernaut XL v8: Download
-
Place all
.safetensorsfiles in themodels/folder you created -
Verify the files are there by running:
Get-ChildItem -Path "models" -Filter "*.safetensors"You should see all three models listed.
The requirements.txt file should contain:
torch>=2.0.0
safetensors>=0.4.0
Run in the VS Code terminal:
For GPU (CUDA 12.1):
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121; pip install safetensorsFor GPU (CUDA 11.8):
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118; pip install safetensorsFor CPU only:
pip install torch safetensorsVerify installation:
python -c "import torch; import safetensors; print('✓ All packages installed')"- Open terminal: Ctrl + `
- Ensure you're in the correct directory (should show
asaasin path) - Run the script:
python merge.py- Open
merge.pyin the editor - Click the
▶️ Run button (top right) - Output appears in terminal
- Press F5 to start debugging
- Select "Python" as the environment
- Monitor progress in Debug Console
To change the contribution of each model:
- Open
merge.pyin editor - Find the section marked
# ============ ADJUSTABLE WEIGHTS ============(around line 150) - Modify the weights:
MODELS_TO_MERGE = {
"juggernaut": ("juggernautXL_v8.safetensors", 0.55), # Change 0.55
"realvis": ("realvisxlV40.safetensors", 0.25), # Change 0.25
"zavymix": ("zavy_mix_xl.safetensors", 0.20), # Change 0.20
}Important: Weights should sum to approximately 1.0 (like 0.55 + 0.25 + 0.20 = 1.0)
Examples of other weight configurations:
- Equal merge:
0.33, 0.33, 0.34 - Focus on Juggernaut:
0.70, 0.15, 0.15 - Focus on RealVis:
0.30, 0.50, 0.20
When running successfully, you'll see:
============================================================
Stable Diffusion XL Model Merger
============================================================
Using device: cuda
Model Information:
------------------------------------------------------------
juggernaut: 55% weight
realvis: 25% weight
zavymix: 20% weight
============================================================
[1/3] Loading juggernaut...
Loading model: juggernautXL_v8.safetensors...
✓ Loaded 1000+ keys
...
[3/3] Saving merged model to merged_sdxl.safetensors...
✓ Successfully saved to models/merged_sdxl.safetensors
File size: XX.XX GB
============================================================
✓ Merge completed successfully!
============================================================
- First run: 15-30 minutes (includes model loading & processing)
- Subsequent runs: Similar timing (models are not cached)
- GPU merge: 5-15 minutes
- CPU merge: 30-60 minutes
Solution: Install safetensors
pip install safetensors --upgradeSolution: Check that:
- Models are in
models/folder - Filenames match exactly (case-sensitive)
- Run:
Get-ChildItem modelsto verify
Solution: Use CPU instead by editing merge.py:
self.device = "cpu" # Force CPUSolution: Check which device is being used:
- Look for "Using device: cuda" (good) or "Using device: cpu" (slow)
- For GPU, install correct CUDA toolkit matching your GPU
The merged model is saved to:
asaas/models/merged_sdxl.safetensors
You can then use this file with:
- Stable Diffusion WebUI
- Comfy UI
- InvokeAI
- Other SD tools that support SDXL
- ✅ Loads all 3 models with progress tracking
- ✅ Weighted sum merging algorithm
- ✅ Shape mismatch detection and safe skipping
- ✅ Progress reporting every 100 keys
- ✅ GPU acceleration with CUDA fallback
- ✅ Detailed error handling
- ✅ Output file size reporting
- Backup originals: Keep the original model files as backup
- Test weights: Try different weight combinations
- Monitor RAM: Watch Task Manager while merging
- GPU: Ensure GPU drivers are up to date for best performance
Created: 2025
Compatible with: Stable Diffusion XL (SDXL)