{"record":{"id":"3dbcfb590dfe8206","repo":"hpcaitech/Open-Sora","slug":"unsupported-dtype-dtype","errorCode":null,"errorMessage":"Unsupported dtype {dtype}","messagePattern":"Unsupported dtype (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"opensora/utils/misc.py","lineNumber":247,"sourceCode":"        dtype (str | torch.dtype): The input dtype.\n\n    Returns:\n        torch.dtype: The converted dtype.\n    \"\"\"\n    if isinstance(dtype, torch.dtype):\n        return dtype\n    elif isinstance(dtype, str):\n        dtype_mapping = {\n            \"float64\": torch.float64,\n            \"float32\": torch.float32,\n            \"float16\": torch.float16,\n            \"fp32\": torch.float32,\n            \"fp16\": torch.float16,\n            \"half\": torch.float16,\n            \"bf16\": torch.bfloat16,\n        }\n        if dtype not in dtype_mapping:\n            raise ValueError(f\"Unsupported dtype {dtype}\")\n        dtype = dtype_mapping[dtype]\n        return dtype\n    else:\n        raise ValueError(f\"Unsupported dtype {dtype}\")\n\n\n# ======================================================\n# Profile\n# ======================================================\n\n\nclass Timer:\n    def __init__(self, name, log=False, barrier=False, coordinator: DistCoordinator | None = None):\n        self.name = name\n        self.start_time = None\n        self.end_time = None\n        self.log = log\n        self.barrier = barrier","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/hpcaitech/Open-Sora/blob/7ad6a96a135feb81f755c84fb391818718f6beb2/opensora/utils/misc.py#L229-L265","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ndtype = to_torch_dtype(\"float16\")\n\n# after\ndtype = to_torch_dtype(\"fp16\")","handlingStrategy":"validation","validationCode":"SUPPORTED_DTYPES = {\"fp32\", \"fp16\", \"half\", \"bf16\"}\ndtype = cfg.get(\"dtype\", \"bf16\")\nassert dtype in SUPPORTED_DTYPES, f\"dtype must be one of {SUPPORTED_DTYPES}, got {dtype!r}\"","typeGuard":"def is_supported_dtype_str(dtype: str) -> bool:\n    return isinstance(dtype, str) and dtype in {\"fp32\", \"fp16\", \"half\", \"bf16\"}","tryCatchPattern":"try:\n    dtype = to_torch_dtype(cfg[\"dtype\"])\nexcept ValueError:\n    dtype = torch.bfloat16  # safe default with a logged warning","preventionTips":["Use the canonical short names fp32/fp16/bf16 in all configs","Validate dtype at config load with a clear error listing allowed values"],"tags":["pytorch","dtype","config","valueerror","opensora"],"backgroundTag":"unsupported-dtype-string","analyzedSha":"7ad6a96a135feb81f755c84fb391818718f6beb2","analyzedAt":"2026-08-28T16:58:37.171Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}