xr_ai_vllm#
xr-ai-vllm — pluggable vLLM backend for xr-ai inference services.
Lets each vLLM-backed service host vllm via either:
pip — pip-installed vllm CLI in the wrapper’s venv (default; today’s behavior).
docker — docker run nvcr.io/nvidia/vllm:<tag> vllm serve … (NGC container).
The choice is per-server, set via vllm_backend: pip|docker in the service’s YAML. Both paths honor identical config keys (model, ports, vllm flags); only the runtime hosting vllm differs.
Stdlib-only by contract — no vllm or other heavy deps imported here, so the docker path stays light even when pip vllm is not installed.
Typical usage from a service wrapper:
from xr_ai_vllm import serve, DEFAULT_IMAGE
serve(
backend=cfg.get("vllm_backend", "pip"),
persistent=True,
image=cfg.get("vllm_image", DEFAULT_IMAGE),
container_name="xr-ai-vllm-vlm-server",
log_prefix="vlm_server",
model=model,
extra_serve_args=[
"--served-model-name", served_name,
"--max-num-seqs", str(max_seqs),
...
],
host=host, port=port,
model_cache=model_cache,
hf_token=os.environ.get("HF_TOKEN"),
cuda_visible_devices=cfg.get("cuda_visible_devices"),
ready_file=ns.ready_file,
)
Attributes#
Default NGC vLLM image used when a service does not override |
Functions#
|
Return the GPU's compute-capability major version, or 0 if unknown. |
|
Parse |
|
Resolve |
|
Apply the shared HuggingFace / CUDA env block. |
|
Pull (if needed) and run a NIM container, blocking until stopped. |
|
Launch vLLM via backend ("pip" or "docker"). |
|
Stop persisted servers and report whether every discovered server stopped. |
Package Contents#
- xr_ai_vllm.gpu_compute_major() int#
Return the GPU’s compute-capability major version, or 0 if unknown.
Reads
CUDA_VISIBLE_DEVICESfrom the env, so set the device filter before calling. Logs a warning on failure and falls back to 0.
- xr_ai_vllm.load_config(
- argv: list[str] | None = None,
Parse
--config/--ready-fileand load the YAML config.Reconfigures stdout/stderr to line-buffered so logs flush under the launcher’s piped stdout. Returns
(cfg, yaml_dir, ready_file);yaml_diris the config’s directory (cwd when no config is given), used as the base for relative paths likemodel_cache.
- xr_ai_vllm.resolve_model_cache(
- cfg: dict,
- yaml_dir: pathlib.Path,
- *,
- default: str,
Resolve
model_cache(relative to the YAML dir) and ensure it exists.
- xr_ai_vllm.setup_hf_env(cfg: dict, model_cache: pathlib.Path) str | None#
Apply the shared HuggingFace / CUDA env block.
Sets
CUDA_VISIBLE_DEVICES(when configured),HF_TOKEN(when provided),HF_XET_HIGH_PERFORMANCE,HF_HOME, andTRANSFORMERS_CACHE.A non-empty env value for
HF_TOKEN,HF_HOME, orTRANSFORMERS_CACHEwins over the YAML value, per docs/source/getting_started/credentials.md.TRANSFORMERS_CACHEmirrorsHF_HOMEfor Transformers <4.36 and libraries that have not adoptedHF_HOME.Returns the resolved
cuda_visible_devicesstring (orNone) so callers that run GPU detection can confirm the device filter is applied.
- xr_ai_vllm.serve_nim(
- *,
- image: str,
- container_name: str,
- log_prefix: str,
- http_port: int,
- grpc_port: int | None = None,
- nim_cache: pathlib.Path,
- cuda_visible_devices: str | None = None,
- extra_env: dict[str, str] | None = None,
- ready_file: pathlib.Path | None = None,
Pull (if needed) and run a NIM container, blocking until stopped.
Readiness is
/v1/health/readyon http_port. First start includes the NGC engine download (multi-GB), so expect a long cold start; the mounted nim_cache makes subsequent starts fast.
- xr_ai_vllm.DEFAULT_IMAGE = 'nvcr.io/nvidia/vllm:26.08-py3'#
Default NGC vLLM image used when a service does not override
vllm_image.Individual services may pin a newer image when required by their model.
- xr_ai_vllm.serve(
- *,
- backend: str,
- persistent: bool,
- image: str = DEFAULT_IMAGE,
- container_name: str,
- log_prefix: str,
- model: str,
- extra_serve_args: list[str],
- host: str,
- port: int,
- model_cache: pathlib.Path,
- hf_token: str | None = None,
- cuda_visible_devices: str | None = None,
- extra_env: dict[str, str] | None = None,
- extra_pip: list[str] | None = None,
- ready_file: pathlib.Path | None = None,
- spark_uma: bool = False,
Launch vLLM via backend (“pip” or “docker”).
extra_serve_args are the flags appended after vllm serve <model> — everything past the model id (e.g.
--served-model-name,--max-num-seqs,--reasoning-parser, …). They are passed verbatim, so caller-side flag construction is unchanged from the per-service wrappers’ previous inline argv.persistent controls the pip-mode lifecycle only:
True— vLLM pip process starts in a new session so it survives wrapper restarts. Cleanup is via stop_persistent_servers.False— die with the wrapper.
For the docker backend persistent is ignored: the container always runs foreground with
start_new_session=True, so it escapes the launcher’s process group regardless. UseProcess(..., launch_mode="persist")in the orchestratormain.pyto tell the launcher not to kill the wrapper on shutdown.container_name is only consulted in docker mode. Use a stable, service-specific name (e.g.
xr-ai-vllm-<entry-point>) so the stop helper can find it.Docker mode verifies a Xet-capable Hub inside the container and repairs a missing or incompatible
hf-xetwheel. extra_pip is an additional docker-only list of pip-installable package specs for model architectures whose wheels the image doesn’t bundle. Silently ignored in pip mode (deps belong in the wrapper’s pyproject.toml there).spark_uma enables the DGX Spark cold-start safeguards in docker mode: prefetching and syncing the Hugging Face snapshot before CUDA starts, and one bounded restart of a container attempt launched by this wrapper after a non-container-OOM CUDA driver-allocation failure. Pip mode ignores this Docker lifecycle option, preserving the one-field backend switch used by the service YAML files.
- xr_ai_vllm.stop_persistent_servers(services: list[tuple[str, int]]) bool#
Stop persisted servers and report whether every discovered server stopped.
services is a list of
(label, port)tuples. For each entry:Look for a docker container labelled
xr-ai-vllm.port=<port>(stamped at start time by the vLLM wrapper) anddocker stopit.Fall back to port → pid for pip-mode vLLM or in-process servers (e.g. STT). Pocket TTS is signalled as a complete process group; other local servers are signalled by PID.
A missing container and listener is already stopped. Output is print-style with
[<label>] …prefixes. Discovery errors and listeners that are not identified as xr-ai services fail closed without sending a signal.