Ray Serve (LLM)
Gets an OpenAI-compatible LLM endpoint running on Ray Serve, scaled across replicas and nodes, observable, and
upgradable, on a plain Ray cluster or on Kubernetes through KubeRay. Verified against Ray 2.59.0 and KubeRay
v1.7.1 (2026-10-11).
Scope: Ray Serve LLM (ray.serve.llm) with vLLM as the engine, plus the KubeRay operator that runs it.
Engine flags themselves belong to the vllm skill; llm-d, the inference gateway and autoscaling by KEDA are
sibling skills.
Work through the steps in order. Load a reference only when a step names it.
Discover first
Read-only. Never print tokens.
# Local Ray
command -v ray serve && ray --version
python3 -c "import ray, vllm; print(ray.__version__, vllm.__version__)" 2>&1 | tail -1
ray status 2>&1 | head -30 # nodes, GPUs, pending demands
serve status 2>&1 | head -40 # applications and replica states
curl -s -m 3 http://127.0.0.1:8265/api/version # dashboard / jobs API
curl -s -m 3 http://127.0.0.1:8000/v1/models | jq '.data[].id'
# Hardware
nvidia-smi --query-gpu=name,memory.total,driver_version --format=csv 2>/dev/null
# Kubernetes
kubectl get crd | grep -E 'ray.io' ; helm list -A | grep -i kuberay
kubectl get rayservice,raycluster -A 2>/dev/null
kubectl get nodes -o custom-columns=NAME:.metadata.name,GPU:.status.allocatable.nvidia\\.com/gpu
Decision flow
- One model, one box, no Ray needed? Use the
vllm skill. Ray Serve earns its place when you want
several replicas with request-level autoscaling, cross-node TP/PP, DP attention for MoE, custom routing,
or you already run Ray.
- No Ray yet ->
references/install.md: pip install "ray[llm]" or the rayproject/ray-llm image.
- Write one
LLMConfig per model (references/serve-config.md, templates/serve-config.yaml):
model_loading_config, accelerator_type, engine_kwargs, deployment_config.autoscaling_config.
- Model larger than one GPU?
engine_kwargs.tensor_parallel_size (and pipeline_parallel_size across
nodes), placement groups: references/parallelism-multinode.md.
- Kubernetes? Install KubeRay and apply a
RayService: references/kubernetes-kuberay.md,
templates/rayservice-llm.yaml.
- Traffic shape: shared prompts -> prefix/KV-aware routing; many adapters -> multi-LoRA; separate
prefill and decode ->
build_pd_openai_app: references/features.md.
- Scale and tune:
target_ongoing_requests, max_ongoing_requests, delays, scale to zero:
references/scaling-and-tuning.md.
- Observe:
references/observability.md. Upgrade: references/updating.md.
- Broken:
references/troubleshooting.md.
Quick start (single node)
pip install "ray[llm]"
cat > config.yaml <<'YAML'
applications:
- name: llm_app
route_prefix: "/"
import_path: ray.serve.llm:build_openai_app
args:
llm_configs:
- model_loading_config:
model_id: qwen-0.5b
model_source: Qwen/Qwen2.5-0.5B-Instruct
accelerator_type: A10G # set to the GPU you have (see references/serve-config.md)
deployment_config:
autoscaling_config: {min_replicas: 1, max_replicas: 2}
YAML
serve run config.yaml # foreground; Ctrl-C stops it
curl -s http://127.0.0.1:8000/v1/chat/completions -H 'Content-Type: application/json' \
-d '{"model":"qwen-0.5b","messages":[{"role":"user","content":"Say hi"}],"max_tokens":32}' | jq '.choices[0].message'
The Authorization header is not checked by Ray Serve (the docs use Bearer fake-key); protect the endpoint
with a gateway or network policy. Use serve deploy config.yaml to hand the config to a running cluster, and
serve status to follow it.
Rules
- Ask before changing the system. Installs, Helm releases, CRDs, RayService applies, Services or Ingresses
and scale changes need approval and an undo path (
references/updating.md).
- Secrets never touch output.
HF_TOKEN goes into a Kubernetes Secret (secretKeyRef) or runtime_env
read from the environment, never typed into a YAML you show. Create Secrets from 0600 files.
- No auth in Serve.
/v1 has no API key check. Keep it on ClusterIP or loopback and put LiteLLM,
an Ingress with auth or a gateway in front. The Ray dashboard (8265) can run jobs: never expose it.
- Pin versions. Image
rayproject/ray-llm:<ray>-py312-cu130 (check tags), matching rayVersion and
the KubeRay operator; never latest or nightly. Each Ray release is tested with one vLLM version
(references/install.md).
- Set
accelerator_type so replicas land on the right GPU, and make Kubernetes GPU limits match
tensor_parallel_size * pipeline_parallel_size per replica.
- Bake weights or mirror them. Per-replica Hugging Face downloads make scale-up slow; use a cloud mirror
(
model_source: {bucket_uri: ...}), a shared volume or the image.
- Head node: zero GPUs. Set
num-cpus: "0" and num-gpus: "0" on the head so no model replica runs there.
- Measure after every autoscaling or routing change, with versions recorded.
Facts that surprise people (Ray 2.59.0)
- Only
model_loading_config is required in LLMConfig; llm_engine supports "vLLM"; SGLang goes through
server_cls (alpha integration).
engine_kwargs are vLLM engine arguments in snake_case (max_model_len, gpu_memory_utilization);
disable_log_stats=True is rejected while log_engine_metrics is on (the default).
- Serve defaults are small:
max_ongoing_requests 5 and target_ongoing_requests 2 for ordinary deployments,
so raise them for LLM replicas (KubeRay sample uses 128 and 64). downscale_delay_s defaults to 600.
num_replicas: "auto" enables Serve autoscaling; replica scale needs the Ray autoscaler (KubeRay worker
group minReplicas/maxReplicas) to add GPU nodes.
- Prefix-aware routing needs
enable_prefix_caching: true in engine_kwargs; it is alpha, as is KVAwareRouter.
- Data-parallel deployments force
STRICT_PACK; GPUs needed = num_replicas * data_parallel_size * tensor_parallel_size.
- Multi-LoRA:
max_loras must equal max_num_adapters_per_replica; query as <model_id>:<adapter_folder>.
- The Ray/vLLM compatibility table lags: it listed 2.58.0 with vLLM 0.26.0 and nightly with 0.27.0, with no
2.59.0 row, when verified. Check
pip show vllm inside the image.
Workflows
Serve a model on a Ray cluster
Deploy on Kubernetes with KubeRay
Scale replicas and nodes
Debug a failure
Reference index
references/install.md: pip, ray-llm images, vLLM compatibility, KubeRay Helm.
references/serve-config.md: LLMConfig fields, deployment_config, YAML, serve CLI.
references/parallelism-multinode.md: TP/PP, placement groups, data parallel attention, expert parallel.
references/features.md: routers, prefill/decode, multi-LoRA, direct streaming, SGLang, cloud mirrors.
references/scaling-and-tuning.md: autoscaling knobs, scale to zero, cold start.
references/kubernetes-kuberay.md: RayService, worker groups, GPU scheduling, upgrades, GCS fault tolerance.
references/observability.md: metrics, dashboards, logs, health.
references/updating.md: Ray and KubeRay upgrades, rollback.
references/troubleshooting.md: symptom to cause to fix.
references/combos/litellm-gateway.md: put LiteLLM in front for keys and budgets.
references/combos/keda-vllm-pods.md: when KEDA fits and when it does not.
templates/: serve-config.yaml, rayservice-llm.yaml.
Companion skills
vllm: engine flags, parsers, quantization. Install: npx skills add ScaleDockHQ/llm-skills --skill vllm.
nvidia-gpu-operator: GPU drivers and device plugin on Kubernetes. Install: npx skills add ScaleDockHQ/llm-skills --skill nvidia-gpu-operator.
keda: event-driven pod autoscaling on queue and vLLM metrics. Install: npx skills add ScaleDockHQ/llm-skills --skill keda.
gateway-api-inference-extension: model-aware load balancing for plain vLLM pods. Install: npx skills add ScaleDockHQ/llm-skills --skill gateway-api-inference-extension.
litellm and llm-gateway: keys, routing, fallbacks. Install: npx skills add ScaleDockHQ/llm-skills --skill litellm.
multi-node-inference, disaggregated-serving, prefix-aware-routing: technique-level guidance. Install: npx skills add ScaleDockHQ/llm-skills --skill multi-node-inference.
multi-lora-serving: adapter strategy across engines. Install: npx skills add ScaleDockHQ/llm-skills --skill multi-lora-serving.
1---2name: ray-serve3description: Serve LLMs on a Ray cluster with Ray Serve LLM (ray.serve.llm, LLMConfig, build_openai_app, `serve run|deploy|status`, rayproject/ray-llm) and run it on Kubernetes with KubeRay (RayService, RayCluster). Use for vLLM replicas with autoscaling, tensor/pipeline/data parallel, prefill/decode, prefix- or KV-aware routing, multi-LoRA, Prometheus metrics, zero-downtime upgrades, head-node fault tolerance. Fixes pending replicas, gated model 401, slow downloads, NIXL libcudart. Not for plain vLLM (vllm), llm-d, or KEDA.4license: MIT5compatibility: Linux with NVIDIA GPUs (Python 3.12 images), Docker or a Kubernetes cluster with the GPU operator, bash, curl, jq, kubectl and helm for KubeRay. Installs, cluster changes and exposure need the user's explicit approval.6metadata:7 source: https://skillmd.com/skills/scaledockhq/ray-serve8 author: ScaleDockHQ9 version: "0.1.0"10---1112# Ray Serve (LLM)1314Gets an OpenAI-compatible LLM endpoint running on Ray Serve, scaled across replicas and nodes, observable, and15upgradable, on a plain Ray cluster or on Kubernetes through KubeRay. Verified against Ray 2.59.0 and KubeRay16v1.7.1 (2026-10-11).1718**Scope:** Ray Serve LLM (`ray.serve.llm`) with vLLM as the engine, plus the KubeRay operator that runs it.19Engine flags themselves belong to the `vllm` skill; llm-d, the inference gateway and autoscaling by KEDA are20sibling skills.2122Work through the steps in order. Load a reference only when a step names it.2324## Discover first2526Read-only. Never print tokens.2728```bash29# Local Ray30command -v ray serve && ray --version31python3 -c "import ray, vllm; print(ray.__version__, vllm.__version__)" 2>&1 | tail -132ray status 2>&1 | head -30 # nodes, GPUs, pending demands33serve status 2>&1 | head -40 # applications and replica states34curl -s -m 3 http://127.0.0.1:8265/api/version # dashboard / jobs API35curl -s -m 3 http://127.0.0.1:8000/v1/models | jq '.data[].id'3637# Hardware38nvidia-smi --query-gpu=name,memory.total,driver_version --format=csv 2>/dev/null3940# Kubernetes41kubectl get crd | grep -E 'ray.io' ; helm list -A | grep -i kuberay42kubectl get rayservice,raycluster -A 2>/dev/null43kubectl get nodes -o custom-columns=NAME:.metadata.name,GPU:.status.allocatable.nvidia\\.com/gpu44```4546## Decision flow47481. **One model, one box, no Ray needed?** Use the `vllm` skill. Ray Serve earns its place when you want49 several replicas with request-level autoscaling, cross-node TP/PP, DP attention for MoE, custom routing,50 or you already run Ray.512. **No Ray yet** -> `references/install.md`: `pip install "ray[llm]"` or the `rayproject/ray-llm` image.523. **Write one `LLMConfig` per model** (`references/serve-config.md`, `templates/serve-config.yaml`):53 `model_loading_config`, `accelerator_type`, `engine_kwargs`, `deployment_config.autoscaling_config`.544. **Model larger than one GPU?** `engine_kwargs.tensor_parallel_size` (and `pipeline_parallel_size` across55 nodes), placement groups: `references/parallelism-multinode.md`.565. **Kubernetes?** Install KubeRay and apply a `RayService`: `references/kubernetes-kuberay.md`,57 `templates/rayservice-llm.yaml`.586. **Traffic shape**: shared prompts -> prefix/KV-aware routing; many adapters -> multi-LoRA; separate59 prefill and decode -> `build_pd_openai_app`: `references/features.md`.607. **Scale and tune**: `target_ongoing_requests`, `max_ongoing_requests`, delays, scale to zero:61 `references/scaling-and-tuning.md`.628. **Observe**: `references/observability.md`. **Upgrade**: `references/updating.md`.639. **Broken**: `references/troubleshooting.md`.6465## Quick start (single node)6667```bash68pip install "ray[llm]"69cat > config.yaml <<'YAML'70applications:71- name: llm_app72 route_prefix: "/"73 import_path: ray.serve.llm:build_openai_app74 args:75 llm_configs:76 - model_loading_config:77 model_id: qwen-0.5b78 model_source: Qwen/Qwen2.5-0.5B-Instruct79 accelerator_type: A10G # set to the GPU you have (see references/serve-config.md)80 deployment_config:81 autoscaling_config: {min_replicas: 1, max_replicas: 2}82YAML83serve run config.yaml # foreground; Ctrl-C stops it84curl -s http://127.0.0.1:8000/v1/chat/completions -H 'Content-Type: application/json' \85 -d '{"model":"qwen-0.5b","messages":[{"role":"user","content":"Say hi"}],"max_tokens":32}' | jq '.choices[0].message'86```8788The `Authorization` header is not checked by Ray Serve (the docs use `Bearer fake-key`); protect the endpoint89with a gateway or network policy. Use `serve deploy config.yaml` to hand the config to a running cluster, and90`serve status` to follow it.9192## Rules9394- **Ask before changing the system.** Installs, Helm releases, CRDs, RayService applies, Services or Ingresses95 and scale changes need approval and an undo path (`references/updating.md`).96- **Secrets never touch output.** `HF_TOKEN` goes into a Kubernetes Secret (`secretKeyRef`) or `runtime_env`97 read from the environment, never typed into a YAML you show. Create Secrets from `0600` files.98- **No auth in Serve.** `/v1` has no API key check. Keep it on ClusterIP or loopback and put LiteLLM,99 an Ingress with auth or a gateway in front. The Ray dashboard (8265) can run jobs: never expose it.100- **Pin versions.** Image `rayproject/ray-llm:<ray>-py312-cu130` (check tags), matching `rayVersion` and101 the KubeRay operator; never `latest` or `nightly`. Each Ray release is tested with one vLLM version102 (`references/install.md`).103- **Set `accelerator_type`** so replicas land on the right GPU, and make Kubernetes GPU limits match104 `tensor_parallel_size * pipeline_parallel_size` per replica.105- **Bake weights or mirror them.** Per-replica Hugging Face downloads make scale-up slow; use a cloud mirror106 (`model_source: {bucket_uri: ...}`), a shared volume or the image.107- **Head node: zero GPUs.** Set `num-cpus: "0"` and `num-gpus: "0"` on the head so no model replica runs there.108- **Measure** after every autoscaling or routing change, with versions recorded.109110## Facts that surprise people (Ray 2.59.0)111112- Only `model_loading_config` is required in `LLMConfig`; `llm_engine` supports `"vLLM"`; SGLang goes through113 `server_cls` (alpha integration).114- `engine_kwargs` are vLLM engine arguments in snake_case (`max_model_len`, `gpu_memory_utilization`);115 `disable_log_stats=True` is rejected while `log_engine_metrics` is on (the default).116- Serve defaults are small: `max_ongoing_requests` 5 and `target_ongoing_requests` 2 for ordinary deployments,117 so raise them for LLM replicas (KubeRay sample uses 128 and 64). `downscale_delay_s` defaults to 600.118- `num_replicas: "auto"` enables Serve autoscaling; replica scale needs the Ray autoscaler (KubeRay worker119 group `minReplicas`/`maxReplicas`) to add GPU nodes.120- Prefix-aware routing needs `enable_prefix_caching: true` in `engine_kwargs`; it is alpha, as is `KVAwareRouter`.121- Data-parallel deployments force `STRICT_PACK`; GPUs needed = `num_replicas * data_parallel_size *122 tensor_parallel_size`.123- Multi-LoRA: `max_loras` must equal `max_num_adapters_per_replica`; query as `<model_id>:<adapter_folder>`.124- The Ray/vLLM compatibility table lags: it listed 2.58.0 with vLLM 0.26.0 and nightly with 0.27.0, with no125 2.59.0 row, when verified. Check `pip show vllm` inside the image.126127## Workflows128129### Serve a model on a Ray cluster130131- [ ] Run discovery; install (`references/install.md`).132- [ ] Write the config (`templates/serve-config.yaml`); `serve run` first, `serve deploy` after.133- [ ] `serve status` shows `RUNNING`; run a chat completion and a streamed one.134- [ ] Load test at the real concurrency; adjust `max_ongoing_requests` (`references/scaling-and-tuning.md`).135136### Deploy on Kubernetes with KubeRay137138- [ ] Confirm GPU nodes and the NVIDIA GPU operator (skill `nvidia-gpu-operator`).139- [ ] Install the operator by Helm, pinned to the chart version.140- [ ] Apply `templates/rayservice-llm.yaml` after setting image tag, GPUs and the Secret.141- [ ] `kubectl get rayservice`, then `port-forward svc/<name>-serve-svc 8000` and test.142- [ ] Add GCS fault tolerance and an upgrade strategy before production.143144### Scale replicas and nodes145146- [ ] Replica level: `autoscaling_config`. Node level: KubeRay worker group min/max (and the Ray autoscaler).147- [ ] Optional queue/GPU-driven pod scaling outside Ray: skill `keda` (applies to vLLM pods, not Ray Serve replicas).148149### Debug a failure150151- [ ] Capture `serve status`, `ray status`, and the replica log tail, then match `references/troubleshooting.md`.152153## Reference index154155- `references/install.md`: pip, `ray-llm` images, vLLM compatibility, KubeRay Helm.156- `references/serve-config.md`: `LLMConfig` fields, `deployment_config`, YAML, `serve` CLI.157- `references/parallelism-multinode.md`: TP/PP, placement groups, data parallel attention, expert parallel.158- `references/features.md`: routers, prefill/decode, multi-LoRA, direct streaming, SGLang, cloud mirrors.159- `references/scaling-and-tuning.md`: autoscaling knobs, scale to zero, cold start.160- `references/kubernetes-kuberay.md`: RayService, worker groups, GPU scheduling, upgrades, GCS fault tolerance.161- `references/observability.md`: metrics, dashboards, logs, health.162- `references/updating.md`: Ray and KubeRay upgrades, rollback.163- `references/troubleshooting.md`: symptom to cause to fix.164- `references/combos/litellm-gateway.md`: put LiteLLM in front for keys and budgets.165- `references/combos/keda-vllm-pods.md`: when KEDA fits and when it does not.166- `templates/`: `serve-config.yaml`, `rayservice-llm.yaml`.167168## Companion skills169170- `vllm`: engine flags, parsers, quantization. Install: `npx skills add ScaleDockHQ/llm-skills --skill vllm`.171- `nvidia-gpu-operator`: GPU drivers and device plugin on Kubernetes. Install: `npx skills add ScaleDockHQ/llm-skills --skill nvidia-gpu-operator`.172- `keda`: event-driven pod autoscaling on queue and vLLM metrics. Install: `npx skills add ScaleDockHQ/llm-skills --skill keda`.173- `gateway-api-inference-extension`: model-aware load balancing for plain vLLM pods. Install: `npx skills add ScaleDockHQ/llm-skills --skill gateway-api-inference-extension`.174- `litellm` and `llm-gateway`: keys, routing, fallbacks. Install: `npx skills add ScaleDockHQ/llm-skills --skill litellm`.175- `multi-node-inference`, `disaggregated-serving`, `prefix-aware-routing`: technique-level guidance. Install: `npx skills add ScaleDockHQ/llm-skills --skill multi-node-inference`.176- `multi-lora-serving`: adapter strategy across engines. Install: `npx skills add ScaleDockHQ/llm-skills --skill multi-lora-serving`.