ComfyUI Extension: ComfyUI-Rebase-LoRA

Authored by srv1n

Created

Updated

0 stars

Run ComfyUI workflows without the setup

No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.

This custom node builds a new LoRA or patch file relative to a finetuned model, computing weight differences and writing results as standard LoRA or exact diff patch files.

Looking for a different extension?

Custom Nodes (1)

README

ComfyUI Rebase LoRA From Finetune

This custom node builds a new LoRA or patch file relative to a finetuned model.

It computes:

(base model + source LoRA) - finetuned model

and then writes the result back out as either:

  • a standard low-rank LoRA (output_mode = standard), or
  • an exact diff patch file (output_mode = full_diff_patch).

What changed in this version

This version adds several practical improvements:

  • proper .alpha tensors for standard LoRA output
  • canonical LoRA prefixes when available, instead of raw state-dict keys
  • selectable compute device (auto, cpu, cuda)
  • selectable SVD strategy (auto, full, lowrank)
  • CUDA SVD driver option for torch.linalg.svd
  • per-layer CUDA-to-CPU fallback on SVD failure or OOM
  • bias diffs now resolve against the corresponding weight prefix, so .diff_b keys load correctly
  • tuple-style loader targets are normalized in original_lora_only, improving compatibility with mapped/sliced patch keys
  • torch.inference_mode() / inference-style execution
  • passthrough of simple metadata like prompt, description, tool

Files

ComfyUI-Rebase-LoRA/
├── __init__.py
├── rebase_lora_node.py
├── README.md
└── js/
    └── rebase_lora_ui.js

Install

Copy the folder into:

ComfyUI/custom_nodes/ComfyUI-Rebase-LoRA

Then restart ComfyUI.

Node

Node name: Rebase LoRA From Finetune

Required inputs

  • base_model (MODEL)
  • finetuned_model (MODEL)
  • base_lora_name
  • save_relpath
  • rank
  • layer_scope
  • rank_mode
  • output_mode
  • strength_model
  • strength_clip
  • save_dtype
  • bias_diff
  • clamp_quantile
  • include_clip
  • compute_device
  • svd_mode
  • cuda_svd_driver
  • lowrank_oversample
  • lowrank_niter

Optional inputs

  • base_clip (CLIP)
  • finetuned_clip (CLIP)

Recommended workflow

CheckpointLoaderSimple (base)  ---- model ----┐
                                ---- clip  ---┤
                                               │
CheckpointLoaderSimple (finetune) ---- model --┼--> Rebase LoRA From Finetune
                                   ---- clip ---┤
                                               │
                            base_lora_name ----┘

If your source LoRA includes text-encoder weights, connect both clip inputs and leave include_clip = true.

Practical settings

Fastest exact patch export

output_mode    = full_diff_patch
compute_device = cpu

This skips SVD entirely. It is usually the best choice when you care more about speed and fidelity than file size.

Smaller standard LoRA, safe default

layer_scope    = original_lora_only
rank_mode      = match_input_lora_when_possible
output_mode    = standard
compute_device = auto
svd_mode       = auto

This keeps the output focused on the layers touched by the source LoRA and uses GPU only when available.

Push speed on a CUDA box

output_mode       = standard
compute_device    = cuda
svd_mode          = auto
cuda_svd_driver   = auto
lowrank_oversample= 16
lowrank_niter     = 2

That is the reasonable performance preset. If CUDA SVD blows up on one layer, the node falls back to CPU for that layer instead of dying dramatically like a Victorian inventor.

Most faithful standard LoRA extraction

output_mode     = standard
compute_device  = auto
svd_mode        = full
cuda_svd_driver = auto

This stays with full SVD per layer, so it avoids randomized low-rank approximation.

Notes on performance

  • The cheap part is weight subtraction.
  • The expensive part is SVD / low-rank factorization.
  • full_diff_patch mostly needs memory bandwidth and disk I/O.
  • standard mode is where CUDA helps a lot, because the bottleneck is dense linear algebra.
  • svd_mode = lowrank or CUDA auto can be much faster when your requested rank is much smaller than the layer size, but it is an approximation path.

Save path behavior

  • save_relpath is relative to the first registered ComfyUI loras folder.
  • .safetensors is optional.
  • If the target filename already exists, the node increments it:
rebased/my_lora.safetensors
rebased/my_lora_00001.safetensors
rebased/my_lora_00002.safetensors

Output details

standard

Writes:

<prefix>.lora_up.weight
<prefix>.lora_down.weight
<prefix>.alpha

and bias diffs as:

<prefix>.diff_b

full_diff_patch

Writes:

<prefix>.diff

and optional bias diffs as:

<prefix>.diff_b

Caveats

  • A rebased LoRA is still a low-rank approximation unless you use full_diff_patch.
  • svd_mode = lowrank uses randomized low-rank SVD under the hood, so tiny numeric differences between runs are possible.
  • GPU acceleration is mainly useful for standard mode. For full_diff_patch, CPU is usually fine.
  • The node uses the effective incoming MODEL/CLIP weights. If you feed already-patched models into it, those patches become part of the source or finetuned side.
  • The JS extension adds a node context-menu action to auto-fill the save path from the selected LoRA name.

Run ComfyUI workflows without the setup

No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.

Learn more