ComfyUI Node

DGX Spark Model Unloader

The DGX Spark unloader nobody realizes they need

By redstonewhite·Created 6 months ago·Updated 6 months ago· 0
DGX Spark Model Unloader
      confirmfalse
      modeall
      target(none)

      Here's the thing nobody warns you about when you switch a DGX Spark workflow to the fast loaders: those nodes sit outside ComfyUI's memory management. ComfyUI's normal loaders track what they load and evict models when you run out of room. The DGX Spark loaders in this pack don't - by design, so they can cache models in unified memory and never touch disk again. The catch is that nothing ever tells ComfyUI to free them.

      That's the whole reason DGX Spark Model Unloader exists. It's the cleanup half of the pack, the counterpart to the loaders that keeps your 128 GB of unified memory from slowly filling with every checkpoint you've touched this session.

      How it works

      It's an output node with no outputs. You drop it in a workflow, and when it runs it walks the pack's registry of everything a DGX Spark loader has loaded and releases it: it removes the models from ComfyUI's loaded-model list, wipes the tensor data out of the modules, closes the fastsafetensors file handles, and calls gc.collect() plus torch.cuda.empty_cache() for good measure. Then it prints what it did as UI text.

      The three inputs

      • confirm - a boolean, default False, and the single most important input on the node. It's the safety toggle: the tooltip says it "Must be True to unload. When False the node is a no-op." You read that right - with confirm off, running the node does nothing and just reports the current state. That's the guard that keeps you from accidentally nuking every loaded model the moment the graph runs.
      • mode - all unloads every model loaded by any DGX Spark loader; selected unloads only the model you pick in target.
      • target - only used in selected mode. It's a dropdown of currently loaded models, and the tooltip carries the gotcha: "Refresh the page to update this list after loading models." The choices are snapshotted when the node is built, so newly loaded models won't show up until you refresh the browser.

      So the actual flow is: set confirm to True, set mode to all (or pick a target), queue the workflow, and it unloads. The node even prints a tip after doing its job: set confirm back to False before the next run. That tip exists because with confirm left on, the node will unload everything every time the graph runs - which is presumably not what you want mid-generation.

      The node is smart about when it actually forces a run: its change-detection returns "always changed" only when confirm is True and there's something to unload. Otherwise it's a cheap no-op, so leaving it parked in a workflow costs you nothing.

      Installing it

      Same pack as the loaders it cleans up. ComfyUI Manager, search ComfyUI-DGXSparkFastSafetensorsLoaders, or:

      cd ComfyUI/custom_nodes
      git clone https://github.com/redstonewhite/ComfyUI-DGXSparkFastSafetensorsLoaders.git
      pip install fastsafetensors
      

      Restart ComfyUI; it shows up under loaders.

      Common issues

      • "Target not found." You picked a model that's no longer in the registry (or never was on this server), and the node tells you so instead of erroring. Refresh the page and re-check the dropdown.
      • Models keep coming back. Unloading only clears the registry entry and the GPU memory; if a loader later runs again, it re-loads from disk. That's normal - the unloader frees memory, it doesn't ban the model.
      • Nothing happens when you run it. Check confirm. With it at False, the node is doing exactly what it's told.

      One honest note: if you never use the fast loaders, this node is dead weight - it only frees models that a DGX Spark loader put there. But if you do, it's the difference between a Spark that needs a daily restart and one that just works.

      Categoryloaders

      Inputs (3)

      NameTypeDefaultDescription
      confirmBOOLEANfalseSafety toggle. Must be True to unload. When False the node is a no-op.
      modeCOMBOall'all' unloads every model loaded by any DGX Spark loader. 'selected' unloads only the model chosen in 'target'.
      targetoptCOMBO(none)The model to unload (only used when mode is 'selected'). Refresh the page to update this list after loading models.

      Outputs (0)

      No outputs