ComfyUI-ModelUtils Introduction
ComfyUI-ModelUtils is a collection of custom nodes for working with model files inside ComfyUI. It helps you inspect what a file contains, rename or remove parts of it, combine models, extract a LoRA from two models, and convert a diffusion model’s numerical format.
These tools are useful when you want to understand a model before using it, prepare files for a particular workflow, or experiment with how two models blend. Some operations change or create model files, so keep your originals when trying a new setting.
How ComfyUI-ModelUtils Works
A model file contains many named pieces of data called tensors. You can think of the names, or keys, as labels on drawers: they help a tool find the right piece of a model. ComfyUI-ModelUtils lets you inspect those labels and, depending on the node, change which pieces are used or how they are combined.
For example, a merger can blend two or three models using a chosen blend mode and ratio. A layer filter can limit an operation to named parts of a model. LoRA extraction compares a pair of models and creates an adapter representing their differences; its rank settings control how that difference is represented. These operations work on model data, so their settings affect the resulting file rather than directly editing an image.
ComfyUI-ModelUtils Features
- MetaKeys: Displays metadata and tensor keys from a model file. Use it to see what a file contains before choosing names for a filter or a key-editing operation.
- RenameKeys: Renames multiple tensor keys using pattern matching. This is for changing the names assigned to model data, not for renaming the model file itself.
- PruneKeys: Removes unwanted keys or layers from a model. Check your selection carefully: a broad pattern could remove more than you intended.
- Mergers: Combine two or three models with configurable blend modes and ratios. Changing the ratio changes how much each input contributes; filters and per-layer settings can make the blend more selective.
- LoRA Extraction: Extracts a LoRA adapter from a pair of models. Rank-selection methods include Fixed, Ratio, Quantile, Knee-detection, and Frobenius-norm. These offer different ways to decide how much detail the extracted adapter retains.
- Diffusion Model Dtype Conversion: Streams a diffusion model to fp32, fp16, or bf16, while preserving the numerical formats of excluded tensors. This lets you choose a target format without forcing every excluded part of the model to change.
Choosing Layers to Process
Nodes with an exclude_patterns or skip_patterns field also have an include_mode toggle, which is off by default.
With include_mode off, the field follows that node’s usual exclusion or skip behavior. Turn include_mode on to process only layers matching the pattern in that same field. The field keeps its existing pattern syntax, which may be a regular expression or a glob depending on the node. An empty include filter selects nothing.
What happens to layers that do not match depends on the operation:
- Pattern-exclusion mergers, resize nodes, and conversion nodes preserve the source or anchor layer.
- Analysis and extraction nodes omit nonmatching layers from the operation.
- LoRA Merge to Model keeps its existing skip behavior: nonmatching base tensors are omitted from the saved model, although guarded low-bit base tensors are always preserved. Its filter accepts regular expressions only.
Where a discard_patterns setting is available, it still takes precedence. Before saving a result, check both your filter and the node’s behavior for layers it does not select.
Setting Different Values for Different Layers
Connect Layer Parameter Configuration to the layer_parameters input on a standard two- or three-input merger, an extraction node, or a LoRA resize node. This lets you assign settings to particular layers instead of using the same value everywhere.
For example, a fixed-extraction rule can be written as:
(blocks\.4[589]\.attn\.qkv_proj) a:64 b:32 c:0.99 d:0
The pattern identifies the target layers; the lettered values set parameters for those layers. Short aliases and full parameter names are supported, with either spaces or commas between assignments. Read the configurator’s documentation output for the meaning and allowed range of each parameter for the method you are using.
Only values you explicitly assign override the receiving node’s settings. Its other settings and filters continue to apply. Overlapping rules, or rules that match no target layer, fail before streaming or writing. For LoRAs, patterns match normalized logical layer names rather than individual factor or alpha suffixes.
ComfyUI-ModelUtils Models
ComfyUI-ModelUtils does not provide a list of bundled models. Its nodes work with model-file types named in the original documentation: Models, TextEncoders, LoRAs, Checkpoints, and Embeddings. The file types and node settings determine what you can inspect or modify; there is no separate ComfyUI-ModelUtils model to select for each task.
Troubleshooting ComfyUI-ModelUtils
A filter processes no layers
- Check whether
include_modeis on. With that setting enabled, an empty filter selects nothing. - Inspect the file with MetaKeys to see its actual tensor keys.
- Check whether the node expects a regular expression or a glob. LoRA Merge to Model uses regular expressions only.
- If you are filtering a LoRA, match its normalized logical layer names, not separate factor or alpha suffixes.
A per-layer rule fails before a file is written
- Check for rules whose patterns overlap.
- Use the configurator’s documentation output to check parameter names and bounds.
- Compare your pattern against the target layers; a rule that matches no layer will fail.
- Try a narrower pattern, then add further rules one at a time.
The saved result does not contain every layer from the input
- Review
include_mode,exclude_patterns,skip_patterns, and anydiscard_patterns. - Check the specific node’s treatment of nonmatching layers. Some operations preserve them; analysis and extraction omit them.
- For LoRA Merge to Model, remember that nonmatching base tensors are omitted from the saved model, except for guarded low-bit base tensors.
Frequently asked questions
Does turning on include_mode simply reverse an exclusion filter?
It makes matching layers the ones processed, but the treatment of nonmatching layers still depends on the node. Check the behavior described under “Choosing Layers to Process.”
Do per-layer rules replace all of a node’s settings?
No. Only the values explicitly assigned by a matching rule override the receiving node. Other settings and filters remain in effect.
Which LoRA extraction rank method should I choose?
The extension offers Fixed, Ratio, Quantile, Knee-detection, and Frobenius-norm methods. The provided documentation does not prescribe one method for a particular artistic goal. Start with the method whose controls you understand, consult the configurator’s documentation output, and compare results using the same model pair.
Learn More about ComfyUI-ModelUtils
The example workflows show how nodes are connected for common tasks:
| Workflow | Preview | Workflow file |
|---|---|---|
| Inspect metadata and keys | Get Meta and Keys | GetMetaAndkeys.json |
| Explore LoRA extraction nodes | LoRA Extraction Nodes | LoRA_Extract_nodes.json |
| Explore model merging | Merging Examples | Merging_Examples.json |
| Rename model keys | Rename Keys in Model | RenameKeysInModel.json |
For background on the work referenced by the author’s LoRA extraction functionality, see kohya-ss/sd-scripts, LyCORIS, and kohya_ss. For usage terms, see the project’s LICENSE.
