Nodes/ComfyUI_ExtractLora/Extract LoRA from Checkpoints
ComfyUI Node

Extract LoRA from Checkpoints

Turn a fine-tuned checkpoint into a LoRA — no training run required

By GavChap·Created 9 months ago·Updated 9 months ago· 1
Extract LoRA from Checkpoints
      model_a
      model_b
      rank64
      methodrsvd
      precisionfp16
      deviceauto
      save_nameextracted_lora
      oversamples10

      Ever looked at a 6 GB fine-tune you only like for one style and thought "I wish this was a LoRA"? That's exactly what this node does. Feed it two checkpoints - a base and a fine-tune of that base - and it computes the difference between their weights and squeezes that difference into a standard LoRA file, no GPU-hours of training involved. The math does the work instead.

      This is the "LoRA extraction" trick, and it's older than ComfyUI. A LoRA is just a low-rank approximation of a weight delta: freeze the base, patch on small matrices. Here the "training" is replaced by pure linear algebra - you already have a fine-tune, so the delta is known; you just have to compress it. The result is a 10-200 MB file instead of a multi-gigabyte checkpoint, and one you can apply to other bases at a weight you control.

      How it works

      The node (class ExtractLoRA, category Advanced/LoRA) opens both .safetensors files, normalizes the key prefixes (it strips the model.diffusion_model. prefix SD 1.5/SDXL checkpoints use), then walks every shared .weight tensor that isn't itself a LoRA key. For each one it computes delta = model_b - model_a, flattens anything with more than two dims (that's how Conv2d layers get handled), and runs SVD on the difference.

      The decomposition gives you lora_up and lora_down matrices - the standard LoRA format - which it writes out to a {save_name}.safetensors file in ComfyUI's output folder. It processes one layer at a time with safe_open, so a 12 GB pair of checkpoints never needs to fully fit in RAM.

      The inputs that matter

      Only three of the eight are things you'll actually touch most runs:

      • model_a / model_b - picked from your models/diffusion_models folder. model_a is the base, model_b is the fine-tune. That order matters: flip it and you extract a "reverse" LoRA.
      • rank - how much of the delta to keep, 1-1024, default 64. Higher rank = bigger file and closer to the original fine-tune; the default is a sane starting point.
      • method - rsvd (default) or svd. Randomized SVD is dramatically faster and, per the author, about 99% as good. Take that deal. Full SVD buys you a hair of precision for a lot of waiting.

      precision (default fp16), device (auto/cuda/cpu), save_name, and oversamples (10 by default, only consulted by rsvd) are mostly leave-alone. The node returns nothing and is an output node - its whole job is writing that file.

      Installing it

      No dependencies to chase. The pack is a single __init__.py that only uses torch, safetensors, and tqdm - all already present in any working ComfyUI install. No model downloads, no API keys, no pip step. Easiest path:

      cd ComfyUI/custom_nodes
      git clone https://github.com/GavChap/ComfyUI_ExtractLora
      

      then restart ComfyUI. Or, if you run ComfyUI Manager, search "ComfyUI_ExtractLora" and install from there. You'll find it in the node menu under Advanced/LoRA as "Extract LoRA from Checkpoints".

      Where people get burned

      • The file lands in ComfyUI/output, not models/loras. Move it into your loras folder before it appears in a LoraLoader. Easy to miss, mildly confusing when your fresh LoRA doesn't show up in the loader list.
      • Both checkpoints must be the same architecture. The node only processes keys shared by both files and skips any with mismatched shapes. An SDXL fine-tune and its SDXL base give you thousands of common keys; two unrelated models give you an error about no common processable keys.
      • It's built around the SD 1.5/SDXL key convention. The prefix handling and the diffusion_model. re-prefixing it writes back into the LoRA assume that layout. Flux-era architectures use a different key structure, so don't expect this to hand you a working Flux LoRA.
      • No alpha is written to the file. You get lora_up/lora_down and nothing else, so loaders fall back to alpha = rank, meaning the full delta applies at weight 1.0. Start at a lower weight and work up.

      It's a niche tool - the kind of thing you reach for once a month when you finally want to archive a checkpoint you've been hoarding. But for that job it's the fastest thing in the drawer: honest about what it does, no training loop, no surprise dependencies.

      CategoryAdvanced/LoRA

      Inputs (8)

      NameTypeDefaultDescription
      model_aCOMBO0 options:
      model_bCOMBO0 options:
      rankINT641–1024
      methodCOMBOrsvd2 options: rsvd, svd
      precisionCOMBOfp163 options: fp32, fp16, bf16
      deviceCOMBOauto3 options: auto, cuda, cpu
      save_nameSTRINGextracted_lora
      oversamplesoptINT100–100

      Outputs (0)

      No outputs