Nodes/Model Utility Toolkit/CWB Merge Text Encoders (2 Models)
ComfyUI Node

CWB Merge Text Encoders (2 Models)

Merge two CLIP text encoders with a consensus blend

By silveroxides·Created about a year ago·Updated about 24 hours ago· 14
CWB Merge Text Encoders (2 Models)
  • cwb_config
  • output_filename
  • documentation
  • cwb_report
execution_mode
model_a
model_b
cwb_presetbalanced_mean
mismatch_modeskip
output_filenamecwb_merged_2_text_encoder
save_dtype
process_device
exclude_patterns
discard_patterns
glob_patternsfalse
lazy_loadtrue
force_clear_cachetrue
override_dtypefalse

Text encoders don't get merged nearly as often as checkpoints or LoRAs, which is a shame, because the ones that come with the big models are quietly influential - the CLIP models in an SDXL checkpoint, or the T5/Qwen-style encoders in newer architectures, shape everything downstream of your prompt. If you have two fine-tuned text encoders and want one file with the strengths of both, this is the CWB merger that does it.

How it works

Same Consensus-Weighted Blending engine as the rest of the pack. Model A anchors: it supplies output metadata and anchors tensor names and shapes. Model B is the second equal-prior contributor. For each tensor, CWB computes an element-wise mean or median consensus, measures each model's cosine similarity to that consensus, rejects below-threshold contributors, powers and normalizes the surviving weights, and produces the weighted sum - with optional norm rescaling. No global ratio to dial; per-layer similarity is the weight. Text encoder tensors always keep their fixed coordinate alignment, so there's no alignment toggle to worry about - the layers line up by position, the way they should for an encoder with a fixed architecture.

The output is a text encoder file written to models/text_encoders, loadable with the CLIP Loader / Text Encoder Loader for your architecture. Missing or shape-incompatible tensors are handled by mismatch_mode - skip preserves the anchor, zeros inserts a zero contribution where possible, error aborts.

Inputs that matter

  • execution_mode - MERGE writes the file; DOCUMENTATION ONLY returns the CWB reference without loading anything.
  • model_a / model_b - the two text encoder files.
  • cwb_preset (default balanced_mean) - dense presets; robust_medn for a median consensus.
  • output_filename (default cwb_merged_2_text_encoder) - written to models/text_encoders.
  • 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; text encoders are small, so this matters less, but leave it on.
  • force_clear_cache (default on) - per-layer 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 a CLIP/Text Encoder Loader and wire it into your prompt conditioning as usual.

Why you'd reach for it

Prompt understanding is a real lever on output quality, and merging two encoders that each "get" different phrasing is a legitimate way to combine that. It's also the half of the pack that pairs with CheckpointModelAnalysis's CWB report - you can preview how the two encoders relate before committing disk space.

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). Keep ComfyUI current - the pack uses the newer extension API, and the CWB nodes are author-flagged experimental.

CategoryModelUtils/Merging

Inputs (15)

NameTypeDefaultDescription
execution_modeCOMBOMERGE writes a new safetensors file. DOCUMENTATION ONLY returns the CWB reference without loading or merging inputs.
model_aCOMBOPrimary contributor and preservation anchor. Supplies output metadata and anchors shared tensor names and shapes.
model_bCOMBOSecond equal-prior contributor. CWB derives its effective per-vector influence from consensus similarity.
cwb_presetCOMBObalanced_meanUse-case preset. Name suffixes expose alignment, consensus, norm rescaling, DSC, soft comfort bandpass, and prefix preservation. A connected CWB Config overrides it completely.
mismatch_modeCOMBOskipFor 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_filenameSTRINGcwb_merged_2_text_encoderFilename without extension. The result is atomically written to this model category under ComfyUI's models directory.
save_dtypeCOMBORequested dtype for generated floating tensors. Participating FP32 inputs keep a result FP32 unless Override Dtype is enabled.
process_deviceCOMBODevice used for per-layer FP32 CWB arithmetic. A CUDA out-of-memory error retries only the affected layer on CPU.
exclude_patternsSTRINGOne pattern per line. Matching layers are preserved from the anchor instead of merged. Uses regex unless Glob Patterns is enabled.
discard_patternsSTRINGOne pattern per line. Matching tensors or logical LoRA groups are omitted from the output. Uses regex unless Glob Patterns is enabled.
glob_patternsBOOLEANfalseInterpret exclude and discard entries as shell-style glob patterns instead of regular expressions.
lazy_loadBOOLEANtrueUse UEL low-memory loading so tensors are read and released per work unit instead of retaining the complete inputs in RAM.
force_clear_cacheBOOLEANtrueRun Python garbage collection and clear the CUDA allocator cache before each layer. Reduces retained memory but can substantially slow merging.
override_dtypeBOOLEANfalseForce generated tensors to save_dtype; guarded tensors and enabled 1D direct diffs are exempt.
cwb_configoptCWB_CONFIGOptional settings from CWB Custom Configuration. When connected, it completely overrides the selected preset.

Outputs (3)

NameTypeDescription
output_filename*
documentationSTRING
cwb_reportSTRING