Swap Device β‘π ‘π π £π
Force an image or mask onto CPU or CUDA before ComfyUI complains
- image
- mask
- IMAGE
- MASK
The plainest node in the whole RyanOnTheInside pack, and one you'll end up reaching for specifically because the rest of the pack isn't plain. A good chunk of it - particle sims via pymunk, optical flow via OpenCV, spline masks rendered with matplotlib - is doing CPU-side numpy/OpenCV work under the hood, not GPU tensor math. Hand that result straight to a node that expects a CUDA tensor (a sampler, a VAE, a lot of the rest of ComfyUI) and you can trip the classic RuntimeError: Expected all tensors to be on the same device. SwapDevice is the fix: it moves an image or mask to whichever device you tell it, on purpose, before that error has a chance to happen.
How it works
There's no cleverness here, which is exactly the point. You pick a target device - cpu or cuda - and feed it an image and/or a mask. It moves whichever tensors you gave it onto that device and hands them back unchanged otherwise. Content is untouched; only where the data physically lives in memory changes.
The inputs and outputs that matter
device (required, cpu or cuda) is the whole decision you're making. image and mask are both optional - feed either one, both, or (if you're just testing) neither. Outputs mirror the inputs: IMAGE and MASK, now living on the device you picked.
How to install it
Via ComfyUI Manager, search "RyanOnTheInside." Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ryanontheinside/ComfyUI_RyanOnTheInside.git
cd ComfyUI_RyanOnTheInside
pip install -r requirements.txt
Restart ComfyUI. This specific node has no dependency of its own worth worrying about - it's a thin wrapper around a standard PyTorch .to(device) call. Nothing to download, nothing that can go wrong at the requirements level.
Common issues & troubleshooting
If you're hitting a device-mismatch error right after one of this pack's more CPU-heavy nodes (a particle emitter, an optical flow node, a spline modulator's mask output) and before a GPU-bound node like a sampler or VAE, drop a SwapDevice set to cuda in between. That's the node's whole reason to exist.
Less obviously: if you're chaining several of the CPU-side nodes together - say, multiple mask operations before anything touches the GPU - forcing everything to cpu explicitly at the start of that chain can actually be faster than letting a tensor bounce to GPU and back for each hop, since you skip the transfer overhead each time.
And the obvious one, but worth saying: if you're running ComfyUI on a CPU-only machine, picking cuda isn't going to conjure a GPU into existence - you'll just get an error from PyTorch about CUDA not being available. This node moves tensors between devices you actually have; it doesn't provision hardware.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| device | COMBO | 2 options: cpu, cuda | |
| imageopt | IMAGE | β | |
| maskopt | MASK | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | β |
| MASK | MASK | β |