SaveTorchTensor
Persist a tensor to disk so you don't regenerate it every run
- tensor
- STRING
ComfyUI re-runs a graph top to bottom every time you hit Queue, and that's a problem when one of your nodes is a slow download, a big shuffle, or a RandomTensor that changes every run. SaveTorchTensor is the fix: it writes a TORCH_TENSOR to a .pt file on disk so you can generate once and reuse forever. If you've got a dataset you're tired of re-processing, this is the node that makes it stop.
It's part of EternalKernel PyTorch Nodes (TashaSkyUp), the raw-PyTorch-inside-ComfyUI pack. It's deliberately boring - a single torch.save(tensor, file) wrapped in a node - and boring is exactly what you want from persistence.
How it works
The mechanism is one line: torch.save(tensor, file), the standard PyTorch serialization. SaveTorchTensor is flagged as an output node, and it returns the file path as a STRING output (handy if you want to log where things went). The "load it back" half of the story lives in the pack's LoadTorchTensor node, which isn't in this batch - same .pt format, inverse operation.
Two honest caveats about the format. It's pickle-based .pt, not the safetensors format the modern ecosystem prefers - fine for your own scratch files, but don't plan to hand these to other tools, and don't load .pt files from strangers (that's the classic pickle-arbitrary-code-execution footgun the community keeps warning about). Also the default path is literally /somewhere/some.pt, which will error on most systems - you're expected to replace it. Change it to something real like C:/Users/you/Desktop/mnist_features.pt or ./data/tensor.pt.
Inputs and outputs
- tensor (required
TORCH_TENSOR) - whatever you're persisting. - file (required STRING) - where to write it. Absolute paths are your friend here.
- Output: STRING - the path you saved to.
Installing it
Shared with the whole pack:
cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes.git
cd EternalKernelPytorchNodes
pip install -r requirements.txt
Restart ComfyUI and it's under ETK/pytorch - or ComfyUI Manager, searching "EternalKernel PyTorch Nodes".
Troubleshooting
The two things that actually go wrong: the directory doesn't exist (torch.save won't create it for you - make the folder first), and permission errors on weird paths. Both surface as a plain FileNotFoundError or PermissionError at the node. There's no validation on the path, so typos fail loudly mid-run rather than being caught at the port. And because this pack patches ComfyUI's type-checking to ignore mismatches, a None sneaking into the tensor input (say, from a PyTorchDatasetDownloader output you didn't fill) will write a broken file rather than fail cleanly - check what's actually on the wire before you blame the file system.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| tensor | TORCH_TENSOR | — | |
| file | STRING | /somewhere/some.pt | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |