Regex Weights
Per-key merge weights by pattern — block weights, but with regex instead of architecture
- recipe
- recipe_txt
Mecha Regex Weights is the "I want a different strength for these weights" node. Where Blocks Mecha Hyper gives you one weight per architecture block, this gives you weights per key pattern: write rules like pattern: weight, one per line, and every model key matching a pattern gets that weight when the merge runs. It's the general case of block weighting - instead of being stuck with the architecture's notion of "block," you can weight by anything you can express as a pattern. Merge attention blocks differently from the rest, boost the mid layer, treat all time_embed keys one way - that's the kind of control that used to mean writing a custom script.
Inputs
regex_weights- the rules, one per line,pattern: weight. The author's tooltip:<pattern>: <weight>. What counts as a pattern depends onregex_mode:simple(default) - the only special character is*, meaning "any number of characters."a*nmatchesalliteration.\*matches a literal*,\\a literal backslash. Perfect for people who flinch at regex.regex- full Python regex..*matches any number of characters. For real pattern power.
default- the weight for any key matching nothing (aFLOAT, default 0.0). This is your "everything else" value, so zeroing it out zeroes out unmatched keys - usually you want it set to the same strength as the rest of the blend.model_config- which key layout the patterns run against (17 configs, defaultsdxl-sgm). The patterns match keys in this layout.match_full_keys-false(default): a pattern matches if it covers part of a key.true: the pattern must cover the whole key start to finish.falseis the forgiving mode - you'll notice if a partial match catches more than you meant.regex_mode-simpleorregex, as above.
Outputs: recipe (the param MECHA_RECIPE) and recipe_txt (the STRING form of it - handy for seeing exactly what the patterns expanded to).
How it works
Patterns are matched against each key in the model config, in order; first match wins, and matched keys carry that weight into the merge's param slot (typically alpha). Because the result is a param recipe, it plugs into the same sockets as a Float - but with per-key variation instead of one flat number.
Install & gotchas
ComfyUI Manager → search mecha → Mecha Merge Node Pack, or:
cd ComfyUI/custom_nodes
git clone https://github.com/ljleb/comfy-mecha.git
pip install -r comfy-mecha/requirements.txt
Restart; only dependency is sd-mecha==1.1.7.
Where people get burned: the default of 0.0 is a trap - if you write patterns for a handful of keys and leave default at zero, every other key gets strength 0 and the merge collapses to almost nothing. Set default to your base strength first, then layer patterns over it. Second: patterns are matched against the keys as they appear in the chosen model_config - a pattern that worked for SDXL won't necessarily match the same semantic layer in a kohya-layout config, where keys are renamed. And in simple mode, remember only * is special; if you write what looks like regex and it silently matches everything, that's the mode doing its job. Use the recipe_txt output to verify what actually matched before running the full merge.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| regex_weights | STRING | one regex per line: <pattern>: <weight> <pattern>: <weight> | |
| default | FLOAT | 0.00-18446744073709550000–18446744073709550000 | — |
| model_config | COMBO | sdxl-sgm | 17 options: singleton-mecha, sdxl-supermerger_blocks, sdxl-sgm, sdxl-kohya_lycoris_lora, sdxl-kohya_kohya_lora, sdxl-kohya_but_diffusers_lycoris_lora, +11 |
| regex_mode | COMBO | simple | - simple: the only special character is *, which means to match any number of characters. For example, "a*n" will match "alliteration". \* matches * literally and \\ matches \ literally - regex: full python regex mode. for example, ".*" matches any number of characters |
| match_full_keys | BOOLEAN | false | - True: a pattern needs to cover a key from start to end to match it - False: a pattern only needs cover a part of a key to match it |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| recipe | MECHA_RECIPE | — |
| recipe_txt | STRING | — |