Prune Checkpoint Keys
Strip unwanted tensors out of a checkpoint file
- output_path
A checkpoint file is a bag of tensors, and not every tensor in it earns its place. Training checkpoints sometimes ship with EMA weights alongside the regular ones, optimizer state that never should have been included in a distributable file, or components (a VAE, a CLIP tower) you don't need because you're loading those separately elsewhere. "Pruned" checkpoints - the term you'll see all over CivitAI download options - exist because stripping that dead weight can shrink a file meaningfully without touching image quality at all. This node is how you do that pruning yourself, on any checkpoint, instead of relying on someone else to have published a pruned version.
How it works
ckpt_name picks the source file. keys_to_prune is a multiline text field where you list what to remove. use_regex (default off) switches that field from literal exact-name matching to regex pattern matching - flip it on if you want to strip, say, every key matching .*\.ema\..* in one line instead of listing each EMA tensor individually. output_filename (default pruned_checkpoint) names the result, and the node saves it as a new safetensors file - the node's own description confirms exactly that: it "loads a checkpoint, removes specified keys, and saves it as a new safetensors file." Output is a single output_path string.
Know before you go: with use_regex off, you're matching exact key names, which means (like LoRARenameKeys) you should already know precisely what's in the file. Run CheckpointMetaKeys on the same checkpoint first - its keys output is the ground truth for what you're actually working with, and it's a lot faster than guessing at tensor names and getting a no-op.
Installing it
ComfyUI Manager: search Model Utility Toolkit, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-ModelUtils
Restart ComfyUI. No downloads needed - this operates on a checkpoint already on your disk.
Where people get burned
The obvious one: prune the wrong thing and the checkpoint breaks. Stripping EMA weights or unused optimizer state is safe; stripping something the model actually needs at inference - part of the UNet, the VAE if nothing else supplies one - produces a file that loads without error and then fails or generates garbage the moment you actually run it. There's no undo here beyond keeping your original file around, so don't overwrite the source and always keep the unpruned checkpoint until you've confirmed the pruned one still generates correctly.
The regex trap is the second one. use_regex matches against key names as patterns, which means an overly broad expression (a stray .* where you meant something narrower) can silently prune far more than you intended. Test a regex pattern against the keys output from CheckpointMetaKeys mentally (or in any regex tester) before trusting it against a multi-gigabyte file you don't want to redo. And remember file size isn't the only cost of a bad prune - a checkpoint missing a component another node in your workflow expected to find bundled in it is a confusing failure to debug, because the error shows up downstream, not at the point where you actually removed the tensor.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| ckpt_name | COMBO | 0 options: | |
| keys_to_prune | STRING | — | |
| use_regex | BOOLEAN | false | — |
| output_filename | STRING | pruned_checkpoint | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output_path | STRING | — |