DOGMA v35.4 Mask Device Guard
The one-line fix for 'Expected all tensors to be on the same device'
- image
- mask
- mask
- info
This is a four-line node and it will save you an evening. DOGMAMaskMatchImageDeviceV354 takes an IMAGE and a MASK, moves the mask to whatever device the image is on, casts it to float32, and hands it back.
Why that's a node
Because in a crop-and-inpaint pipeline, mask and image routinely end up on different devices. The mask came down a path that deliberately parked tensors on CPU - mask checkpoints, CPU-side segmentation post-processing, the "VRAM safe" variants of SAM prep nodes that exist precisely because a full-resolution mask costs real memory. The crop's pixels went to the GPU with the rest of the image pipeline.
Then you hand both to a conditioning node that inpainting needs, it checks that mask and image agree about where they live, and it dies with the classic Expected all tensors to be on the same device, but found at least two devices. The message points at the conditioning node. The cause is somewhere three nodes upstream. Fun one to bisect, that.
The node's own docstring states the contract: the conditioning step receives the mask on exactly the same device as the crop's pixels. That's it. align is the function, mask and info are the outputs, where info prints the move it made - mask device cpu -> cuda:0.
Where to wire it
Immediately before the node that consumes mask + crop pixels together - a InpaintModelConditioning-style node, or anything doing a masked VAE encode in this pack's flow. Put it on the mask wire only; the image is the reference and shouldn't be moved.
Don't sprinkle it everywhere. It's a .to() call with a device-detection check and a float32 cast; running it on every mask in a graph is harmless but it hides where the CPU tensors are coming from. Find the source once, then keep this at the boundary.
Inputs and outputs
image (IMAGE) and mask (MASK) in; mask (MASK) and info (STRING) out. No options, nothing to tune.
Install
ComfyUI Manager → search DOGMA Nodes, or:
cd ComfyUI/custom_nodes
git clone https://github.com/axior/ComfyUI-DOGMA-Nodes
Restart. No Python dependencies - the pack's requirements.txt says as much and the code backs it up. Nothing to download.
Where it bites
It changes dtype as well as device, casting to float32 unconditionally. If something downstream cared that your mask was half precision, this will quietly upgrade it - which is fine for the nodes it's meant for, and a wasted 2x on mask memory for anything elaborate.
Second, the device is taken from the image, so wiring them the other way round (image moved to the mask's device) isn't an option - that's the point. If your image is on CPU and your mask is on the GPU, this node will happily drag the mask down to CPU and whatever consumes them next will be slow rather than broken.
And it doesn't resize. A mask at 2048 squared against an image at 1024 squared will align devices perfectly and still be wrong. Resize first, align second - the ordering trips people up because the crash you fixed was the loud one.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| info | STRING | — |