{"record":{"id":"4add9c1ce4eeeac9","repo":"hiyouga/LlamaFactory","slug":"unexpected-precision-precision","errorCode":null,"errorMessage":"Unexpected precision: {precision}","messagePattern":"Unexpected precision: (.+?)","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/utils/dtype.py","lineNumber":48,"sourceCode":"\n\nclass DtypeInterface:\n    \"\"\"Type of precision used.\"\"\"\n\n    _is_fp16_available = is_torch_fp16_available_on_device(DistributedInterface().current_device)\n    _is_bf16_available = is_torch_bf16_available_on_device(DistributedInterface().current_device)\n    _is_fp32_available = True\n\n    @staticmethod\n    def is_available(precision: str | torch.dtype) -> bool:\n        if precision in DtypeRegistry.HALF_LIST:\n            return DtypeInterface._is_fp16_available\n        elif precision in DtypeRegistry.FLOAT_LIST:\n            return DtypeInterface._is_fp32_available\n        elif precision in DtypeRegistry.BFLOAT_LIST:\n            return DtypeInterface._is_bf16_available\n        else:\n            raise RuntimeError(f\"Unexpected precision: {precision}\")\n\n    @staticmethod\n    def is_fp16(precision: str | torch.dtype) -> bool:\n        return precision in DtypeRegistry.HALF_LIST\n\n    @staticmethod\n    def is_fp32(precision: str | torch.dtype) -> bool:\n        return precision in DtypeRegistry.FLOAT_LIST\n\n    @staticmethod\n    def is_bf16(precision: str | torch.dtype) -> bool:\n        return precision in DtypeRegistry.BFLOAT_LIST\n\n    @staticmethod\n    def to_dtype(precision: str | torch.dtype) -> torch.dtype:\n        if precision in DtypeRegistry.HALF_LIST:\n            return torch.float16\n        elif precision in DtypeRegistry.FLOAT_LIST:","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/utils/dtype.py#L30-L66","documentation":"RuntimeError from DtypeInterface.is_available (dtype.py:48) when the precision argument is not in HALF_LIST (fp16/float16/half/torch.float16), FLOAT_LIST (fp32/float32/float/torch.float32), or BFLOAT_LIST (bf16/bfloat16/torch.bfloat16). The registry is a fixed allowlist, so any other string or torch dtype (e.g. 'fp8', 'tf32', torch.float64) is rejected with no fallback.","triggerScenarios":"Calling DtypeInterface.is_available('fp8'), is_available('tf32'), or passing a config precision value like 'auto' or a torch dtype such as torch.float64. Also 'float' vs 'foat' typos from YAML.","commonSituations":"Newer quantization/dtype names (fp8, tf32) set in training args reach this helper; users pass 'auto' expecting transformers-style resolution; mixed torch.dtype objects and strings from different code paths.","solutions":["Normalize the precision to one of the supported strings: fp16/float16/half, fp32/float32/float, or bf16/bfloat16 (or the matching torch dtype).","Resolve 'auto'-style values yourself before calling: pick bf16 if available, else fp16.","If you control the caller, validate precision against DtypeRegistry lists before invoking is_available()."],"exampleFix":"# before\nprecision = \"auto\"\nDtypeInterface.is_available(precision)\n\n# after\nprecision = \"bf16\" if DtypeInterface.is_bf16_available_variant else \"fp16\"\nDtypeInterface.is_available(precision)","handlingStrategy":"validation","validationCode":"from llamafactory.v1.utils.dtype import DtypeRegistry\nVALID = set(DtypeRegistry.HALF_LIST + DtypeRegistry.FLOAT_LIST + DtypeRegistry.BFLOAT_LIST)\nassert precision in VALID, f\"unsupported precision {precision!r}; valid: fp16/fp32/bf16\"","typeGuard":"def is_supported_precision(p) -> bool:\n    from llamafactory.v1.utils.dtype import DtypeRegistry\n    return p in DtypeRegistry.HALF_LIST + DtypeRegistry.FLOAT_LIST + DtypeRegistry.BFLOAT_LIST","tryCatchPattern":null,"preventionTips":["Constrain precision in config schemas to an enum of fp16/fp32/bf16.","Resolve 'auto' to a concrete value before calling dtype helpers."],"tags":["dtype","precision","validation","config"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}