{"record":{"id":"48ba5b5aaf0438d8","repo":"sgl-project/sglang","slug":"unknown-dtype-dtype","errorCode":null,"errorMessage":"Unknown dtype: {dtype}","messagePattern":"Unknown dtype: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/configs/model_config.py","lineNumber":1819,"sourceCode":"                    if model_type == \"gemma\":\n                        gemma_version = \"\"\n                    else:\n                        gemma_version = model_type[5]\n                    logger.info(\n                        f\"For Gemma {gemma_version}, we downcast float32 to bfloat16 instead \"\n                        \"of float16 by default. Please specify `dtype` if you \"\n                        \"want to use float16.\"\n                    )\n                    torch_dtype = torch.bfloat16\n                else:\n                    # Following the common practice, we use float16 for float32\n                    # models.\n                    torch_dtype = torch.float16\n            else:\n                torch_dtype = config_dtype\n        else:\n            if dtype not in _STR_DTYPE_TO_TORCH_DTYPE:\n                raise ValueError(f\"Unknown dtype: {dtype}\")\n            torch_dtype = _STR_DTYPE_TO_TORCH_DTYPE[dtype]\n    elif isinstance(dtype, torch.dtype):\n        torch_dtype = dtype\n    else:\n        raise ValueError(f\"Unknown dtype: {dtype}\")\n\n    # Verify the dtype.\n    if torch_dtype != config_dtype:\n        if torch_dtype == torch.float32:\n            # Upcasting to float32 is allowed.\n            logger.debug(\"Upcasting %s to %s.\", config_dtype, torch_dtype)\n            pass\n        elif config_dtype == torch.float32:\n            # Downcasting from float32 to float16 or bfloat16 is allowed.\n            logger.debug(\"Downcasting %s to %s.\", config_dtype, torch_dtype)\n            pass\n        else:\n            # Casting between float16 and bfloat16 is allowed with a warning.","sourceCodeStart":1801,"sourceCodeEnd":1837,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/configs/model_config.py#L1801-L1837","documentation":"_get_and_verify_dtype converts the dtype argument to a torch.dtype; if dtype is a string not present in _STR_DTYPE_TO_TORCH_DTYPE (e.g. 'bfloat', 'float', 'bf16 ' with whitespace, 'fp16'), it raises 'Unknown dtype'.","triggerScenarios":"ModelConfig(..., dtype='fp16') or server --dtype fp16 / bfloat / float — any string not exactly matching keys like 'float16','bfloat16','float32'. Falls through the str branch at model_config.py:1819.","commonSituations":"Passing shorthand dtype names from other frameworks, trailing whitespace or wrong casing in scripts, typos like 'flaot16'.","solutions":["Use one of the exact keys of _STR_DTYPE_TO_TORCH_DTYPE: 'float16', 'bfloat16', 'float32' (or 'auto')","Strip/normalize user-supplied dtype strings before passing them to ModelConfig","Pass a torch.dtype instance instead of a string when constructing ModelConfig programmatically"],"exampleFix":"# before\n--dtype fp16\n# after\n--dtype float16","handlingStrategy":"type-guard","validationCode":"VALID = {'auto','float16','bfloat16','float32','half','float'}  # per _STR_DTYPE_TO_TORCH_DTYPE\nif isinstance(dtype, str) and dtype.strip().lower() not in VALID:\n    raise SystemExit(f\"bad dtype {dtype!r}\")","typeGuard":"def is_valid_dtype_str(s: str) -> bool:\n    from sglang.srt.configs.model_config import _STR_DTYPE_TO_TORCH_DTYPE\n    return s in _STR_DTYPE_TO_TORCH_DTYPE","tryCatchPattern":null,"preventionTips":["Normalize dtype strings (strip, lowercase) at your config boundary","Prefer the canonical names float16/bfloat16/float32"],"tags":["dtype","config-validation","sglang"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}