Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:AUTOMATIC1111 Stable diffusion webui Merge output options

From Leeroopedia


Knowledge Sources
Domains Model Precision, Checkpoint Merging, Model Optimization
Last Updated 2026-02-08 00:00 GMT

Overview

Merge output options govern the precision format, weight filtering, and VAE configuration applied to a merged model checkpoint before it is saved to disk.

Description

After the mathematical interpolation of model weights is complete, several post-processing decisions determine the final characteristics of the output checkpoint. These merge output options affect file size, inference performance, and compatibility.

FP16 vs FP32 precision: Neural network weights are stored as floating-point numbers. Full precision (FP32, 32 bits per value) preserves maximum numerical fidelity, while half precision (FP16, 16 bits per value) reduces file size by approximately 50% and can accelerate inference on hardware with native FP16 support. For diffusion model weights, FP16 typically introduces negligible quality loss because the weights are already within a well-behaved numerical range.

VAE baking: A Variational Autoencoder (VAE) is a separate component that decodes latent representations into pixel-space images. Baking a VAE into a checkpoint replaces the model's existing VAE weights with those from a specified external VAE file. This is commonly done to use community-preferred VAEs (e.g., the "ft-MSE" VAE) that produce sharper or more color-accurate outputs.

Weight filtering (discard_weights): Some checkpoint keys are unnecessary for inference or can cause issues during merging. A regex-based discard pattern allows users to strip specific weight keys from the output, such as EMA (Exponential Moving Average) weights or optimizer states that inflate file size without affecting generation quality.

Metadata preservation: When merging, users can choose whether to copy metadata fields from source models, add a machine-readable merge recipe, or inject custom JSON metadata. This supports traceability and community sharing.

Usage

Use merge output options when:

  • Reducing file size: Enable FP16 to halve the checkpoint size (from ~4GB to ~2GB for typical SD models) without meaningful quality loss.
  • Standardizing VAE behavior: Bake in a specific VAE to ensure consistent color reproduction and decoding quality regardless of the user's VAE settings.
  • Cleaning merged checkpoints: Discard EMA weights or training-specific keys that are not needed for inference.
  • Documenting merge provenance: Enable metadata saving with merge recipe to create an auditable record of how the checkpoint was produced.

Theoretical Basis

Floating-Point Precision Tradeoffs

The IEEE 754 floating-point formats differ in their representational capacity:

Format Bits Exponent Mantissa Range Precision
FP32 32 8 23 ~1e-38 to ~3e38 ~7 decimal digits
FP16 16 5 10 ~6e-8 to ~65504 ~3 decimal digits

For model weights that typically lie in the range [-1, 1] with magnitudes around 0.01-0.1, FP16 provides sufficient precision. The conversion is:

if tensor.dtype == float32:
    tensor_half = tensor.half()  # torch.float32 -> torch.float16

Key consideration: FP16 conversion should only be applied to weight tensors, not to integer tensors (e.g., position IDs) or tensors that may contain values outside the FP16 representable range.

VAE Baking

VAE baking performs a key-prefix replacement in the merged state dictionary:

for key in vae_state_dict:
    merged_state_dict["first_stage_model." + key] = vae_state_dict[key]

This overwrites the merged model's VAE weights with the specified VAE, effectively embedding the preferred decoder directly into the checkpoint file. The advantage is that the model becomes self-contained and does not depend on external VAE configuration at inference time.

Weight Filtering

Weight filtering applies a regular expression against all keys in the state dictionary:

regex = compile(discard_weights_pattern)
for key in state_dict:
    if regex.search(key):
        del state_dict[key]

Common patterns include discarding EMA weights (model_ema.*) and optimizer states that are artifacts of training.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment