LoRA Merge Formula
Control the merge order instead of a flat one-shot blend
- lora_stack
- lora_stack
By default, LoRA Optimizer treats a stack as one flat merge - every LoRA gets analyzed and resolved against every other LoRA at once. Most of the time that's fine. But sometimes the order you'd merge things in genuinely matters: you want two closely related LoRAs blended into a clean base first, and only then have a third, more disruptive LoRA layered on top of that already-settled result, rather than all three fighting for resolution simultaneously. That's what this node is for - it attaches a hierarchical merge order to your stack instead of leaving it flat.
How it works
It's a passthrough, not a merge node itself - it doesn't touch the actual LoRA tensors. It attaches formula metadata to the stack, and it's the downstream Optimizer that reads and acts on that metadata during the actual merge. The formula syntax uses 1-indexed positions matching your stack order, + to combine, and parentheses to group sub-merges: (1+2) + 3 means merge LoRAs 1 and 2 together first, then blend that combined result with LoRA 3 - rather than resolving all three as one flat three-way conflict. You can also weight the components: (1+2):0.6 + 3:0.4 weights the (1+2) group at 0.6 against LoRA 3's 0.4 in the final blend.
An empty formula (the default) falls back to a normal flat merge of the whole stack - so adding this node with nothing typed in changes nothing.
The inputs and outputs that matter
lora_stack(required) - the stack to attach a formula to. Position numbers in your formula refer to this stack's order.formula(default empty string) - the hierarchical merge expression. Leave empty for the normal flat merge.
Output: lora_stack - the same tensors, unchanged, with formula metadata attached. Feed it onward to LoRA Optimizer as you normally would.
How to install it
ComfyUI Manager: search "LoRA Optimizer", install, restart. Manually:
cd ComfyUI/custom_nodes/
git clone https://github.com/ethanfel/ComfyUI-LoRA-Optimizer.git
Restart - nodes appear under loaders. No downloads; this node only attaches metadata to a stack you've already built.
Common issues & troubleshooting
Position numbers don't match what you expect. The formula refers to 1-indexed positions in the stack as it arrives at this node - if you've chained multiple LoRAStack nodes together, or reordered things upstream, double-check what position each LoRA actually landed at before writing a formula that assumes a specific order.
Formula seems to have no effect. If formula is left empty, this node is a no-op by design - you get the normal flat merge. Make sure you've actually typed an expression, and that this node sits between your LoRA Stack and LoRA Optimizer in the graph, not off to the side disconnected from the main chain.
Unsure whether you actually need this. If your stack is two or three LoRAs of roughly equal importance, a flat merge (no formula at all) is usually the right call - the per-prefix adaptive merge already handles most conflict resolution well without hierarchy. Reach for a formula specifically when you want a clean two-LoRA base established before a third, more disruptive LoRA gets layered on, or similar deliberately staged combinations.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| lora_stack | LORA_STACK | The LoRA stack to apply the merge formula to. | |
| formula | STRING | Merge formula defining hierarchical merge order. Numbers reference 1-indexed LoRA positions in the stack. Use + to combine and () to group sub-merges. Example: '(1+2) + 3' merges LoRAs 1 & 2 first, then blends with 3. Optional weights: '(1+2):0.6 + 3:0.4'. Leave empty for default flat merge. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| lora_stack | LORA_STACK | — |