CWB Merge Models (2 Models)
Merge two diffusion models (UNet/DiT) with a per-layer consensus blend
- cwb_config
- output_filename
- documentation
- cwb_report
This is the CWB merger for standalone diffusion models - the UNet or DiT files in models/diffusion_models, without the text encoder and VAE that a full checkpoint bundles in. If you're merging the denoiser alone, this is the node; if you want the whole checkpoint including encoders, use CWBCheckpointTwoMerger instead.
How it works
Same Consensus-Weighted Blending engine as the rest of the pack's CWB nodes. Model A is the anchor - output metadata, tensor name/shape anchoring, preservation reference. Model B is the second equal-prior contributor. For each tensor, the merger computes an element-wise mean or median consensus, measures each model's cosine similarity to that consensus, rejects contributors below the threshold, raises survivors to a power, normalizes the weights, and produces the weighted sum - then optionally rescales the result's norm to the participating average. There's no global alpha to dial; per-layer similarity is the weighting.
Because these are standalone diffusion models, the merge output lands in models/diffusion_models and gets loaded with a UNet Loader (or the DiffusionModel Loader), not a CheckpointLoader. That's the practical difference from the checkpoint variant: you're building the denoiser, and you still need a text encoder and VAE elsewhere in your workflow.
Inputs that matter
- execution_mode -
MERGEwrites the file;DOCUMENTATION ONLYreturns the CWB reference without loading or merging. - model_a / model_b - the two files. A anchors metadata and naming.
- cwb_preset (default
balanced_mean) - dense-model presets;robust_mednfor median consensus,strongdiv_medn_rn_dsc_softcbto push diversity hard. - mismatch_mode -
skippreserves the anchor,zerosinserts zero contributions,erroraborts for missing or incompatible tensors. - output_filename (default
cwb_merged_2_model) - written tomodels/diffusion_models. - save_dtype / override_dtype - fp32/fp16/bf16 for generated tensors.
- exclude_patterns / discard_patterns / glob_patterns - regex (or glob) lists; excludes preserve matching layers from the anchor, discards drop them from the output.
- lazy_load (default on) - UEL streaming, keep it on for multi-GB DiTs.
- force_clear_cache (default on) - per-layer cache flushing; memory-safe, slower.
- process_device - CUDA with per-layer CPU retry on OOM.
Outputs
output_filename (the written file), documentation (the CWB reference), and cwb_report (per-layer merge detail). Load the result with the model loader for your architecture.
Why you'd reach for it
The common scenario: you have two fine-tuned UNets (say, a realism-tuned Flux and a detail-calibrated variant) and you want the strengths of both in one file. Or you're doing the trendy thing - merging a base DiT with a style specialist - and you want per-layer adaptation instead of a fixed 50/50. Run DiffusionModelAnalysis on the pair first to preview the consensus math and see whether the merge is likely to be a clean union.
Install
Part of Model Utility Toolkit (silveroxides/ComfyUI-ModelUtils). ComfyUI Manager → search "Model Utility Toolkit", or:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-ModelUtils
Restart ComfyUI. Real dependency: unifiedefficientloader (UEL) for streaming. Keep ComfyUI current - the pack uses the newer extension API, and the CWB nodes are author-flagged as experimental.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| execution_mode | COMBO | MERGE writes a new safetensors file. DOCUMENTATION ONLY returns the CWB reference without loading or merging inputs. | |
| model_a | COMBO | Primary contributor and preservation anchor. Supplies output metadata and anchors shared tensor names and shapes. | |
| model_b | COMBO | Second equal-prior contributor. CWB derives its effective per-vector influence from consensus similarity. | |
| cwb_preset | COMBO | balanced_mean | Use-case preset. Name suffixes expose alignment, consensus, norm rescaling, DSC, soft comfort bandpass, and prefix preservation. A connected CWB Config overrides it completely. |
| mismatch_mode | COMBO | skip | For missing or incompatible anchored inputs: skip preserves the anchor, zeros inserts a zero contribution where possible, and error aborts. A lone secondary-only tensor is copied unchanged. |
| output_filename | STRING | cwb_merged_2_model | Filename without extension. The result is atomically written to this model category under ComfyUI's models directory. |
| save_dtype | COMBO | Requested dtype for generated floating tensors. Participating FP32 inputs keep a result FP32 unless Override Dtype is enabled. | |
| process_device | COMBO | Device used for per-layer FP32 CWB arithmetic. A CUDA out-of-memory error retries only the affected layer on CPU. | |
| exclude_patterns | STRING | One pattern per line. Matching layers are preserved from the anchor instead of merged. Uses regex unless Glob Patterns is enabled. | |
| discard_patterns | STRING | One pattern per line. Matching tensors or logical LoRA groups are omitted from the output. Uses regex unless Glob Patterns is enabled. | |
| glob_patterns | BOOLEAN | false | Interpret exclude and discard entries as shell-style glob patterns instead of regular expressions. |
| lazy_load | BOOLEAN | true | Use UEL low-memory loading so tensors are read and released per work unit instead of retaining the complete inputs in RAM. |
| force_clear_cache | BOOLEAN | true | Run Python garbage collection and clear the CUDA allocator cache before each layer. Reduces retained memory but can substantially slow merging. |
| override_dtype | BOOLEAN | false | Force generated tensors to save_dtype; guarded tensors and enabled 1D direct diffs are exempt. |
| cwb_configopt | CWB_CONFIG | Optional settings from CWB Custom Configuration. When connected, it completely overrides the selected preset. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| output_filename | * | — |
| documentation | STRING | — |
| cwb_report | STRING | — |