ComfyUI Node

Prune LoRA Keys

Prune LoRA Keys — strip tensors out of a LoRA .safetensors file

By silveroxides·Created about a year ago·Updated 4 days ago· 14
Prune LoRA Keys
    • output_path
    lora_name
    keys_to_prune
    use_regexfalse
    output_filenamepruned_lora

    Loads a LoRA, removes whichever tensor keys you tell it to, saves the result as a new file. It's the same pattern silveroxides' ComfyUI-ModelUtils applies across embeddings, diffusion models, and text encoders, here targeting the file type most people in this pack actually reach for - a LoRA.

    Why you'd cut keys out of a LoRA. A few real reasons come up. Some LoRAs ship with both UNet and text-encoder keys bundled together, and if you only want the UNet side applied - or a stricter downstream loader only expects one or the other - pruning the unwanted half is a clean fix without needing to retrain anything. Other times a LoRA carries vestigial or duplicate keys from whatever pipeline produced it, and trimming them shrinks the file without touching what actually matters. Either way, this is a targeted edit, not a rebuild: the tensors you keep are untouched, byte for byte.

    How it works. Loads the LoRA named in lora_name, removes any tensor whose key matches an entry in keys_to_prune, writes a new .safetensors file. Your source file is never modified.

    Inputs that matter. lora_name picks the source from your loras folder. keys_to_prune is a multiline field - put the exact tensor names you want gone, one per line. use_regex switches from literal exact matching to regex, useful if you're cutting a whole family of keys sharing a prefix rather than typing each one out. output_filename defaults to pruned_lora. The single output, output_path, tells you where the result landed.

    Installing it. ComfyUI Manager, search "Model Utility Toolkit" - or cd ComfyUI/custom_nodes && git clone https://github.com/silveroxides/ComfyUI-ModelUtils, restart. No extra dependencies in the README; it works on LoRA files you already have.

    Know your key names before you prune. This pack ships a metadata/keys inspector for embeddings (Get Embedding Metadata & Keys), and given the shared naming pattern across its Keys category, there's likely a sibling for other file types too - check the same category in the node menu. If you can't find one, reading the safetensors JSON header directly (it's plain text, no code execution risk) will get you the real key names. Either way, guessing at keys_to_prune is a waste of a run: a mistyped or wrong key just matches nothing, silently, and your "pruned" file comes out identical to the original with no error to tell you why.

    What pruning can't fix. LoRAs are architecture-bound - a LoRA trained for one base model doesn't become compatible with a different one just because you removed some of its keys. Pruning is for cutting components you know you don't want out of a file that's otherwise the right one; it's not a repair tool for a fundamentally mismatched LoRA. If a LoRA isn't loading or isn't doing anything, check that it actually targets your checkpoint's architecture before reaching for this node.

    One execution quirk. This node isn't marked as a workflow output, so if output_path doesn't feed into something downstream - even just a Show Text node - ComfyUI's graph pruning can skip it entirely and the file never gets written, despite the save happening as a side effect rather than through the wire itself. Always connect the output before queuing.

    CategoryModelUtils/Keys

    Inputs (4)

    NameTypeDefaultDescription
    lora_nameCOMBO0 options:
    keys_to_pruneSTRING
    use_regexBOOLEANfalse
    output_filenameSTRINGpruned_lora

    Outputs (1)

    NameTypeDescription
    output_pathSTRING