File size: 1,080 Bytes
848f645
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""GPU detection for tuning concurrent eval clients."""
from __future__ import annotations

import shutil
import subprocess


def count_gpus() -> int:
    """Return visible CUDA GPU count via nvidia-smi; 0 if unavailable."""
    if not shutil.which("nvidia-smi"):
        return 0
    try:
        out = subprocess.run(
            [
                "nvidia-smi",
                "--query-gpu=index",
                "--format=csv,noheader",
            ],
            capture_output=True,
            text=True,
            timeout=30,
            check=False,
        )
        if out.returncode != 0 or not out.stdout.strip():
            return 0
        return len([ln for ln in out.stdout.strip().splitlines() if ln.strip() != ""])
    except (OSError, subprocess.TimeoutExpired):
        return 0


def parse_api_urls(spec: str | None) -> list[str]:
    """Comma-separated OpenAI-compatible base URLs (each may be a vLLM replica on one GPU)."""
    if not spec or not spec.strip():
        return []
    return [u.strip().rstrip("/") for u in spec.split(",") if u.strip()]