sgl-project/sglang · error · ValueError

--gpu-ids contains duplicate GPU ids: {parsed}

Error message

--gpu-ids contains duplicate GPU ids: {parsed}

What it means

Thrown by normalize_gpu_ids when the same GPU id appears more than once in --gpu-ids, detected via len(set(parsed)) != len(parsed). Duplicate ids would otherwise cause double-binding to one device.

Source

Thrown at python/sglang/multimodal_gen/runtime/utils/common.py:109

    for value in values:
        tokens.extend(part for part in str(value).replace(",", " ").split() if part)
    if not tokens:
        return []

    parsed: list[int] = []
    for token in tokens:
        try:
            gpu_id = int(token)
        except ValueError as exc:
            raise ValueError(
                f"--gpu-ids contains a non-integer GPU id: {token}"
            ) from exc
        if gpu_id < 0:
            raise ValueError(f"--gpu-ids GPU ids must be non-negative: {gpu_id}")
        parsed.append(gpu_id)

    if len(set(parsed)) != len(parsed):
        raise ValueError(f"--gpu-ids contains duplicate GPU ids: {parsed}")
    return parsed


def parse_size(size: str) -> tuple[int | None, int | None]:
    try:
        parts = size.lower().replace(" ", "").split("x")
        if len(parts) != 2:
            raise ValueError
        return int(parts[0]), int(parts[1])
    except ValueError:
        return None, None


def parse_tcp_host_port(value: str | None, field_name: str) -> tuple[str, int]:
    if value is None or not str(value).strip():
        raise ValueError(f"{field_name} is required")

    addr = str(value).strip()

View on GitHub (pinned to 0132848349)

Solutions

  1. Deduplicate the list before passing it: sorted(set(ids))
  2. Check how the --gpu-ids value was assembled (concatenated lists are a common cause)
  3. Pass each GPU exactly once, e.g. --gpu-ids 0,1,2

Example fix

# before
--gpu-ids 0,1,0
# after
--gpu-ids 0,1
Defensive patterns

Strategy: validation

Validate before calling

tokens = [t for t in gpu_ids_str.split(",")]
assert len(set(tokens)) == len(tokens), "duplicate gpu ids"

Prevention

When it happens

Trigger: Passing --gpu-ids "0,0,1" or a duplicated id produced by concatenating config lists.

Common situations: Building the gpu list programmatically (e.g. list_a + list_b) without deduplication; shell variable accidentally repeated.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/8efe91cca2ded7c6. Report an issue: GitHub.