ComfyUI Node

Lora

Merge a LoRA into a checkpoint with ComfyUI, no extra RAM

By ljleb·Created 2 years ago·Updated 29 days ago· 101
Lora
    • recipe
    model_path
    model_config

    You know how everyone's favorite trick for getting a character or style into a model is a LoRA? This node does the less common thing: it turns a LoRA into a merge ingredient so you can permanently bake it into a checkpoint. No more loading "style v3" on top of every generation - you merge it in once, save the checkpoint, and the result stands alone.

    The name "Recipe" is the whole point. A MECHA_RECIPE isn't a merged model; it's a lazy description of how to build one, tensor by tensor. Everything in the comfy-mecha pack (by ljleb, the same person behind the sd-mecha library) works this way, which is why it can merge a full SDXL on a machine that would choke on a classic merge. You chain recipe nodes together, and a single Mecha Merger executes the whole graph at the end.

    What it does

    Lora Mecha Recipe reads a LoRA file from your models/loras folder and produces a recipe output of type MECHA_RECIPE. Internally it converts the LoRA's lora_up/lora_down/lora_mid tensors into a delta - the difference the LoRA represents - expressed against the base model's key structure. That delta is exactly what merge methods like Add Difference want to consume.

    Two inputs, and really only one you'll touch:

    • model_path - the LoRA file, picked from whatever's in your loras folder.
    • model_config - leave on auto. The other choices (e.g. sdxl-kohya_kohya_lora, sd1-kohya_lycoris_lora) are there for files whose key naming the auto-detection can't resolve, like an SDXL LoRA that was trained with a diffusers-style layout. If auto fails, try the matching Kohya or Lycoris config for your base.

    You don't need a checkpoint loaded to do this. The node reads the safetensors header, not the whole file, so even a 200 MB LoRA costs almost nothing to bring into the recipe.

    Wiring it up

    Lora Mecha Recipe ──recipe──▶ Add Difference Mecha Recipe ──recipe──▶ Mecha Merger ──▶ MODEL / CLIP / VAE
    Model Mecha Recipe ──recipe──▶ (base input)
    

    The classic pattern: load your base checkpoint with Model Mecha Recipe, load the LoRA with this node, and feed both into Add Difference Mecha Recipe (which computes base + alpha * lora_delta). Set alpha to how strongly you want it baked in - 1.0 is a full bake. Then Mecha Merger executes the graph and hands you a MODEL, CLIP, and VAE you can save with the standard checkpoint-save nodes. All the merge recipes in this pack share a merge_checkpointing toggle that caches the branch on CPU in fp16 if you're iterating on the same inputs.

    Installing

    In ComfyUI Manager: search for mecha and install "Mecha Merge Node Pack". Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ljleb/comfy-mecha.git
    pip install -r comfy-mecha/requirements.txt
    

    Then restart ComfyUI. The only real dependency is sd-mecha==1.1.7; there are no model downloads. It works for SD1.5 and SDXL LoRAs out of the box - Flux is a different key structure, so don't expect cross-architecture magic.

    Gotchas

    • If the node throws an "unsupported lora model config" error, it's almost always a key-layout mismatch - switch model_config off auto before blaming the pack.
    • Architecture lock-in applies exactly as it does at inference: an Illustrious LoRA merges onto an SDXL base fine, but an SDXL LoRA onto Flux is nonsense. Same rule, just baked in.
    • Remember the output is a delta. If you wire a LoRA recipe straight into Mecha Merger without a base, the result won't be a usable model. The validation in sd-mecha usually catches this and tells you, which is more than most merge tools bother to do.
    Categorymecha

    Inputs (2)

    NameTypeDefaultDescription
    model_pathCOMBO0 options:
    model_configCOMBO7 options: auto, sdxl-kohya_lycoris_lora, sdxl-kohya_but_diffusers_lycoris_lora, sd1-kohya_lycoris_lora, sdxl-kohya_kohya_lora, sdxl-kohya_but_diffusers_kohya_lora, +1

    Outputs (1)

    NameTypeDescription
    recipeMECHA_RECIPE