{"record":{"id":"871b311e54fc1a9c","repo":"Comfy-Org/ComfyUI","slug":"unsupported-dtype","errorCode":null,"errorMessage":"Unsupported dtype","messagePattern":"Unsupported dtype","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/float.py","lineNumber":35,"sourceCode":"\ndef calc_mantissa(abs_x, exponent, normal_mask, MANTISSA_BITS, EXPONENT_BIAS, generator=None):\n    mantissa_scaled = torch.where(\n        normal_mask,\n        (abs_x / (2.0 ** (exponent - EXPONENT_BIAS)) - 1.0) * (2**MANTISSA_BITS),\n        (abs_x / (2.0 ** (-EXPONENT_BIAS + 1 - MANTISSA_BITS)))\n    )\n\n    mantissa_scaled += torch.rand(mantissa_scaled.size(), dtype=mantissa_scaled.dtype, layout=mantissa_scaled.layout, device=mantissa_scaled.device, generator=generator)\n    return mantissa_scaled.floor() / (2**MANTISSA_BITS)\n\n#Not 100% sure about this\ndef manual_stochastic_round_to_float8(x, dtype, generator=None):\n    if dtype == torch.float8_e4m3fn:\n        EXPONENT_BITS, MANTISSA_BITS, EXPONENT_BIAS = 4, 3, 7\n    elif dtype == torch.float8_e5m2:\n        EXPONENT_BITS, MANTISSA_BITS, EXPONENT_BIAS = 5, 2, 15\n    else:\n        raise ValueError(\"Unsupported dtype\")\n\n    x = x.half()\n    sign = torch.sign(x)\n    abs_x = x.abs()\n    sign = torch.where(abs_x == 0, 0, sign)\n\n    # Combine exponent calculation and clamping\n    exponent = torch.clamp(\n        torch.floor(torch.log2(abs_x)) + EXPONENT_BIAS,\n        0, 2**EXPONENT_BITS - 1\n    )\n\n    # Combine mantissa calculation and rounding\n    normal_mask = ~(exponent == 0)\n\n    abs_x[:] = calc_mantissa(abs_x, exponent, normal_mask, MANTISSA_BITS, EXPONENT_BIAS, generator=generator)\n\n    sign *= torch.where(","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/float.py#L17-L53","documentation":"Raised by manual_stochastic_round_to_float8 when the requested dtype is neither torch.float8_e4m3fn nor torch.float8_e5m2. This manual fallback implements mantissa/exponent arithmetic only for the two FP8 formats PyTorch defines for inference; any other dtype string (including float8_e4m3fnuz or a bogus value) hits the else branch.","triggerScenarios":"Calling manual_stochastic_round_to_float8(x, dtype) with dtype=torch.float8_e4m3fnuz, a float16/bfloat16 dtype, or a raw string/int. Code that derives dtype from checkpoint quantization config (e.g. 'fp8_e4m3fnuz' on older AMD/NPU paths) and forwards it verbatim.","commonSituations":"Custom quantization nodes supporting the fnuz variant that assume the manual rounding helper accepts it; passing a fake dtype placeholder before real FP8 support is wired; copy-paste from code that assumed torch.float8_e4m3 only.","solutions":["Map the unsupported dtype to the nearest supported FP8 format before calling (e4m3fnuz -> float8_e4m3fn) if the precision loss is acceptable for your use","Use the comfy_kitchen _ck_stochastic_rounding_fp8 path, which may support a broader dtype set","Reject fnuz early in your own config parsing with a clear message instead of reaching this helper"],"exampleFix":"# before\nmanual_stochastic_round_to_float8(x, torch.float8_e4m3fnuz)  # ValueError\n# after\nif dtype == torch.float8_e4m3fnuz:\n    dtype = torch.float8_e4m3fn\nmanual_stochastic_round_to_float8(x, dtype)","handlingStrategy":"validation","validationCode":"SUPPORTED_FP8 = (torch.float8_e4m3fn, torch.float8_e5m2)\nif dtype not in SUPPORTED_FP8:\n    raise ValueError(f'manual_stochastic_round_to_float8 supports only {SUPPORTED_FP8}')","typeGuard":"def is_supported_fp8(dtype: torch.dtype) -> bool:\n    return dtype in (torch.float8_e4m3fn, torch.float8_e5m2)","tryCatchPattern":null,"preventionTips":["Map fnuz dtypes to e4m3fn at your config boundary","Never forward raw quantization-config dtype strings into rounding helpers"],"tags":["fp8","dtype","quantization","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}