invoke-ai/InvokeAI · error · ValueError

out_dtype must be a float type, but got {out_dtype}

Error message

out_dtype must be a float type, but got {out_dtype}

What it means

to_standard_float_mask converts a mask to a (1, h, w) float tensor of 0.0/1.0 values in the requested out_dtype. Before doing any work it verifies out_dtype.is_floating_point; integer or bool dtypes (torch.uint8, torch.int64, torch.bool) are rejected with this ValueError because thresholding to 1.0/0.0 requires float arithmetic.

Source

Thrown at invokeai/backend/util/mask.py:39

    return mask


def to_standard_float_mask(mask: torch.Tensor, out_dtype: torch.dtype) -> torch.Tensor:
    """Standardize the format of a mask tensor.

    Args:
        mask (torch.Tensor): A mask tensor. The dtype can be any bool, float, or int type. The shape must be (1, h, w)
            or (h, w).

        out_dtype (torch.dtype): The dtype of the output mask tensor. Must be a float type.

    Returns:
        torch.Tensor: The output mask tensor. The dtype is out_dtype. The shape is (1, h, w). All values are either 0.0
            or 1.0.
    """

    if not out_dtype.is_floating_point:
        raise ValueError(f"out_dtype must be a float type, but got {out_dtype}")

    mask = to_standard_mask_dim(mask)
    mask = mask.to(out_dtype)

    # Set masked regions to 1.0.
    if mask.dtype == torch.bool:
        mask = mask.to(out_dtype)
    else:
        mask = mask.to(out_dtype)
        mask_region = mask > 0.5
        mask[mask_region] = 1.0
        mask[~mask_region] = 0.0

    return mask

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Pass a float dtype, e.g. to_standard_float_mask(mask, torch.float32) (or float16/bfloat16 as needed).
  2. Convert a non-float dtype variable: out_dtype = torch.tensor(0, dtype=out_dtype).float().dtype or just hardcode torch.float32.
  3. Keep masks in bool and call .to(float) afterwards if you need integer semantics elsewhere.

Example fix

// before
out = to_standard_float_mask(mask, torch.uint8)
// after
out = to_standard_float_mask(mask, torch.float32)
Defensive patterns

Strategy: validation

Validate before calling

if not out_dtype.is_floating_point:
    out_dtype = torch.float32
out = to_standard_float_mask(mask, out_dtype)

Type guard

def is_float_dtype(dtype: torch.dtype) -> bool:
    return dtype.is_floating_point

Try / catch

try:
    m = to_standard_float_mask(mask, out_dtype)
except ValueError as e:
    if "must be a float type" in str(e):
        m = to_standard_float_mask(mask, torch.float32)

Prevention

When it happens

Trigger: Calling to_standard_float_mask(mask, torch.uint8), torch.int32, torch.int64, torch.bool, or any non-float dtype; tests like test_to_standard_float_mask_wrong_shape exercise this path deliberately.

Common situations: Reusing a dtype variable that came from an integer input image, assuming bool masks are allowed, passing the VAE latent dtype when it is an integer type.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/535838bca165a7a3. Report an issue: GitHub.