Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee Selective Model Reloader
ComfyUI Node

EmAySee Selective Model Reloader

Push a CPU-offloaded model back onto your GPU

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee Selective Model Reloader
  • image
  • image
  • reloaded_count
  • debug_info
model_name_filterSamImage
force_bfloat16false
purge_cachetrue

This node is the mirror image of the EmAySee Selective Model Unloader: where the unloader evicts specific models from VRAM, the reloader finds models that got moved to CPU and shoves them back onto the GPU. On its own it does nothing useful. Paired with the unloader, it's a manual on-demand offload/reload cycle - a poor man's version of the memory juggling that a workflow with a big checkpoint and a big auxiliary model (SAM, a vision backbone, a LoRA-heavy pass) sometimes needs to survive on a tight card.

Think about the order you'd use it in. A face-fixing workflow loads SAM to build a mask, then needs all the VRAM it can get for the actual detailer pass. You run the unloader to evict SAM mid-graph, do the heavy sampling, then run the reloader to bring SAM back for the next batch - without forcing a full re-load from disk and without reloading the checkpoint ComfyUI kept resident.

How it works

The mechanism is a blunt instrument, and it's worth knowing that before you trust it: it walks gc.get_objects() - every live Python object in the process - and for every torch.nn.Module whose class name contains your filter, it checks where the module's first parameter or buffer lives. If it's on CPU, it calls .to(device) to move it back.

  • model_name_filter - comma-separated substrings matched against class names; default "SamImage", i.e. aimed squarely at SAM-family segmenters. Case-insensitive.
  • force_bfloat16 - if on, the reload moves the module to GPU and casts it to bfloat16 in one shot. Handy if you'd rather hold the model at half precision on a small card, but only do this if the model tolerates it.
  • purge_cache - on by default; after moving things it runs gc.collect(), soft_empty_cache(), and torch.cuda.empty_cache(). The idea is to actually free the fragmentation so the freed VRAM is usable, not just marked free.

The image input is a passthrough wire so the node executes where you want it in the graph - it doesn't look at the image at all.

Outputs

  • image - passed through unchanged.
  • reloaded_count - how many modules matched and got moved to GPU.
  • debug_info - a log like Moving back to GPU: SamImage; or No models needed reloading. when nothing was on CPU.

Read the count before you trust the workflow: because the scan is gc.get_objects()-based, a "reload" that reports zero might mean the model was never on CPU - or that its class name doesn't match your filter.

Installing it

Same pack as the rest: ComfyUI_EmAySee_CustomNodes, via ComfyUI Manager or git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes into ComfyUI/custom_nodes/, then restart. No dependencies beyond what ComfyUI already has - it's pure torch + ComfyUI internals, no requirements file, no model files.

The honest caveats

Two things to know before you build around this. First, the gc-scan approach is fragile by design: it matches any torch.nn.Module with a matching class name, so a filter like "Transformer" could catch a dozen unrelated modules. Keep filters specific. Second, force_bfloat16 will happily cast a module that isn't bf16-safe if you ask it to. And the deeper truth: if you're fighting this hard for VRAM, ComfyUI's built-in lowvram/novram offloading or GGUF quantized checkpoints (KB's troubleshooting doc calls GGUF the main lever for fitting big models on small cards) will usually serve you better than manual reload games. This node is for the specific case where you know exactly which model you want back and when.

CategoryEmAySee/Utils

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
model_name_filterSTRINGSamImage
force_bfloat16BOOLEANfalse
purge_cacheBOOLEANtrue

Outputs (3)

NameTypeDescription
imageIMAGE
reloaded_countINT
debug_infoSTRING