Nodes/Model Utility Toolkit/TE DoRA Extract (Ratio)
ComfyUI Node

TE DoRA Extract (Ratio)

DoRA for text encoders, rank by ratio

By silveroxides·Created about a year ago·Updated about 24 hours ago· 14
TE DoRA Extract (Ratio)
    • output_path
    model_a
    model_b
    linear_ratio2.0
    conv_ratio2.0
    probe_offset32
    linear_max_rank128
    conv_max_rank128
    lazy_loadtrue
    force_clear_cachefalse
    chunk_large_layersfalse
    clamp_quantile0.99
    min_diff0.000
    mismatch_modeskip
    output_filenameextracted_te_lora
    save_dtypefp16
    devicecuda
    skip_patterns
    glob_skip_patternsfalse

    This is the ratio-flavored sibling of the TE DoRA extractors in ModelUtils: same DoRA trick, rank decided per layer by a ratio instead of a fixed number or a percentile. Keep every singular value above max(S) / ratio, decompose the direction, stash the magnitude in a dora_scale. If you already understand the LoRA Ratio node, this is that, with the DoRA difference step swapped in.

    Quick refresher on what changes with DoRA. Where LoRA extraction just computes A - B and decomposes the whole delta, the DoRA path rescales each row of the fine-tuned encoder to the base's row magnitude before subtracting. That separates the update into direction (what gets low-rank-decomposed) and magnitude (what gets saved as the per-layer dora_scale). So the output file has lora_A, lora_B, and dora_scale keys - the DoRA signature. Whether that's worth the extra moving parts is up to you; the community's DoRA enthusiasm cooled mostly because trained DoRAs don't stack like LoRAs do, but for distilling one specific delta the magnitude/direction split is a legitimate choice, not a gimmick.

    The inputs that matter

    • model_a / model_b - fine-tuned and base text encoders from models/text_encoders.
    • linear_ratio / conv_ratio - the rank threshold for linear/attention vs convolution layers, default 2. Higher values keep more singular values (a higher ratio lowers the cutoff, max(S) / ratio), so raise it for higher fidelity, lower it for a tighter, smaller file. Same kohya-style convention as the LoRA Ratio node.
    • linear_max_rank / conv_max_rank - hard caps (default 128) so no single noisy layer blows the rank up.
    • probe_offset - extra singular values sampled past the cap so the threshold decision sees a full-enough spectrum.
    • output_filename / save_dtype / device / lazy_load / force_clear_cache - the shared knobs: output name in your loras folder, save precision (fp16 default), compute device with per-layer CPU fallback on OOM, streaming memory.

    It's an output node; output_path tells you where the file landed.

    Install

    ComfyUI Manager → "Model Utility Toolkit", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/silveroxides/ComfyUI-ModelUtils
    cd ComfyUI-ModelUtils
    pip install -r requirements.txt
    

    Restart; it sits under ModelUtils/DoRA Extract (TE). The streaming dependency that actually matters is unifiedefficientloader.

    Gotchas

    Same family warnings: mismatch_mode: skip is the default, so a wrong base means a silently small, useless file. DoRA extraction runs the full SVD per layer, so budget minutes, not seconds. And if the resulting file loads but does nothing, suspect the loader before the extraction - dora_scale support is not universal across LoraLoaders. When in doubt, compare against the plain LoRA Ratio output: if it behaves better in your stack, that's your answer about whether DoRA was worth it for your use case.

    CategoryModelUtils/DoRA Extract (TE)

    Inputs (18)

    NameTypeDefaultDescription
    model_aCOMBOFinetuned Text Encoder model (A - B = LoRA)
    model_bCOMBOBase Text Encoder model (A - B = LoRA)
    linear_ratioFLOAT2.01–100Ratio threshold for linear layers; higher values retain more singular values.
    conv_ratioFLOAT2.01–100Ratio threshold for convolution layers; higher values retain more singular values.
    probe_offsetINT321–4096Extra singular values sampled beyond Max Rank for a reliable bounded rank decision.
    linear_max_rankINT1281–16384Maximum extracted rank for linear layers.
    conv_max_rankINT1281–16384Maximum extracted rank for convolution layers.
    lazy_loadBOOLEANtrueLow memory mode: load tensors from disk on demand
    force_clear_cacheBOOLEANfalseClear CUDA cache after each layer; slower but useful under severe VRAM pressure.
    chunk_large_layersBOOLEANfalseSplit large fused layers (QKV, MLP) into chunks
    clamp_quantileFLOAT0.990.5–1Clamp outlier singular values
    min_diffFLOAT0.0000–1Skip layers with max difference below this
    mismatch_modeCOMBOskipHandle missing or incompatible text-encoder tensors by skipping them, substituting zeros where supported, or aborting.
    output_filenameSTRINGextracted_te_loraOutput filename without extension, written under the ComfyUI LoRA directory.
    save_dtypeCOMBOfp16Data type used to save extracted text-encoder LoRA factors.
    deviceCOMBOcudaDevice used for per-layer extraction arithmetic; CUDA out-of-memory retries the affected layer on CPU where supported.
    skip_patternsSTRINGPatterns for layers to skip (regex or glob depending on glob_skip_patterns)
    glob_skip_patternsBOOLEANfalseWhen True, skip_patterns use glob syntax (* = any sequence, ? = any char, dots are literal). When False (default), patterns are Python regex matched as substrings.

    Outputs (1)

    NameTypeDescription
    output_path*