PyTorchToDevice
Move a model or tensor between CUDA and CPU
- model
- tensor
- TORCH_MODEL
- TORCH_TENSOR
Every PyTorch user eventually hits the moment where part of the pipeline is on the GPU and the rest is on the CPU, and the two refuse to talk. PyTorchToDevice is the .to(device) call turned into a node: point it at cuda or cpu, feed it a model and/or a tensor, and it moves them. That's the whole job, and honestly it's the whole job a lot of the time.
It's part of EternalKernel PyTorch Nodes (TashaSkyUp), the raw-PyTorch-in-ComfyUI pack. Training on CPU when you have a GPU is how this pack teaches you to start - TrainModel defaults to torch.device('cpu') - and PyTorchToDevice is what you wire in when you decide the one-epoch MNIST run can wait no longer.
How it works
The mechanism is a single line of PyTorch: it builds torch.device(device) and calls .to(device_to_use) on whatever you gave it. Models and tensors are both plain .to() targets, so the node handles either - or both at once.
Here's the subtle part. The node always emits two outputs, a TORCH_MODEL and a TORCH_TENSOR, even if you only fed it one. The one you didn't provide comes out as None. That's technically a return-type mismatch, and it works only because this pack patches ComfyUI's validation on import to ignore exactly those mismatches. In practice: wire the output you care about and ignore the ghost None - but know that this pack is quietly making ComfyUI's type checking looser for your whole session.
Inputs and outputs
- device (required enum) -
cudaorcpu, defaultcpu. - model (optional
TORCH_MODEL) - move a network. - tensor (optional
TORCH_TENSOR) - move data. - Outputs:
TORCH_MODEL,TORCH_TENSOR(the one you didn't feed isNone).
Installing it
Part of the shared pack, so:
cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes.git
cd EternalKernelPytorchNodes
pip install -r requirements.txt
Restart ComfyUI, look under ETK/pytorch. ComfyUI Manager users: search "EternalKernel PyTorch Nodes".
Troubleshooting
The most common complaint is that cuda throws an error on machines without a working CUDA build - RuntimeError: Found no NVIDIA driver or similar. That's a real environment problem, not a node bug: check torch.cuda.is_available() in a terminal before blaming the graph. Second, be deliberate about why you're moving things. If the model is on CUDA and the tensor stays on CPU, PyTorchInferenceNode will quietly move the input for you, so a lot of graphs never need this node at all - reach for it when a node in the middle doesn't auto-fix the mismatch. And since the un-feed output is None, wiring both outputs downstream of a one-input usage is how you get mysterious "not a tensor" errors in some other node.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| device | COMBO | cpu | 2 options: cuda, cpu |
| modelopt | TORCH_MODEL | — | |
| tensoropt | TORCH_TENSOR | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| TORCH_MODEL | TORCH_MODEL | — |
| TORCH_TENSOR | TORCH_TENSOR | — |