# How the AUTOMATIC1111 Checkpoint Merger Combines Stable Diffusion Models

> Discover how the AUTOMATIC1111 checkpoint merger combines Stable Diffusion models by interpolating tensor weights. Learn about weighted sum and add difference techniques for custom model creation.

- Repository: [AUTOMATIC1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui)
- Tags: internals
- Published: 2026-02-24

---

**The AUTOMATIC1111 checkpoint merger creates new Stable Diffusion models by mathematically interpolating the tensor weights of two or three source checkpoints using methods like weighted sum or add difference.**

The AUTOMATIC1111 checkpoint merger is a native utility within the stable-diffusion-webui repository that enables users to synthesize hybrid AI art models without external tools. Operating entirely in Python, it utilizes the same model loading pipeline as standard inference and exposes several blending strategies to control how source checkpoints combine into a new file.

## Core Interpolation Methods

The merger supports three distinct mathematical approaches for combining model weights, selectable via the **Interpolation Method** radio buttons in the UI.

### Weighted Sum

**Weighted sum** performs linear interpolation between model tensors using the formula `merged = (1-M)·A + M·B`, where **M** represents the multiplier slider value ranging from `0.0` to `1.0`. When merging three models (A, B, and C), the system applies similar proportional blending across all three state dictionaries. This method produces smooth transitions between model characteristics, with values closer to `0.0` preserving primary model traits and values near `1.0` emphasizing secondary model features.

### Add Difference

**Add difference** implements the formula `merged = A + M·(B-A)`, effectively capturing the stylistic or structural delta between two models and applying it to a base model. This technique is particularly effective for injecting specific artistic styles or subject modifications while preserving the core knowledge and composition abilities of the primary checkpoint.

### No Interpolation

Selecting **No interpolation** simply copies the primary model (A) without mathematical blending. This option serves utility purposes such as converting checkpoint formats, stripping or injecting metadata, or baking a VAE directly into the weights without altering the underlying model behavior.

## Architecture and Source Code Implementation

The checkpoint merger architecture separates concerns between the Gradio-based user interface and the backend tensor manipulation logic.

### UI Layer: UiCheckpointMerger

The frontend interface is defined in **[`modules/ui_checkpoint_merger.py`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/main/modules/ui_checkpoint_merger.py)**, where the **`UiCheckpointMerger`** class constructs dropdown selectors for the primary, secondary, and optional tertiary models. This component renders the multiplier slider, interpolation method radio buttons, and post-processing checkboxes for half-precision and metadata handling. When users click the **Merge** button, the UI invokes a thin wrapper function that forwards all parameters to the backend processing queue.

### Backend Logic: run_modelmerger

The core merging algorithm resides in **[`modules/extras.py`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/main/modules/extras.py)** within the **`run_modelmerger`** function starting at line 88. This function executes the following sequence:

1. **Model Loading**: Calls `sd_models.checkpoint_tiles()` to enumerate available checkpoints, then loads selected models using `sd_models.load_model()` to retrieve their state dictionaries.
2. **Tensor Interpolation**: Iterates through every key in the source state dictionaries, applying the selected mathematical formula (weighted sum or add difference) to combine tensor values. The system handles missing keys according to the *discard_weights* filter parameter.
3. **Post-Processing**: Optionally casts tensors to `torch.float16` if **half-precision** is enabled, embeds VAE weights under the `"vae"` key when baking is requested, and constructs a JSON metadata block documenting the merge recipe.
4. **Persistence**: Invokes `sd_models.save_checkpoint()` to write the resulting state dictionary to disk in either `.ckpt` or `.safetensors` format, including the generated metadata and copied configuration files.

The function is wrapped with `call_queue.wrap_gradio_gpu_call` to ensure GPU operations execute safely without blocking the WebUI interface.

## Practical Implementation Example

You can invoke the merger programmatically using the same API that powers the UI:

```python
from modules import extras, sd_models

# Model names must match entries in the checkpoint dropdown

primary = "sd15.ckpt"
secondary = "wd-1.4.ckpt"

# Execute weighted sum merge with 30% influence from model B

extras.run_modelmerger(
    id_task=None,
    primary_model_name=primary,
    secondary_model_name=secondary,
    tertiary_model_name="",           # Empty for two-way merge

    interp_method="Weighted sum",
    multiplier=0.3,
    save_as_half=False,
    custom_name="sd15+wd-1.4-0.3",
    checkpoint_format="safetensors",
    config_source="A",
    bake_in_vae="None",
    discard_weights="",
    save_metadata=True,
    add_merge_recipe=True,
    metadata_json="{}"
)

```

This creates a new checkpoint in the `models/Stable-diffusion` directory containing the interpolated weights.

## Configuration and Post-Processing Options

Beyond core interpolation, the AUTOMATIC1111 checkpoint merger provides several output controls:

- **Save Format**: Choose between legacy `.ckpt` or modern `.safetensors` formats for the output file.
- **Half-Precision**: Store weights as `float16` to reduce file size by approximately 50% with minimal quality impact.
- **Metadata Handling**: Embed a reproducible *merge recipe* JSON block recording source model names, interpolation method, and multiplier values.
- **Config Source**: Copy the [`v1-inference.yaml`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/main/v1-inference.yaml) (or appropriate config) from model A, B, or C, or omit configuration entirely.
- **VAE Baking**: Permanently embed a VAE checkpoint into the merged model, eliminating the need for separate VAE loading during inference.

These options are exposed through the Gradio interface in [`modules/ui_checkpoint_merger.py`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/main/modules/ui_checkpoint_merger.py) and processed within the `run_modelmerger` function in [`modules/extras.py`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/main/modules/extras.py).

## Summary

- The **AUTOMATIC1111 checkpoint merger** combines Stable Diffusion models by interpolating tensor weights from source checkpoints.
- Three interpolation methods exist: **Weighted sum** for linear blending, **Add difference** for delta injection, and **No interpolation** for format conversion.
- Core logic resides in **[`modules/extras.py`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/main/modules/extras.py)** within the `run_modelmerger` function, while the UI is defined in **[`modules/ui_checkpoint_merger.py`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/main/modules/ui_checkpoint_merger.py)**.
- The merger supports **half-precision** storage, **VAE baking**, and **metadata preservation** for reproducible results.
- All operations utilize the existing `sd_models` loading infrastructure to ensure compatibility with the WebUI ecosystem.

## Frequently Asked Questions

### What file formats does the AUTOMATIC1111 checkpoint merger support?

The merger outputs checkpoints in either `.ckpt` (Pickle) or `.safetensors` formats, selectable via the **Checkpoint format** dropdown in the UI. Input models must be compatible Stable Diffusion checkpoints loadable by the WebUI's `sd_models.load_model()` function.

### How does the multiplier (M) value affect the merged model?

The **Multiplier** slider controls the interpolation strength between `0.0` and `1.0`. In **Weighted sum** mode, `0.0` returns the primary model unchanged while `1.0` returns the secondary model. Values between create proportional blends. In **Add difference** mode, the multiplier scales the magnitude of the difference being added to the base model.

### Can I merge three models simultaneously?

Yes, the merger supports three-way interpolation by selecting a **Tertiary model (C)** in the UI. In weighted sum mode, the system blends all three state dictionaries proportionally. The tertiary model field can be left empty for standard two-model merging.

### Where is the merged checkpoint saved?

Completed merges are saved to the `models/Stable-diffusion` directory within your WebUI installation using either the **Custom name** specified in the UI or an auto-generated filename. The `run_modelmerger` function in [`modules/extras.py`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/main/modules/extras.py) handles the final write operation via `sd_models.save_checkpoint()`.