Nodes/ComfyDL/Model Save
ComfyUI Node

Model Save

Save a model's weights — only the weights, and only to a .pt

By Cynthia-lxx·Created 2 months ago·Updated 3 days ago· 6
Model Save
  • model
  • message
pathmodel.pt

CdlModelSave writes a ComfyDL model's weights to disk with torch.save(model.state_dict(), path) and returns a confirmation string. If you've trained a LeNet or an RNN in ComfyDL and want to keep it, this is the node. It's the mirror image of Model Load, and together they're how "deep learning in a graph" survives a restart.

The one sentence to tattoo on your brain: it saves the weights, not the model. state_dict is a plain mapping of parameter names to tensors - no architecture, no training history, no optimizer state. That means loading it back later requires you to rebuild an identical model from the same model node settings and then pour the weights in. This is a deliberate, standard PyTorch pattern (it's what torch.save(model.state_dict(), ...) means), and it's fine for this pack's purpose - the models are small and cheap to rebuild.

How it works

The node calls torch.save(model.state_dict(), path). The path is whatever string you give it; the default model.pt resolves relative to ComfyUI's working directory, which is easy to lose track of. The output is a STRING confirmation like Saved state_dict to: C:/models/my_model.pt, which doubles as a tiny receipt in your graph.

Inputs and output

  • model - the cdlModel to save.
  • path - a STRING, default model.pt. Give it an absolute path to keep the file where you can find it.

The single output is message, a STRING confirmation.

Installing ComfyDL

It's part of the ComfyDL pack:

cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ComfyDL/requirements.txt

Restart ComfyUI. The only extra dependency is matplotlib; torch comes with ComfyUI. ComfyUI Manager users: search "ComfyDL", and if it's missing from the built-in list (the pack isn't on the official registry yet), use Install via Git URL with the repo link.

Common issues

Three things to know before you rely on it. First, don't expect to load a saved file with anything but CdlModelLoad (or a matching PyTorch script) - and only then into the identical architecture; change num_classes between save and load and you get a shape mismatch. Second, the default relative path is a trap: model.pt with no directory lands wherever ComfyUI was launched, which is not where you're looking. Give absolute paths from the start. Third, it doesn't save optimizer state, so if you were mid-training you'll restart the optimizer from scratch - acceptable for a teaching pack, but worth knowing before you treat a save as a full checkpoint.

Categoryd2l/Model Utils

Inputs (2)

NameTypeDefaultDescription
modelcdlModel
pathSTRINGmodel.pt

Outputs (1)

NameTypeDescription
messageSTRING