OpenBMB/VoxCPM · error · ValueError

Unsupported dtype: {dtype}

Error message

Unsupported dtype: {dtype}

What it means

get_dtype maps dtype strings to torch types and only accepts bfloat16/float32/fp32 (plus the fp16/bf16 branches above). Anything else raises ValueError.

Source

Thrown at src/voxcpm/model/utils.py:155

    return CharTokenizerWrapper(tokenizer)


def get_dtype(dtype: str):
    if dtype == "bfloat16":
        return torch.bfloat16
    elif dtype == "bf16":
        return torch.bfloat16
    elif dtype == "float16":
        return torch.float16
    elif dtype == "fp16":
        return torch.float16
    elif dtype == "float32":
        return torch.float32
    elif dtype == "fp32":
        return torch.float32
    else:
        raise ValueError(f"Unsupported dtype: {dtype}")


def _has_mps() -> bool:
    return hasattr(torch.backends, "mps") and torch.backends.mps.is_available()


def pick_runtime_dtype(device: str, configured_dtype: str) -> str:
    """Pick a safe runtime dtype for the resolved device.

    On Apple Silicon (MPS), bfloat16/float16 produce enough numerical drift
    in the diffusion AR loop that the output is glitched and the model's
    badcase detector triggers infinite retries. float32 is the only stable
    option today. CUDA and CPU keep whatever the checkpoint was trained with.

    Users can override with ``VOXCPM_MPS_DTYPE`` (e.g. ``bfloat16``) when
    they want to test future MPS improvements.
    """
    if device != "mps":

View on GitHub (pinned to f5a1c6a6b9)

Solutions

  1. Use one of the supported strings: 'bfloat16','float16','fp16','float32','fp32'
  2. If you hold a torch.dtype, map it to its string name first
  3. Check the current supported list in get_dtype

Example fix

# before
model = VoxCPM(..., dtype=torch.float16)
# after
model = VoxCPM(..., dtype="float16")
Defensive patterns

Strategy: validation

Validate before calling

VALID = {"bfloat16","bf16","float16","fp16","float32","fp32"}
dtype = dtype if dtype in VALID else "float32"

Type guard

def is_valid_dtype(s) -> bool:
    return isinstance(s, str) and s in {"bfloat16","bf16","float16","fp16","float32","fp32"}

Prevention

When it happens

Trigger: Passing dtype='float16' spelled as 'fp16' is fine but 'float64', 'int8', 'fp8', or a torch.dtype object instead of a string raises this.

Common situations: Copy-pasting dtype names from other libraries, passing torch.float16 (the object) rather than 'float16', or a typo like 'f32'.

Related errors


AI-assisted analysis of OpenBMB/VoxCPM@f5a1c6a6b9 (2026-08-27). Data as JSON: /api/errors/4cd47489c27ad494. Report an issue: GitHub.