{"record":{"id":"c739da4a7ca6fb4e","repo":"sgl-project/sglang","slug":"gpu-ids-contains-a-non-integer-gpu-id-token","errorCode":null,"errorMessage":"--gpu-ids contains a non-integer GPU id: {token}","messagePattern":"--gpu-ids contains a non-integer GPU id: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/utils/common.py","lineNumber":101,"sourceCode":"    if gpu_ids is None:\n        return None\n    if isinstance(gpu_ids, str):\n        values = [gpu_ids]\n    else:\n        values = list(gpu_ids)\n\n    tokens: list[str] = []\n    for value in values:\n        tokens.extend(part for part in str(value).replace(\",\", \" \").split() if part)\n    if not tokens:\n        return []\n\n    parsed: list[int] = []\n    for token in tokens:\n        try:\n            gpu_id = int(token)\n        except ValueError as exc:\n            raise ValueError(\n                f\"--gpu-ids contains a non-integer GPU id: {token}\"\n            ) from exc\n        if gpu_id < 0:\n            raise ValueError(f\"--gpu-ids GPU ids must be non-negative: {gpu_id}\")\n        parsed.append(gpu_id)\n\n    if len(set(parsed)) != len(parsed):\n        raise ValueError(f\"--gpu-ids contains duplicate GPU ids: {parsed}\")\n    return parsed\n\n\ndef parse_size(size: str) -> tuple[int | None, int | None]:\n    try:\n        parts = size.lower().replace(\" \", \"\").split(\"x\")\n        if len(parts) != 2:\n            raise ValueError\n        return int(parts[0]), int(parts[1])\n    except ValueError:","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/utils/common.py#L83-L119","documentation":"Thrown by normalize_gpu_ids when a token in the --gpu-ids argument cannot be parsed as an integer via int(). It indicates the GPU id list contains a non-numeric token, e.g. '0,x,1' or an empty segment from a trailing comma. The original ValueError from int() is chained as the cause.","triggerScenarios":"Passing --gpu-ids \"0,foo\" or \"0,,1\" or \"gpu0\" to the multimodal_gen runtime, whose config __post_init__ calls normalize_gpu_ids which does int(token) on each comma-separated token.","commonSituations":"Typo in a CLI flag or shell variable expansion producing an empty/garbage token (e.g. unset $GPU_IDS yielding '--gpu-ids ,'), copy-pasting CUDA_VISIBLE_DEVICES-style values with extra text.","solutions":["Fix the --gpu-ids value so every comma-separated token is a plain non-negative integer (e.g. --gpu-ids 0,1,2)","Check for stray commas, spaces, or shell variable expansion issues (empty vars) in the argument","Validate the string with a small pre-parse check before launching the runtime"],"exampleFix":"# before\n--gpu-ids 0,foo,2\n# after\n--gpu-ids 0,1,2","handlingStrategy":"validation","validationCode":"def valid_gpu_ids(s: str) -> bool:\n    return all(t.strip().lstrip(\"+\").isdigit() for t in s.split(\",\") if t != \"\" ) and all(t.strip() for t in s.split(\",\"))","typeGuard":null,"tryCatchPattern":"try:\n    cfg = PoolConfig(gpu_ids=args.gpu_ids)\nexcept ValueError as e:\n    if \"non-integer GPU id\" in str(e):\n        sys.exit(f\"Bad --gpu-ids {args.gpu_ids!r}: {e}\")\n    raise","preventionTips":["Pre-parse --gpu-ids with a regex like ^\\d+(,\\d+)*$ before handing it to the runtime","Quote shell variables used in the flag to avoid empty-token expansion"],"tags":["gpu","cli-arguments","validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}