Nodes/ComfyUI-Rebase-LoRA/Rebase LoRA From Finetune
ComfyUI Node

Rebase LoRA From Finetune

Turn a finetune back into a LoRA

By srv1n·Created 6 months ago·Updated 6 months ago· 0
Rebase LoRA From Finetune
  • base_model
  • finetuned_model
  • base_clip
  • finetuned_clip
  • saved_lora
  • report
base_lora_name
save_relpathrebased/rebased_lora
rank16
layer_scope
rank_mode
output_mode
strength_model1.00
strength_clip1.00
save_dtype
bias_difftrue
clamp_quantile0.990
include_cliptrue
compute_deviceauto
svd_modeauto
cuda_svd_driverauto
lowrank_oversample16
lowrank_niter2

Somebody shares a finetune you love, and it's a 6 GB checkpoint. You don't want to host it, and honestly the model owner probably doesn't either. LoRA extraction is the classic middle ground - take the diff between a base and a finetune and compress it into a small adapter file. That's been a command-line trick for years. This node does it inside ComfyUI, with a twist: instead of base − finetune, it computes (base + source LoRA) − finetuned, then writes the result out as either a standard low-rank LoRA or an exact diff patch.

Why the twist matters: you often have a finetune and also know roughly which LoRA on a base produced it (or got you 90% there). Rebase lets you say "this finetune is really just base + that LoRA plus a small leftover" - and then package just the leftover, or the whole thing, as a file you can actually distribute. Think of it as cleaning up the residual between where the LoRA gets you and where the finetune actually is. It's the difference between "rebuild from scratch" and "subtract what you already have."

How it works

The node does three mechanical things, and the source is refreshingly honest about it:

  1. Loads your base_lora_name and applies it to base_model (and base_clip, if connected), honoring strength_model and strength_clip.
  2. For each selected weight, subtracts the finetuned_model's weight from the patched base's weight. The cheap part - pure tensor subtraction.
  3. Depending on output_mode, either writes those deltas verbatim or runs SVD to factor each delta into lora_up / lora_down factors plus an .alpha.

The expensive part is step 3. Standard LoRA output is inherently a low-rank approximation - the README doesn't sugarcoat it. full_diff_patch skips SVD entirely and writes exact .diff tensors, so it's both faster and lossless, just bigger. Bias deltas go out as .diff_b either way. It uses ComfyUI's own lora loading machinery under the hood, so there's nothing exotic to install.

The inputs that actually matter

There are a lot of widgets. Ignore most of them on your first run:

  • output_mode - standard (SVD LoRA, small) vs full_diff_patch (exact diff, fast). Your first call should almost certainly be full_diff_patch just to see the pipeline work.
  • layer_scope - original_lora_only keeps just the layers your source LoRA touches (default and usually what you want); all_compatible_weights tries to reproduce the entire target delta.
  • rank_mode - match_input_lora_when_possible reuses each source layer's rank; fixed forces one rank everywhere. rank is the fallback for fixed.
  • compute_device - GPU mainly helps standard mode. For full_diff_patch, CPU is fine.
  • save_relpath - where it lands inside your ComfyUI loras folder (rebased/…). If the file exists, it auto-increments with a _00001 suffix rather than overwriting.

Both outputs are strings: saved_lora is the path to the file it wrote, and report is a plain-text log of how many layers were processed, written as LoRA vs diff, skipped, or fell back to CPU. Wire saved_lora anywhere you'd show a path, or just read the report in the node's text display.

Installing it

No dependencies, no requirements.txt, nothing to download - it's a single Python file plus a tiny JS extension that adds right-click presets.

cd ComfyUI/custom_nodes
git clone https://github.com/srv1n/ComfyUI-Rebase-LoRA

Then restart ComfyUI. Or just search "Rebase LoRA" in ComfyUI Manager. Right-clicking the node gives you two handy presets: "Apply CPU exact patch preset" (fast + lossless) and "Apply CUDA speed preset" (standard mode with randomized SVD tuned for speed).

Where people get burned

The node validates that your LoRA loads keys onto the base, but it can't save you from a category error: base, source LoRA, and finetune must all be the same architecture family. Point an SDXL LoRA at an SD 1.5 base and it dies with "The selected LoRA did not load any keys" - that error is doing you a favor. Also remember the node uses the effective incoming weights, so if you feed it already-patched models, those patches quietly become part of the diff. And if the source LoRA was trained on a different base than the finetune, the leftover delta will be garbage - the whole thing hinges on "base + LoRA ≈ finetune" being roughly true to begin with.

One genuinely nice touch: svd_mode = lowrank uses randomized SVD, so you get tiny run-to-run numeric differences. The README calls the CPU fallback "instead of dying dramatically like a Victorian inventor." It's a small pack, but it behaves like someone actually runs it.

Categorymodel_merging/lora

Inputs (21)

NameTypeDefaultDescription
base_modelMODEL
finetuned_modelMODEL
base_lora_nameCOMBOThe source LoRA trained on top of the base model.
save_relpathSTRINGrebased/rebased_loraRelative path inside the ComfyUI loras folder. .safetensors is optional.
rankINT161–4096
layer_scopeCOMBOoriginal_lora_only keeps only layers touched by the source LoRA. all_compatible_weights tries to recreate the full target delta.
rank_modeCOMBOReuse the input LoRA layer rank when possible, or force one fixed rank for every extracted layer.
output_modeCOMBOstandard writes LoRA factors where possible. full_diff_patch writes exact diff tensors instead.
strength_modelFLOAT1.00-10–10
strength_clipFLOAT1.00-10–10
save_dtypeCOMBOTensor dtype used in the written safetensors file.
bias_diffBOOLEANtrueWhen enabled, bias deltas are written as .diff_b patches.
clamp_quantileFLOAT0.9900–1Symmetric clamp used before writing LoRA factors. Set to 0 or 1 to disable.
include_clipBOOLEANtrueAlso extract text-encoder deltas when clip inputs are connected.
compute_deviceCOMBOautoWhere to run subtraction and SVD. GPU mainly helps standard LoRA extraction; full_diff_patch is usually fine on CPU.
svd_modeCOMBOautoauto uses full SVD for most layers and randomized low-rank SVD only when the requested rank is much smaller than the matrix.
cuda_svd_driverCOMBOautoCUDA-only torch.linalg.svd driver. Leave on auto unless you are tuning speed/accuracy.
lowrank_oversampleINT160–512Extra rank budget used by randomized low-rank SVD in auto/lowrank mode.
lowrank_niterINT20–16Power iterations for randomized low-rank SVD. Higher is slower but usually more accurate.
base_clipoptCLIP
finetuned_clipoptCLIP

Outputs (2)

NameTypeDescription
saved_loraSTRING
reportSTRING