hpcaitech/Open-Sora · error · ValueError
Unsupported dtype {dtype}
Error message
Unsupported dtype {dtype} What it means
This ValueError is raised by to_torch_dtype in opensora/utils/misc.py when a string dtype is not one of the mapped keys: "fp32", "fp16", "half", "bf16". The string branch of the function looks the name up in dtype_mapping and raises before any conversion happens. It exists to reject misspelled or unsupported precision names early, typically when parsing training config.
Source
Thrown at opensora/utils/misc.py:247
dtype (str | torch.dtype): The input dtype.
Returns:
torch.dtype: The converted dtype.
"""
if isinstance(dtype, torch.dtype):
return dtype
elif isinstance(dtype, str):
dtype_mapping = {
"float64": torch.float64,
"float32": torch.float32,
"float16": torch.float16,
"fp32": torch.float32,
"fp16": torch.float16,
"half": torch.float16,
"bf16": torch.bfloat16,
}
if dtype not in dtype_mapping:
raise ValueError(f"Unsupported dtype {dtype}")
dtype = dtype_mapping[dtype]
return dtype
else:
raise ValueError(f"Unsupported dtype {dtype}")
# ======================================================
# Profile
# ======================================================
class Timer:
def __init__(self, name, log=False, barrier=False, coordinator: DistCoordinator | None = None):
self.name = name
self.start_time = None
self.end_time = None
self.log = log
self.barrier = barrierView on GitHub (pinned to 7ad6a96a13)
Solutions
- Use one of the supported strings: "fp32", "fp16", "half", or "bf16"
- If you have a torch.dtype or the string "auto"-style value, pass the actual torch.dtype instead of a string
- Normalize config inputs before calling: strip whitespace and lowercase the string
Example fix
# before
dtype = to_torch_dtype("float16")
# after
dtype = to_torch_dtype("fp16") Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED_DTYPES = {"fp32", "fp16", "half", "bf16"}
dtype = cfg.get("dtype", "bf16")
assert dtype in SUPPORTED_DTYPES, f"dtype must be one of {SUPPORTED_DTYPES}, got {dtype!r}" Type guard
def is_supported_dtype_str(dtype: str) -> bool:
return isinstance(dtype, str) and dtype in {"fp32", "fp16", "half", "bf16"} Try / catch
try:
dtype = to_torch_dtype(cfg["dtype"])
except ValueError:
dtype = torch.bfloat16 # safe default with a logged warning Prevention
- Use the canonical short names fp32/fp16/bf16 in all configs
- Validate dtype at config load with a clear error listing allowed values
When it happens
Trigger: Calling to_torch_dtype("float16"), to_torch_dtype("fp8"), to_torch_dtype("float"), or any string other than fp32/fp16/half/bf16. Non-string inputs take the other branch (error 44). Called from main when translating a config dtype string into a torch.dtype.
Common situations: Writing "float16" (the torch spelling) instead of "fp16" in a YAML/JSON training config; upgrading/downgrading OpenSora versions where accepted dtype names differ; setting fp8 or tf32 names that this mapping never supported.
Related errors
- Unknown optimizer: {optimizer_name}
- Unknown plugin {plugin}
- resize(mode={mode}) not implemented.
- dtype: {dtype}
- Invalid logging level: {level}
AI-assisted analysis of hpcaitech/Open-Sora@7ad6a96a13 (2026-08-28).
Data as JSON: /api/errors/3dbcfb590dfe8206.
Report an issue: GitHub.