KJNodes/loragenerated

LoraExtractKJ

This node supports multiple LoRA extraction modes, including standard fixed rank (standard), full rank (full), and various adaptive rank methods (adaptive_*), to accommodate different accuracy and file size requirements.

Lora Extract KJ

finetuned
original
filename_prefix
loras/ComfyUI_extracted_lora
rank
64
lora_type
COMBO
algorithm
svd_lowrank
lowrank_iters
7
output_dtype
fp16
bias_diff
adaptive_param
0.15
clamp_quantile
KJNodes

The LoraExtractKJ node supports multiple LoRA extraction modes, including standard fixed-rank (standard), full-rank (full), and various adaptive-rank methods (adaptive_*), to accommodate different precision and file size requirements.

The LoraExtractKJ node is a tool for extracting LoRA (Low-Rank Adaptation) weight files from the differences between a fine-tuned model and the original base model. Its core function is to analyze the parameter changes between the two models, compress these changes, and save them as independent, reusable LoRA files. This node does not output any data but directly saves the generated LoRA file to a specified directory.

Node Functionality

This node supports multiple LoRA extraction modes, including standard fixed-rank (standard), full-rank (full), and various adaptive-rank methods (adaptive_*), to accommodate different precision and file size requirements. Technically, it uses the Singular Value Decomposition (SVD) algorithm to compute a low-rank approximation of the weight matrices. Users can choose between the svd_linalg (precise but slower) or svd_lowrank (faster but approximate) algorithms. The extracted weights can be saved in fp16, bf16, or fp32 precision.

Node Parameter Description - LoraExtractKJ

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
finetunedMULTITYPEYes--The finetuned model or clip to extract LoRA from.
originalMULTITYPEYes--The original base model or clip to diff against.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
lora_typeCOMBOYesstandard"standard", "full", "adaptive_ratio", "adaptive_quantile", "adaptive_energy", "adaptive_fro"Full-rank (full) and four adaptive-rank methods (adaptive_ratio, adaptive_quantile, adaptive_energy, adaptive_fro).
algorithmCOMBOYessvd_lowrank"svd_linalg", "svd_lowrank"Select the algorithm used for Singular Value Decomposition (SVD). svd_linalg is more precise but slower, svd_lowrank is faster but approximate.
output_dtypeCOMBOYesfp16"fp16", "bf16", "fp32"The precision for saving the extracted LoRA weights: fp16, bf16, or fp32.
filename_prefixSTRINGYesloras/ComfyUI_extracted_lora-Sets the save path and filename prefix for the output LoRA file. By default, it is saved in the loras/ directory.
rankINTYes641 - 4096 (step: 1)The rank to use for standard LoRA, or maximum rank limit for adaptive methods.
lowrank_itersINTYes71 - 100 (step: 1)The number of subspace iterations for the lowrank SVD algorithm.
bias_diffBOOLEANYesTrue-Whether to include the differences in the model's bias parameters when extracting LoRA.
adaptive_paramFLOATYes0.150.0 - 1.0 (step: 0.01)For ratio mode, this is the ratio of the maximum singular value. For quantile mode, this is the quantile of the singular values. For fro mode, this is the Frobenius norm retention ratio.
clamp_quantileBOOLEANYesfalse-Controls whether to clamp singular values in adaptive quantile mode to improve numerical stability.

Usage Scenario

A typical usage scenario is when a user has performed personalized fine-tuning on a Stable Diffusion model using methods like Dreambooth. After fine-tuning, the user can connect the complete fine-tuned model and the original, unmodified base model to the node's two input ports. By configuring the extraction parameters, a lightweight LoRA file can be generated for quickly applying the same style or concept in other workflows.

The LoraExtractKJ node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…