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
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 Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
finetuned | MULTITYPE | Yes | - | - | The finetuned model or clip to extract LoRA from. |
original | MULTITYPE | Yes | - | - | The original base model or clip to diff against. |
Control Parameters (Parameters)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
lora_type | COMBO | Yes | standard | "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). |
algorithm | COMBO | Yes | svd_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_dtype | COMBO | Yes | fp16 | "fp16", "bf16", "fp32" | The precision for saving the extracted LoRA weights: fp16, bf16, or fp32. |
filename_prefix | STRING | Yes | loras/ComfyUI_extracted_lora | - | Sets the save path and filename prefix for the output LoRA file. By default, it is saved in the loras/ directory. |
rank | INT | Yes | 64 | 1 - 4096 (step: 1) | The rank to use for standard LoRA, or maximum rank limit for adaptive methods. |
lowrank_iters | INT | Yes | 7 | 1 - 100 (step: 1) | The number of subspace iterations for the lowrank SVD algorithm. |
bias_diff | BOOLEAN | Yes | True | - | Whether to include the differences in the model's bias parameters when extracting LoRA. |
adaptive_param | FLOAT | Yes | 0.15 | 0.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_quantile | BOOLEAN | Yes | false | - | 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.
LoraExtractKJ Node Source Code Link
The LoraExtractKJ node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.