sgl-project/sglang · error · ValueError

missing value for {a} (expected e.g. `{a} 2,4`)

Error message

missing value for {a} (expected e.g. `{a} 2,4`)

What it means

_extract_num_gpus_override parses --num-gpu/--num-gpus from a test/bench command line. The space-separated form requires a following value token (e.g. `--num-gpu 2,4`); if the flag is the last argument with no value after it, the parser raises this ValueError before anything launches.

Source

Thrown at python/sglang/kernels/ops/communication/mp.py:99

    psutil.wait_procs(descendants, timeout=5)


def _extract_num_gpus_override(
    argv: list[str],
) -> tuple[list[int] | None, list[str]]:
    """Pop `--num-gpu(s)` flags out of `argv` and return them separately.

    Accepts `--num-gpu N`, `--num-gpu=N`, `--num-gpus ...`, and comma-separated
    lists like `--num-gpu 2,4,8`. May be repeated.
    """
    override: list[int] = []
    remaining: list[str] = []
    i = 0
    while i < len(argv):
        a = argv[i]
        if a in ("--num-gpu", "--num-gpus"):
            if i + 1 >= len(argv):
                raise ValueError(f"missing value for {a} (expected e.g. `{a} 2,4`)")
            override.extend(int(x) for x in argv[i + 1].split(","))
            i += 2
        elif a.startswith("--num-gpu=") or a.startswith("--num-gpus="):
            _, val = a.split("=", 1)
            override.extend(int(x) for x in val.split(","))
            i += 1
        else:
            remaining.append(a)
            i += 1
    return (override if override else None), remaining


def multigpu_launch(
    name: str,
    file: str,
    num_gpus: Sequence[int],
    env_key: str,
    inner: Callable[[], int],

View on GitHub (pinned to 0132848349)

Solutions

  1. Provide the value: `--num-gpu 2,4` or the equals form `--num-gpu=2,4`
  2. Quote/defaults the variable in scripts: `--num-gpu ${GPUS:-1,2}` or skip the flag entirely when unset

Example fix

# before
pytest test_mp.py --num-gpu
# after
pytest test_mp.py --num-gpu=2,4
Defensive patterns

Strategy: validation

Validate before calling

# in shell: prefer the equals form which cannot dangle
# pytest bench.py --num-gpu=2,4

Prevention

When it happens

Trigger: Running a multi-GPU pytest/benchmark with `--num-gpu` as the final CLI token, e.g. `pytest test_x.py --num-gpu` (missing the list).

Common situations: Shell scripts where the GPU list variable is empty (`--num-gpu $GPUS` with GPUS unset) or a truncated copy-pasted command line.

Related errors


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