Nodes/comfyui-mask-util/Mask Change DType
ComfyUI Node

Mask Change DType

Force a Mask Tensor's Precision

By longgui0318·Created 3 years ago·Updated about a year ago· 8
Mask Change DType
  • mask
  • mask
dtype

The mask-side twin of Image Change DType: masks are tensors too, and tensors carry a numeric precision that occasionally causes friction between nodes that don't agree on what it should be. Mask Change DType lets you force it explicitly instead of hoping everything upstream happened to agree.

Two inputs. mask is what you're converting, and dtype is the same four-option dropdown you'll see on its image counterpart: default (no change), float32 (full precision), float16 (half-precision, standard for GPU inference, half the memory footprint of float32), and bfloat16 (also half-size, but a different bit layout - trading some precision for a wider numeric range, and not a drop-in swap for float16 even though they're the same byte size). Output is mask, same content, new precision.

This is a targeted fix, not something you add by default. Reach for it when a specific downstream node throws a dtype error involving a mask - a mismatch between what your mask-producing node output and what your next node expects - and you'd rather patch it at that one seam than dig through your whole graph to find where the precision diverged. If nothing's complaining, there's no reason to insert this preemptively; masks generally flow through ComfyUI's default handling without needing manual precision control.

Installing it: part of comfyui-mask-util, a small utility pack from longgui0318, who's better known for comfyui-magic-clothing - a virtual-try-on node that had a short burst of Reddit attention in 2024 and has been quiet since. This pack reads as the general device/dtype/crop plumbing split out of that project rather than something with buzz of its own, and correspondingly the GitHub README is just the repo title - no install guide, no usage examples, so everything here comes from the node's own schema.

Install via ComfyUI Manager (search "comfyui-mask-util") or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/longgui0318/comfyui-mask-util

Restart ComfyUI afterward. No models to download - a dtype cast on a mask tensor is a trivial operation, no heavy dependencies involved.

Where it bites: casting a mask down to float16 or bfloat16 repeatedly, especially across several chained operations, can introduce small precision losses that show up as soft or slightly imprecise mask edges over enough iterations - not usually visible in one pass, but worth knowing if you're stacking a lot of mask math together. Going the other direction and forcing float32 on a large mask batch adds memory overhead you may not need. And like its image counterpart, this node is a response to a concrete error, not a preventative measure - if you don't have a specific dtype mismatch to fix, you probably don't need it in the graph at all.

Categorymask

Inputs (2)

NameTypeDefaultDescription
maskMASK
dtypeCOMBO4 options: default, float32, float16, bfloat16

Outputs (1)

NameTypeDescription
maskMASK