feat: llm-d (EPP+Envoy) router backend (#2697)
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
* refactor: drop client-side DP-rank pinning for external-LB
With external-LB data parallelism each DP rank is its own API server on its
own port (the URL is the rank selector), so the client no longer needs the
hybrid-LB `X-data-parallel-rank` header to pin a rollout to an internal DP
shard. Remove the `dp_rank_count` client field + its auto-setup and the
per-rank client expansion: one client per base URL, no rank header. The
router (vllm-router or llm-d EPP) balances across the per-rank endpoints.
This also fixes llm-d routing: the EPP forwards the header to the dp=1
backend, which rejected it ("data_parallel_rank N is out of range").
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat: llm-d (EPP+Envoy) router backend
Add llm-d as a second router backend alongside vllm-router, selected via
`[inference.deployment.router] type = "llm-d"`. Built on the external-LB
launch substrate — the per-rank vLLM engines launch identically; only the
router control plane differs.
- `LlmdRouterConfig`: discriminated-union member with `scorers` (base) +
per-profile `prefill_scorer_overrides`/`decode_scorer_overrides`,
`non_cached_tokens`, `decode_sidecar_port`, and a known-scorer validator.
- `launch_router` helper gains an llm-d branch: renders per-replica EPP +
Envoy + file-discovery endpoints and launches `epp` + `envoy` instead of
vllm-router. Call sites stay router-agnostic.
- pd-sidecar on each decode node (P/D) for remote-prefill orchestration + NIXL.
- Entrypoints pass the `router` config object to the templates.
- Reject `enable_return_routed_experts` with llm-d (breaks P/D, unverified
for multi-node).
- SLURM cleanup also clears stale `epp`/`envoy`/`pd-sidecar` processes.
- Presets under `templates/llmd/` + `scripts/install_llmd.sh`; docs + install skill.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(inference): mooncake-store + llm-d EPP coexistence on SLURM P/D
- per-rank VLLM_RPC_BASE_PATH: external-LB runs one engine per process (all
data_parallel_rank_local 0), so the mooncake-store lookup ipc socket collided
on a node-shared dir; key it by $port. Also avoids an absent submit-node TMPDIR.
- EPP --grpc-health-port 9003 -> 9013: 9003 collided with mooncake_master's
metrics server on the shared replica-head node, which killed the EPP.
- mooncake_master -default_kv_lease_ttl=3600000: KV blocks were expiring (5s
default) before the decode side reused them.
- envoy circuit_breakers raised to 100000 on backend + epp clusters: the default
(~1024) overflowed at high inflight concurrency -> "reset reason: overflow" 500s.
- pd-sidecar launches on every decode node (not just the replica head), else
decode nodes past the head advertise endpoints nothing serves.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Feat: dockerless llmd install
* chore(configs): add GLM-5.1 llm-d disaggregated RL config
End-to-end RL config used for the GLM-5.1-FP8 llm-d (EPP+Envoy) P/D run:
12 train nodes + 16 inference nodes (8 prefill x2 / 8 decode x2), mooncake KV
store, r2e env. Lives alongside the existing glm5 disaggregated inference preset.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore(configs): move GLM-5.1 llm-d RL config to dedicated configs/glm5_llmd/
Relocate the end-to-end GLM-5.1-FP8 llm-d (EPP+Envoy) P/D RL config into its own
configs/glm5_llmd/rl.toml (out of glm5_disagg_inference) and refresh it to the
latest tuned version.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat(inference): per-role prefill/decode vLLM overrides for disaggregated P/D
Add `prefill_vllm_overrides` / `decode_vllm_overrides` to the disaggregated
inference deployment config (mirrors the existing `*_env_overrides`): extra
vLLM config options merged into the per-role `--vllm-extra` JSON for prefill
vs decode ranks on SLURM. Rendered via a small `vllm_overrides_fragment` helper
into the `ROLE_EXTRA` string in the inference / multi-node-RL sbatch templates.
Needed by configs/glm5_llmd/rl.toml (sets `decode_vllm_overrides`), which
otherwise fails `extra="forbid"` validation in test_load_configs.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore(configs): enable prefill dual-batch-overlap in glm5_llmd config
Set prefill_vllm_overrides = {enable_dbo = true} (the inference-side perf knob
tuned during the GLM-5.1 run). Batch size / num-concurrent / node-scale knobs
left as-is — those are run-specific, not portable config.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore(configs): tune glm5_llmd prefill/decode replicas (4 prefill / 1 decode)
num_prefill_replicas 2->4, num_decode_replicas 2->1 — the disaggregation split
found to perform best for GLM-5.1 (prefill is the bottleneck; one wide decode
replica maximizes decode KV/batching).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs: add GLM-5 llm-d example (16-node / 131K trainer) (#2854)
* docs: add GLM-5 llm-d example (16-node / 131K trainer)
Move the glm5_llmd config from configs/ into examples/glm5_llmd/ with a
README, mirroring the other GLM-5 example. Frame llm-d as the faster
router for GLM-5 and document the placeholders users must tweak
(output_dir, slurm partition, mooncake device_name).
Tune the example for a 16-node trainer: seq_len=131072, num_train_nodes=16,
cp=4, and adamw optimizer.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs: reword GLM-5 llm-d example entry as one-line SLURM deploy
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs: highlight GLM-5 llm-d one-line SLURM deploy in Overview
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Signed-off-by: Matej Sirovatka <54212263+S1ro1@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: faresobeid <fares@primeintellect.ai>
Co-authored-by: samsja <55492238+samsja@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
faresobeid
samsja
parent
533e992ad2
commit
e035135126
@@ -38,6 +38,7 @@ PRIME-RL is a framework for large-scale reinforcement learning. It is designed t
|
||||
5. Multi-node deployment with Slurm and Kubernetes support.
|
||||
6. Multimodal support for VLMs such as Qwen3-VL.
|
||||
7. Hackable, modular, and extensible by design.
|
||||
8. One-line SLURM deployment for frontier models — e.g. [`GLM-5` FP8 with P/D disaggregation, the `llm-d` router, and Mooncake KV offload](examples/glm5_llmd/README.md).
|
||||
|
||||
|
||||
## Models support
|
||||
@@ -221,6 +222,7 @@ These guides are designed to be run from a Slurm cluster but can also be adapted
|
||||
3. [**Intellect-3.1**](examples/Intellect-3.1/README.md): Reproduce our `INTELLECT-3.1` training run.
|
||||
4. [**MiniMax-M2.5 SWE**](examples/minimax_m2.5_swe/README.md): Train `MiniMax-M2.5` on agentic SWE tasks.
|
||||
5. [**High-throughput GLM-5**](examples/glm5_pd_disag/README.md): Train `GLM-5` with PD disaggregation and FP8 inference on SWE.
|
||||
6. [**High-throughput GLM-5 (llm-d)**](examples/glm5_llmd/README.md): One-line SLURM deployment for `GLM-5` FP8 with P/D disaggregation, the `llm-d` router, and Mooncake KV offload — the faster way to run `GLM-5`.
|
||||
|
||||
## Docs
|
||||
|
||||
|
||||
+17
-4
@@ -30,7 +30,7 @@ We support 3 distinct deployment shapes:
|
||||
|
||||
Most of the features are supported for all deployment shapes, with few exceptions. These exceptions are rejected on validation.
|
||||
|
||||
You can select the deployment shape with `InferenceDeploymentConfig` in your config file. This is a config-field that allows you to set the deployment shape, deployment-specific knobs such as `num_nodes`, `num_replicas`, `router_port`, `backend_port`, etc.
|
||||
You can select the deployment shape with `InferenceDeploymentConfig` in your config file. This is a config-field that allows you to set the deployment shape, deployment-specific knobs such as `num_nodes`, `num_replicas`, `backend_port`, and a `[...deployment.router]` block, etc.
|
||||
|
||||
```toml
|
||||
[inference.deployment]
|
||||
@@ -102,7 +102,7 @@ tp = 2
|
||||
dp = 4
|
||||
```
|
||||
|
||||
This configuration will run 2 independent vLLM replicas, each with `tp=2` and `dp=4`. Routing will be handled by the `vllm-router` instance running on the same node as the 1st replica. We aim to support more advanced routing options, such as `llm-d` or `dynamo` in the future. You can read more about the supported routing options in the [router](#router) section.
|
||||
This configuration will run 2 independent vLLM replicas, each with `tp=2` and `dp=4`. Routing is handled by a router instance running on the same node as the 1st replica — either `vllm-router` (default) or the upstream `llm-d` EPP+Envoy, selected via the `[...deployment.router]` block. You can read more about the supported routing options in the [router](#router) section.
|
||||
|
||||
### Wide-EP
|
||||
|
||||
@@ -167,9 +167,22 @@ This will run 3 inference replicas, each running on 6 nodes. Each replica will r
|
||||
|
||||
## Router
|
||||
|
||||
We use our own fork of [vllm-router](https://github.com/PrimeIntellect-ai/router) as the request handler. We plan to support more advanced proxy options in the future.
|
||||
Multi-node and disaggregated deployments front their vLLM backends with a router, configured via a discriminated `[...deployment.router]` block (`type = "vllm-router" | "llm-d"`):
|
||||
|
||||
Right now, router handles 2 most important things:
|
||||
```toml
|
||||
[inference.deployment.router] # or [deployment.router] for the standalone inference entrypoint
|
||||
type = "llm-d" # "vllm-router" (default) or "llm-d"
|
||||
# llm-d-only knobs (all optional):
|
||||
scorers = { "prefix-cache-scorer" = 3.0, "active-request-scorer" = 2.0 } # base, applied to every profile
|
||||
prefill_scorer_overrides = { "queue-scorer" = 2.0, "kv-cache-utilization-scorer" = 2.0 } # merged onto the P/D prefill profile
|
||||
decode_scorer_overrides = {} # merged onto the P/D decode profile
|
||||
non_cached_tokens = 16 # below this many non-cached prompt tokens, skip remote prefill (P/D)
|
||||
```
|
||||
|
||||
- **`vllm-router`** (default) — our fork of [vllm-router](https://github.com/PrimeIntellect-ai/router). Knob: `policy`.
|
||||
- **`llm-d`** — the upstream [llm-d](https://llm-d.ai) Endpoint Picker (EPP) + Envoy proxy. Routing combines **prefix-cache affinity** (grouped rollouts reuse a cached prefix and skip prefill) with the **`active-request-scorer`** — an in-flight load balancer that spreads requests across ranks immediately, unlike the metrics-scraped `queue-scorer` / `kv-cache-utilization-scorer` / `load-aware-scorer` (which lag and concentrate bursts of same-prefix requests). The scorer weights follow the upstream llm-d P/D guide; tune via `scorers` (base) + `prefill_scorer_overrides` / `decode_scorer_overrides` (per-profile, P/D). Does not support `enable_return_routed_experts` (router replay).
|
||||
|
||||
Both backends support the 2 most important things:
|
||||
- Request routing - KV cache re-use and balanced routing
|
||||
- P/D disaggregation - handling the prefill and decode stages separately
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
# High-throughput GLM-5 with llm-d
|
||||
|
||||
This example trains `GLM-5.1` with RL on agentic SWE tasks using P/D disaggregation, FP8 inference, and a Mooncake distributed CPU KV store — fronted by the upstream [**llm-d**](https://llm-d.ai) router (Endpoint Picker + Envoy).
|
||||
|
||||
**llm-d is the faster way to run GLM-5.** It is the recommended router backend for large GLM-5 runs: its `active-request-scorer` is an in-flight load balancer that spreads requests across ranks immediately, instead of relying on metrics that are scraped on a delay (as the default `vllm-router` does). Combined with prefix-cache affinity for grouped rollouts, this keeps prefill and decode ranks evenly loaded under the bursty request pattern of RL. If you want the simpler default router instead, see the [GLM-5 PD disaggregation example](../glm5_pd_disag/README.md).
|
||||
|
||||
## Requirements
|
||||
|
||||
You need access to a Slurm cluster with at least **32 nodes** (16 trainer + 16 inference, 8 GPUs each) and a shared filesystem. In this guide we assume the NFS is mounted at `/shared`; you can change it to your own path.
|
||||
|
||||
You also need prime-rl cloned on your cluster into the shared filesystem.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/PrimeIntellect-ai/prime-rl.git /shared/prime-rl
|
||||
cd /shared/prime-rl
|
||||
uv sync --all-extras
|
||||
```
|
||||
|
||||
### Install llm-d
|
||||
|
||||
The llm-d router ships as vendored binaries (`epp`, `envoy`, `pd-sidecar`). Build them once into `third_party/llmd/bin`:
|
||||
|
||||
```bash
|
||||
bash scripts/install_llmd.sh
|
||||
```
|
||||
|
||||
You might also want to create a `.env` file inside the prime-rl directory to store environment variables used during training like W&B and Hugging Face tokens. The `.env` file is automatically sourced during training.
|
||||
|
||||
```bash
|
||||
touch .env
|
||||
echo "WANDB_API_KEY=your_wandb_api_key" >> .env
|
||||
echo "HUGGINGFACE_TOKEN=your_huggingface_token" >> .env
|
||||
```
|
||||
|
||||
### sandbox
|
||||
|
||||
The SWE environment is configured to use Prime Intellect Sandboxes. You can find more information about the sandboxes [here](https://docs.primeintellect.ai/sandboxes/overview). You will need to create a sandbox account and add the credentials to the `.env` file. Alternatively, you can adapt the code of the environment to use your own sandbox implementation.
|
||||
|
||||
## Tweak before launching
|
||||
|
||||
This config is tuned for our cluster — a few values **must** be adapted to yours before you run. Search the config for these markers:
|
||||
|
||||
- **`output_dir`** (`# FILL IN`) — point it at your shared filesystem.
|
||||
- **`[slurm] partition`** (`# FILL IN`) — set it to your cluster's Slurm partition.
|
||||
- **`[inference.kv_cache_offload] device_name`** (`# do it yourself`) — the list of RDMA NICs for Mooncake. Auto-detection is unreliable, so set it by hand from `nvidia-smi topo -m` on your nodes.
|
||||
|
||||
A few more knobs you may want to tune for your hardware:
|
||||
|
||||
- **Trainer parallelism** — this config assumes **16 trainer nodes** at **131K** sequence length with `cp = 4` (context parallel) and the `adamw` optimizer. If you have fewer trainer nodes, drop `seq_len`, lower `num_train_nodes`, and reduce `cp` accordingly.
|
||||
- **Scorer weights** (`[inference.deployment.router]`) — the `scorers` / `prefill_scorer_overrides` / `decode_scorer_overrides` weights follow the upstream llm-d P/D guide and are a good starting point; tune them if your prefill/decode balance drifts.
|
||||
- **Mooncake CPU pool** (`[inference.kv_cache_offload.cpu] num_bytes`) — defaults to 1TB/node; lower it if your nodes have less RAM.
|
||||
|
||||
## Tmux session
|
||||
|
||||
We recommend using the tmux helper to start the run and look at the logs.
|
||||
|
||||
From your Slurm head node:
|
||||
|
||||
```bash
|
||||
bash scripts/tmux.sh glm5-llmd /shared/outputs/glm5-llmd
|
||||
```
|
||||
|
||||
You can then attach to it by doing `tmux attach -t glm5-llmd`.
|
||||
|
||||
## Start the run
|
||||
|
||||
Run the following command to start the RL training:
|
||||
|
||||
PS: If using the tmux helper, you can run the command in the `Terminal` (window 0) pane and look at the logs in the `Logs` (window 1) pane.
|
||||
|
||||
```bash
|
||||
uv run rl @ examples/glm5_llmd/rl.toml --output-dir /shared/outputs/glm5-llmd
|
||||
```
|
||||
|
||||
Output of the command:
|
||||
```
|
||||
XXX:XX:XX INFO Wrote subconfigs to /shared/outputs/glm5-llmd/configs [rl.py::515]
|
||||
XXX:XX:XX INFO Wrote SLURM script to /shared/outputs/glm5-llmd/rl.sbatch [rl.py::534]
|
||||
XXX:XX:XX INFO Submitting: sbatch /shared/outputs/glm5-llmd/rl.sbatch [rl.py::540]
|
||||
XXX:XX:XX SUCCESS Submitted batch job YYYY
|
||||
|
||||
Logs:
|
||||
Trainer: tail -F /shared/outputs/glm5-llmd/logs/trainer.log
|
||||
Orchestrator: tail -F /shared/outputs/glm5-llmd/logs/orchestrator.log
|
||||
Inference: tail -F /shared/outputs/glm5-llmd/logs/inference.log
|
||||
Envs: tail -F /shared/outputs/glm5-llmd/logs/envs/*/*/*.log
|
||||
```
|
||||
@@ -0,0 +1,140 @@
|
||||
max_steps = 10000000
|
||||
seq_len = 131072
|
||||
output_dir = "/shared/outputs/glm5-llmd" # FILL IN: point at your shared filesystem
|
||||
clean_output_dir = true
|
||||
|
||||
[log]
|
||||
level = "debug"
|
||||
|
||||
[wandb]
|
||||
project = "glm5-llmd"
|
||||
name = "base"
|
||||
|
||||
[weight_broadcast]
|
||||
type = "nccl"
|
||||
port = 29502
|
||||
timeout = 12000
|
||||
quantize_in_weight_transfer = true
|
||||
|
||||
[deployment]
|
||||
type = "multi_node"
|
||||
num_train_nodes = 16
|
||||
num_infer_nodes = 16
|
||||
gpus_per_node = 8
|
||||
num_infer_replicas = 1
|
||||
|
||||
[inference.deployment]
|
||||
type = "disaggregated"
|
||||
num_prefill_nodes = 8
|
||||
num_prefill_replicas = 4
|
||||
num_decode_nodes = 8
|
||||
num_decode_replicas = 1
|
||||
# skip warmup for faster start in cost of some jit overhead early
|
||||
# ucx needs to be set else random segfaults, vllm can't autoset before importing for some reason
|
||||
prefill_env_overrides = {"VLLM_ENABLE_MOE_DP_CHUNK"="0", "VLLM_DEEP_GEMM_WARMUP"="skip", "UCX_RCACHE_MAX_UNRELEASED"="1024"}
|
||||
decode_env_overrides = {"VLLM_DEEP_GEMM_WARMUP"="skip", "UCX_RCACHE_MAX_UNRELEASED"="1024"}
|
||||
|
||||
# gives the most KV cache while keeping decent throughput, KV cache increase comes in from lower deep-ep LL static buffers
|
||||
prefill_vllm_overrides = {"enable_dbo"=true}
|
||||
decode_vllm_overrides = {"max_num_batched_tokens"=96, "max_num_seqs"=96}
|
||||
|
||||
[inference.deployment.router]
|
||||
type = "llm-d"
|
||||
scorers = { "prefix-cache-scorer" = 3.0 } # need some prefix-cache routing, however due to shared mooncake pool do low prio
|
||||
|
||||
prefill_scorer_overrides = { "queue-scorer" = 4.0, "active-request-scorer" = 5.0 } # prefill creates queues quite heavily, queue scorer to 4.0, active request at 5.0 is needed due to burstiness of early pipeline RL fill
|
||||
decode_scorer_overrides = { "active-request-scorer" = 5.0, "kv-cache-utilization-scorer" = 4.0, "queue-scorer" = 3.0 } # decode doesn't really create queue, it fills in KV cache fast, give 4.0
|
||||
non_cached_tokens = 128 # if <128 tokens, skip prefill go to decode immediately
|
||||
|
||||
[slurm]
|
||||
job_name = "glm5-llmd"
|
||||
partition = "all" # FILL IN: set to your cluster's partition
|
||||
|
||||
[trainer]
|
||||
dist_timeout_seconds = 1800
|
||||
enable_token_export = true
|
||||
|
||||
[trainer.model]
|
||||
name = "zai-org/GLM-5.1"
|
||||
impl = "custom"
|
||||
attn = "flash_attention_2" # ignored with GLM5
|
||||
fused_lm_head_token_chunk_size = 1024
|
||||
cp = 4 # context parallel for the 131K seq len
|
||||
ep = 8
|
||||
optim_cpu_offload = true
|
||||
fp8 = true
|
||||
|
||||
[trainer.model.ac]
|
||||
freq = 1
|
||||
|
||||
[trainer.model.compile]
|
||||
|
||||
[trainer.model.ac_offloading]
|
||||
max_inflight_activations = 1
|
||||
|
||||
[trainer.optim]
|
||||
type = "adamw"
|
||||
lr = 1e-6
|
||||
weight_decay = 0.0
|
||||
|
||||
[orchestrator]
|
||||
batch_size = 256
|
||||
rollouts_per_example = 16
|
||||
max_inflight_rollouts = 2048
|
||||
max_off_policy_steps = 8 # 16/32 can be better, 8 is more CPU stable
|
||||
|
||||
[orchestrator.model]
|
||||
name = "zai-org/GLM-5.1-FP8"
|
||||
|
||||
[orchestrator.renderer]
|
||||
name = "glm-5.1"
|
||||
preserve_all_thinking = true
|
||||
|
||||
[orchestrator.train.sampling]
|
||||
temperature = 1.0
|
||||
extra_body = {chat_template_kwargs = {clear_thinking = false}}
|
||||
|
||||
|
||||
[[orchestrator.train.env]]
|
||||
id = "rlm_swe"
|
||||
name = "r2e"
|
||||
num_workers = 16
|
||||
|
||||
[orchestrator.train.env.args]
|
||||
max_turns = 300
|
||||
timeout_seconds = 21600
|
||||
summarize_at_tokens = [35000, 80000]
|
||||
poll_interval = 5
|
||||
rlm_ref = "907115a79b2a50d193863e7ea1f3550acb4386f0"
|
||||
labels = ["glm5-llmd"]
|
||||
|
||||
[orchestrator.advantage]
|
||||
type = "default"
|
||||
|
||||
[inference]
|
||||
enable_expert_parallel = true
|
||||
# <0.80 because glm5 layers are too large for 0.85
|
||||
gpu_memory_utilization = 0.75
|
||||
enable_eplb = false
|
||||
use_deep_gemm = true
|
||||
enable_fp32_lm_head = true
|
||||
|
||||
[inference.model]
|
||||
name = "zai-org/GLM-5.1-FP8"
|
||||
max_model_len = 131072
|
||||
tool_call_parser = "glm47"
|
||||
reasoning_parser = "glm45"
|
||||
|
||||
# Speed up GLM-5.1 weight load: EP weight filtering + safetensors prefetch.
|
||||
[inference.vllm_extra]
|
||||
enable_ep_weight_filter = true
|
||||
safetensors_load_strategy = "prefetch"
|
||||
|
||||
# Mooncake distributed CPU KV store: 1TB/node shared pool across all inference nodes.
|
||||
[inference.kv_cache_offload]
|
||||
type = "mooncake"
|
||||
# Auto Detection is funky, do it yourself from nvidia-smi topo -m
|
||||
device_name = "mlx5_0,mlx5_3,mlx5_4,mlx5_5,mlx5_6,mlx5_9,mlx5_10,mlx5_11"
|
||||
|
||||
[inference.kv_cache_offload.cpu]
|
||||
num_bytes = 1_000_000_000_000 # 1TB per node - 16TB total CPU pool
|
||||
@@ -167,8 +167,26 @@ All2AllBackend = Literal[
|
||||
]
|
||||
|
||||
|
||||
# Known llm-d EPP scorer plugins (used to guard the ``scorers`` map against typos).
|
||||
KNOWN_SCORERS = frozenset(
|
||||
{
|
||||
"prefix-cache-scorer",
|
||||
"precise-prefix-cache-scorer",
|
||||
"queue-scorer",
|
||||
"kv-cache-utilization-scorer",
|
||||
"active-request-scorer",
|
||||
"load-aware-scorer",
|
||||
"running-requests-size-scorer",
|
||||
"token-load-scorer",
|
||||
"latency-scorer",
|
||||
"session-affinity-scorer",
|
||||
"lora-affinity-scorer",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class VllmRouterConfig(BaseConfig):
|
||||
"""PrimeIntellect vllm-router fronting the per-rank (external-LB) endpoints."""
|
||||
"""PrimeIntellect vllm-router."""
|
||||
|
||||
type: Literal["vllm-router"] = "vllm-router"
|
||||
|
||||
@@ -179,9 +197,57 @@ class VllmRouterConfig(BaseConfig):
|
||||
"""Routing policy, e.g. ``consistent_hash`` or ``round_robin``."""
|
||||
|
||||
|
||||
# Discriminated on ``type`` so additional router backends can be added to the
|
||||
# union (a single member needs no discriminator yet).
|
||||
RouterConfig: TypeAlias = VllmRouterConfig
|
||||
class LlmdRouterConfig(BaseConfig):
|
||||
"""llm-d router backend (EPP + Envoy)."""
|
||||
|
||||
type: Literal["llm-d"] = "llm-d"
|
||||
|
||||
port: int = 8000
|
||||
"""Port the Envoy gateway listens on — becomes the client-facing router URL."""
|
||||
|
||||
scorers: dict[str, float] = {
|
||||
"prefix-cache-scorer": 3.0,
|
||||
"active-request-scorer": 2.0,
|
||||
}
|
||||
"""EPP scorer name → weight, applied to every routing profile (before the per-profile P/D overrides). Defaults to prefix-cache affinity plus in-flight (active-request) load balancing. Unknown scorer names are rejected."""
|
||||
|
||||
prefill_scorer_overrides: dict[str, float] = {
|
||||
"queue-scorer": 2.0,
|
||||
"kv-cache-utilization-scorer": 2.0,
|
||||
}
|
||||
"""P/D only: scorer → weight merged onto ``scorers`` for the prefill profile (a per-profile weight overrides the base)."""
|
||||
|
||||
decode_scorer_overrides: dict[str, float] = {}
|
||||
"""P/D only: scorer → weight merged onto ``scorers`` for the decode profile (a per-profile weight overrides the base); empty by default."""
|
||||
|
||||
non_cached_tokens: int = 16
|
||||
"""P/D only: requests with fewer than this many non-cached prompt tokens skip remote prefill and run decode-only."""
|
||||
|
||||
decode_sidecar_port: int = 8300
|
||||
"""P/D only: port the decode-side llm-d sidecar listens on."""
|
||||
|
||||
@property
|
||||
def prefill_scorers(self) -> dict[str, float]:
|
||||
"""Effective prefill-profile scorers: ``scorers`` merged with ``prefill_scorer_overrides``."""
|
||||
return {**self.scorers, **self.prefill_scorer_overrides}
|
||||
|
||||
@property
|
||||
def decode_scorers(self) -> dict[str, float]:
|
||||
"""Effective decode-profile scorers: ``scorers`` merged with ``decode_scorer_overrides``."""
|
||||
return {**self.scorers, **self.decode_scorer_overrides}
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_scorers(self):
|
||||
unknown = (
|
||||
set(self.scorers) | set(self.prefill_scorer_overrides) | set(self.decode_scorer_overrides)
|
||||
) - KNOWN_SCORERS
|
||||
if unknown:
|
||||
raise ValueError(f"Unknown llm-d scorer(s): {sorted(unknown)}. Known scorers: {sorted(KNOWN_SCORERS)}.")
|
||||
return self
|
||||
|
||||
|
||||
# Discriminated on ``type`` so the launch path can pick the router backend.
|
||||
RouterConfig: TypeAlias = Annotated[VllmRouterConfig | LlmdRouterConfig, Field(discriminator="type")]
|
||||
|
||||
|
||||
class BaseInferenceDeploymentConfig(BaseConfig):
|
||||
@@ -240,6 +306,12 @@ class DisaggregatedInferenceDeploymentConfig(BaseInferenceDeploymentConfig):
|
||||
decode_env_overrides: dict[str, str] = {}
|
||||
"""Extra environment variables exported only on decode nodes."""
|
||||
|
||||
prefill_vllm_overrides: dict[str, Any] = {}
|
||||
"""Extra vLLM config options merged into --vllm-extra only for prefill ranks (SLURM only)."""
|
||||
|
||||
decode_vllm_overrides: dict[str, Any] = {}
|
||||
"""Extra vLLM config options merged into --vllm-extra only for decode ranks (SLURM only)."""
|
||||
|
||||
@property
|
||||
def num_nodes(self) -> int:
|
||||
return self.num_prefill_nodes + self.num_decode_nodes
|
||||
@@ -369,6 +441,18 @@ class InferenceConfig(BaseConfig):
|
||||
raise ValueError("Must use SLURM for multi-node / disaggregated deployment.")
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_llmd_no_routed_experts(self):
|
||||
"""Reject routed-expert return with the llm-d router (breaks P/D, unverified for multi-node)."""
|
||||
router = getattr(self.deployment, "router", None)
|
||||
if router is not None and router.type == "llm-d" and self.enable_return_routed_experts:
|
||||
raise ValueError(
|
||||
"The llm-d router backend does not support routed-expert return "
|
||||
"(enable_return_routed_experts): it breaks P/D and is unverified for multi-node. "
|
||||
"Use router type 'vllm-router' for routed-expert runs."
|
||||
)
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def auto_setup_kv_cache_offload(self):
|
||||
if self.kv_cache_offload is not None:
|
||||
|
||||
@@ -438,6 +438,25 @@ class RLConfig(BaseConfig):
|
||||
)
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_llmd_no_routed_experts(self):
|
||||
"""Reject routed-expert return with the llm-d router (breaks P/D, unverified for multi-node).
|
||||
|
||||
Runs after ``auto_setup_router_replay`` so it also catches the
|
||||
``trainer.enable_router_replay`` path, which sets the inference flag here
|
||||
(after InferenceConfig's own validators, which therefore miss it).
|
||||
"""
|
||||
if self.inference is not None and self.inference.enable_return_routed_experts:
|
||||
router = getattr(self.inference.deployment, "router", None)
|
||||
if router is not None and router.type == "llm-d":
|
||||
raise ValueError(
|
||||
"The llm-d router backend does not support routed-expert return "
|
||||
"(inference.enable_return_routed_experts / trainer.enable_router_replay): it "
|
||||
"breaks P/D and is unverified for multi-node. Use router type 'vllm-router' "
|
||||
"for router-replay runs."
|
||||
)
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_router_replay_without_kv_offload(self):
|
||||
if (
|
||||
|
||||
Executable
+86
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install the llm-d standalone (no-Kubernetes) routing binaries into
|
||||
# third_party/llmd/bin:
|
||||
# - epp : llm-d-router Endpoint Picker (the routing brain)
|
||||
# - pd-sidecar : decode-side proxy for P/D disaggregation
|
||||
# - envoy : the data-plane proxy that calls the EPP via ext_proc
|
||||
#
|
||||
# epp/pd-sidecar are built from a pinned llm-d-router commit. We currently build
|
||||
# from a small fork that adds P/D disaggregation for vLLM's token-in
|
||||
# /inference/v1/generate endpoint (prime-rl's renderer / TITO rollout path) —
|
||||
# upstream's pd-sidecar only disaggregates the OpenAI endpoints, so token-in P/D
|
||||
# silently runs decode-only. The fork is pending upstream PR
|
||||
# llm-d/llm-d-router#1458; switch LLMD_ROUTER_REPO back to the upstream repo and
|
||||
# bump LLMD_ROUTER_REF once it merges. The fork is branched off the upstream
|
||||
# commit that added the EPP vllmhttp parser (PR #1248), which the renderer path
|
||||
# also needs.
|
||||
#
|
||||
# System Go is not required: a Go toolchain is vendored under third_party/llmd/go
|
||||
# and used to bootstrap; GOTOOLCHAIN=auto fetches the exact version the module
|
||||
# pins. Envoy is extracted as a static binary from its release container image
|
||||
# WITHOUT docker: we build `crane` (pure-Go, talks straight to the OCI registry)
|
||||
# with the same vendored toolchain and use it to export the image filesystem.
|
||||
# This is the only step that previously required a docker daemon, which cluster
|
||||
# compute nodes don't have.
|
||||
set -euo pipefail
|
||||
|
||||
LLMD_ROUTER_REPO="${LLMD_ROUTER_REPO:-https://github.com/S1ro1/llm-d-router.git}"
|
||||
LLMD_ROUTER_REF="${LLMD_ROUTER_REF:-1ca4243ec84c657b4a5f507a1776d6c15a618d5b}"
|
||||
GO_BOOTSTRAP_VERSION="${GO_BOOTSTRAP_VERSION:-1.23.4}"
|
||||
ENVOY_VERSION="${ENVOY_VERSION:-1.36.0}"
|
||||
ENVOY_IMAGE="${ENVOY_IMAGE:-envoyproxy/envoy:v${ENVOY_VERSION}}"
|
||||
|
||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
PROJECT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
|
||||
LLMD_DIR="$PROJECT_DIR/third_party/llmd"
|
||||
BIN_DIR="$LLMD_DIR/bin"
|
||||
GO_ROOT="$LLMD_DIR/go"
|
||||
SRC_DIR="$LLMD_DIR/src"
|
||||
GO_TOOLS_BIN="$LLMD_DIR/gotools/bin"
|
||||
mkdir -p "$BIN_DIR" "$GO_TOOLS_BIN"
|
||||
|
||||
# --- Go toolchain (vendored bootstrap; auto-upgrades to the module's version) ---
|
||||
if [ ! -x "$GO_ROOT/bin/go" ]; then
|
||||
echo "[install_llmd] downloading bootstrap Go $GO_BOOTSTRAP_VERSION"
|
||||
rm -rf "$GO_ROOT"
|
||||
curl -fsSL "https://go.dev/dl/go${GO_BOOTSTRAP_VERSION}.linux-amd64.tar.gz" | tar -xz -C "$LLMD_DIR"
|
||||
fi
|
||||
export GOROOT="$GO_ROOT"
|
||||
export PATH="$GO_ROOT/bin:$PATH"
|
||||
export GOTOOLCHAIN=auto
|
||||
echo "[install_llmd] bootstrap $(go version)"
|
||||
|
||||
# --- Fetch llm-d-router source at the pinned ref ---
|
||||
echo "[install_llmd] fetching ${LLMD_ROUTER_REPO}@${LLMD_ROUTER_REF}"
|
||||
if [ ! -d "$SRC_DIR/.git" ]; then
|
||||
rm -rf "$SRC_DIR"
|
||||
git clone --quiet "$LLMD_ROUTER_REPO" "$SRC_DIR"
|
||||
fi
|
||||
git -C "$SRC_DIR" remote set-url origin "$LLMD_ROUTER_REPO"
|
||||
git -C "$SRC_DIR" fetch --quiet origin
|
||||
git -C "$SRC_DIR" checkout --quiet "$LLMD_ROUTER_REF"
|
||||
|
||||
# --- Build epp + pd-sidecar ---
|
||||
echo "[install_llmd] building epp + pd-sidecar"
|
||||
( cd "$SRC_DIR" && go build -o "$BIN_DIR/epp" ./cmd/epp && go build -o "$BIN_DIR/pd-sidecar" ./cmd/pd-sidecar )
|
||||
|
||||
# --- Envoy static binary (extract from the release image; keep if present) ---
|
||||
# No docker: build crane with the vendored toolchain and export the image's
|
||||
# filesystem straight from the registry, then pull out the static envoy binary.
|
||||
if [ ! -x "$BIN_DIR/envoy" ]; then
|
||||
if [ ! -x "$GO_TOOLS_BIN/crane" ]; then
|
||||
echo "[install_llmd] building crane (OCI registry client, no docker needed)"
|
||||
GOBIN="$GO_TOOLS_BIN" GOFLAGS=-mod=mod \
|
||||
go install github.com/google/go-containerregistry/cmd/crane@latest
|
||||
fi
|
||||
echo "[install_llmd] extracting Envoy ${ENVOY_VERSION} from ${ENVOY_IMAGE}"
|
||||
"$GO_TOOLS_BIN/crane" export "$ENVOY_IMAGE" - \
|
||||
| tar -xf - -O usr/local/bin/envoy > "$BIN_DIR/envoy"
|
||||
chmod +x "$BIN_DIR/envoy"
|
||||
fi
|
||||
|
||||
echo "[install_llmd] installed binaries in $BIN_DIR:"
|
||||
"$BIN_DIR/epp" --version 2>&1 | head -1 || true
|
||||
"$BIN_DIR/envoy" --version 2>&1 | head -1 || true
|
||||
"$BIN_DIR/pd-sidecar" --help >/dev/null 2>&1 && echo " pd-sidecar OK" || true
|
||||
echo "[install_llmd] done"
|
||||
@@ -59,6 +59,16 @@ Flags: `--workspace DIR`, `--deepep-ref REF` (default `73b6ea4`), `--nvshmem-ver
|
||||
|
||||
Verify: `uv run python -c 'import deep_ep; print(deep_ep.__file__)'`.
|
||||
|
||||
### llm-d router backend
|
||||
|
||||
Multi-node / disaggregated deployments can route through the upstream llm-d Endpoint Picker instead of `vllm-router` (set `[...deployment.router] type = "llm-d"`). It needs three native binaries — install once:
|
||||
|
||||
```bash
|
||||
bash scripts/install_llmd.sh # builds epp + pd-sidecar from a pinned llm-d-router commit (vendored Go), fetches envoy
|
||||
```
|
||||
|
||||
Binaries land in `third_party/llmd/bin/{epp,envoy,pd-sidecar}` (a shared path, so SLURM nodes see them). `epp` is pinned to the commit that includes the `vllmhttp-parser` (PR #1248) so prime-rl's renderer/TITO `/inference/v1/generate` path routes correctly. Override the pin with `LLMD_ROUTER_REF=<sha>`. The EPP + Envoy + endpoints configs are rendered from `templates/llmd/*.yaml.j2` (included into the SLURM script); only the per-node IPv4 addresses are filled in inline at launch time.
|
||||
|
||||
## Key files
|
||||
|
||||
- `pyproject.toml` — dependencies, extras, dependency groups
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import tomli_w
|
||||
|
||||
@@ -14,6 +16,17 @@ INFERENCE_TOML = "inference.toml"
|
||||
INFERENCE_SBATCH = "inference.sbatch"
|
||||
|
||||
|
||||
def vllm_overrides_fragment(overrides: dict[str, Any]) -> str:
|
||||
"""Render per-role vLLM overrides as a JSON fragment for the ROLE_EXTRA bash string.
|
||||
|
||||
Returns a leading-comma fragment with quotes escaped for the double-quoted assignment
|
||||
(e.g. `, \\"max_num_seqs\\": 256`), or an empty string when there are no overrides.
|
||||
"""
|
||||
if not overrides:
|
||||
return ""
|
||||
return ", " + json.dumps(overrides)[1:-1].replace('"', '\\"')
|
||||
|
||||
|
||||
def write_config(config: InferenceConfig, output_dir: Path, exclude: set[str] | None = None) -> Path:
|
||||
"""Write resolved config to disk."""
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -47,7 +60,7 @@ def write_slurm_script(config: InferenceConfig, config_path: Path, script_path:
|
||||
dp_per_node=dp_per_node,
|
||||
num_nodes=getattr(config.deployment, "num_nodes", 1),
|
||||
port=config.server.port,
|
||||
disaggregated=is_disaggregated,
|
||||
is_disaggregated=is_disaggregated,
|
||||
kv_offload=offload is not None,
|
||||
kv_offload_mooncake=is_mooncake,
|
||||
kv_offload_cpu_bytes=int(offload.cpu.num_bytes) if is_mooncake else 0,
|
||||
@@ -65,20 +78,21 @@ def write_slurm_script(config: InferenceConfig, config_path: Path, script_path:
|
||||
num_decode_replicas=config.deployment.num_decode_replicas,
|
||||
prefill_port=config.deployment.prefill_port,
|
||||
decode_port=config.deployment.decode_port,
|
||||
router_port=config.deployment.router.port,
|
||||
router_policy=config.deployment.router.policy,
|
||||
router=config.deployment.router,
|
||||
data_parallel_rpc_port=config.data_parallel_rpc_port,
|
||||
use_deep_gemm=config.use_deep_gemm,
|
||||
prefill_env_overrides=config.deployment.prefill_env_overrides,
|
||||
decode_env_overrides=config.deployment.decode_env_overrides,
|
||||
prefill_vllm_extra_json=vllm_overrides_fragment(config.deployment.prefill_vllm_overrides),
|
||||
decode_vllm_extra_json=vllm_overrides_fragment(config.deployment.decode_vllm_overrides),
|
||||
)
|
||||
elif is_multi_node:
|
||||
template_vars.update(
|
||||
router_port=config.deployment.router.port,
|
||||
router=config.deployment.router,
|
||||
backend_port=config.deployment.backend_port,
|
||||
router_policy=config.deployment.router.policy,
|
||||
data_parallel_rpc_port=config.data_parallel_rpc_port,
|
||||
enable_expert_parallel=config.enable_expert_parallel,
|
||||
infer_nodes_per_replica=config.deployment.num_nodes,
|
||||
)
|
||||
|
||||
script = template.render(**template_vars)
|
||||
|
||||
@@ -12,7 +12,9 @@ from threading import Event, Thread
|
||||
import pynvml
|
||||
import tomli_w
|
||||
|
||||
from prime_rl.configs.inference import VllmRouterConfig
|
||||
from prime_rl.configs.rl import RLConfig
|
||||
from prime_rl.entrypoints.inference import vllm_overrides_fragment
|
||||
from prime_rl.utils.config import cli
|
||||
from prime_rl.utils.logger import get_logger, setup_logger
|
||||
from prime_rl.utils.pathing import (
|
||||
@@ -371,7 +373,7 @@ def write_slurm_script(config: RLConfig, config_dir: Path, script_path: Path) ->
|
||||
num_prefill_replicas=infer_deploy.num_prefill_replicas,
|
||||
num_decode_replicas=infer_deploy.num_decode_replicas,
|
||||
gpus_per_node=config.deployment.gpus_per_node,
|
||||
router_port=infer_deploy.router.port,
|
||||
router=infer_deploy.router,
|
||||
prefill_port=infer_deploy.prefill_port,
|
||||
decode_port=infer_deploy.decode_port,
|
||||
inference_tp=config.inference.parallel.tp,
|
||||
@@ -379,6 +381,8 @@ def write_slurm_script(config: RLConfig, config_dir: Path, script_path: Path) ->
|
||||
use_deep_gemm=config.inference.use_deep_gemm,
|
||||
prefill_env_overrides=infer_deploy.prefill_env_overrides,
|
||||
decode_env_overrides=infer_deploy.decode_env_overrides,
|
||||
prefill_vllm_extra_json=vllm_overrides_fragment(infer_deploy.prefill_vllm_overrides),
|
||||
decode_vllm_extra_json=vllm_overrides_fragment(infer_deploy.decode_vllm_overrides),
|
||||
dp_per_node=config.deployment.gpus_per_node // config.inference.parallel.tp,
|
||||
**mooncake_vars,
|
||||
use_nccl_broadcast=config.weight_broadcast is not None and config.weight_broadcast.type == "nccl",
|
||||
@@ -397,7 +401,8 @@ def write_slurm_script(config: RLConfig, config_dir: Path, script_path: Path) ->
|
||||
nodes_per_infer_replica=config.deployment.num_infer_nodes,
|
||||
num_infer_replicas=config.deployment.num_infer_replicas,
|
||||
gpus_per_node=config.deployment.gpus_per_node,
|
||||
router_port=config.inference.deployment.router.port if config.inference else 8000,
|
||||
router=config.inference.deployment.router if config.inference else VllmRouterConfig(),
|
||||
infer_nodes_per_replica=config.deployment.num_infer_nodes,
|
||||
backend_port=config.inference.deployment.backend_port if config.inference else 8100,
|
||||
inference_tp=config.inference.parallel.tp if config.inference else 1,
|
||||
inference_enable_expert_parallel=config.inference.enable_expert_parallel if config.inference else False,
|
||||
|
||||
@@ -15,14 +15,20 @@ rank_log() {
|
||||
# launch_inference_rank <port> <cuda_visible_devices> <dp> <rpc_port> <vllm_extra_json|""> <nixl_side_channel_port|""> <log_file>
|
||||
launch_inference_rank() {
|
||||
local port="$1" gpus="$2" dp="$3" rpc="$4" extra="$5" nixl="$6" log="$7"
|
||||
# Per-rank dir for the mooncake-store lookup ipc socket. It must be unique per process:
|
||||
# external-LB runs one engine per process, all with data_parallel_rank_local 0, so the
|
||||
# lookup socket name collides on bind if the dir is shared node-wide. $port is unique per
|
||||
# rank on the node. Node-local /tmp also avoids inheriting an absent submit-node TMPDIR.
|
||||
local rpcbase="/tmp/vllm-rpc-$USER-$SLURM_JOB_ID-$port"
|
||||
mkdir -p "$rpcbase"
|
||||
local -a cmd=(uv run inference @ "$CONFIG_PATH"
|
||||
--server.host 0.0.0.0 --server.port "$port"
|
||||
--parallel.dp "$dp" --data-parallel-size-local 1 --api-server-count 1)
|
||||
[ -n "$rpc" ] && cmd+=(--data-parallel-rpc-port "$rpc")
|
||||
[ -n "$extra" ] && cmd+=(--vllm-extra "$extra")
|
||||
if [ -n "$nixl" ]; then
|
||||
CUDA_VISIBLE_DEVICES="$gpus" VLLM_NIXL_SIDE_CHANNEL_PORT="$nixl" "${cmd[@]}" 2>&1 | tee -a "$log" &
|
||||
CUDA_VISIBLE_DEVICES="$gpus" VLLM_NIXL_SIDE_CHANNEL_PORT="$nixl" VLLM_RPC_BASE_PATH="$rpcbase" "${cmd[@]}" 2>&1 | tee -a "$log" &
|
||||
else
|
||||
CUDA_VISIBLE_DEVICES="$gpus" "${cmd[@]}" 2>&1 | tee -a "$log" &
|
||||
CUDA_VISIBLE_DEVICES="$gpus" VLLM_RPC_BASE_PATH="$rpcbase" "${cmd[@]}" 2>&1 | tee -a "$log" &
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,9 +1,59 @@
|
||||
{# Shared router launch helper, included once per template and called by the
|
||||
replica-head rank. vllm-router today; an llm-d (EPP+Envoy) branch can slot in
|
||||
here so the call sites stay router-agnostic. #}
|
||||
# launch_router <mode:pd|regular> <worker_args> <port> <policy> <log_file> [replica_idx]
|
||||
replica-head rank. The router backend (vllm-router vs llm-d EPP+Envoy) is
|
||||
chosen here via router.type, so the call sites stay router-agnostic.
|
||||
node_base/node_count locate this replica's nodes in HOSTNAMES for llm-d
|
||||
endpoint discovery (disagg uses NUM_PREFILL_NODES/NUM_DECODE_NODES). #}
|
||||
# launch_router <mode:pd|regular> <worker_args> <port> <policy> <log> <replica_idx> <node_base> [node_count]
|
||||
launch_router() {
|
||||
local mode="$1" worker_args="$2" port="$3" policy="$4" log="$5" replica="${6:-}"
|
||||
local mode="$1" worker_args="$2" port="$3" policy="$4" log="$5" replica="${6:-0}" node_base="${7:-0}" node_count="${8:-0}"
|
||||
{%- if router.type == "llm-d" %}
|
||||
echo "Starting llm-d router (EPP+Envoy) on $LOCAL_IP:$port for replica $replica" | tee "$log"
|
||||
export PATH="$PROJECT_DIR/third_party/llmd/bin:$PATH"
|
||||
local LLMD_DIR="$OUTPUT_DIR/logs/inference/llmd_${replica}"
|
||||
mkdir -p "$LLMD_DIR"
|
||||
read -ra HOSTNAMES <<< "$HOSTNAMES_STR"
|
||||
{%- if is_disaggregated %}
|
||||
{%- set ep_disaggregated = true %}
|
||||
{%- set ep_num_prefill = num_prefill_nodes %}
|
||||
{%- set ep_num_decode = num_decode_nodes %}
|
||||
{%- set ep_dp = dp_per_node %}
|
||||
{%- set ep_prefill_port = prefill_port %}
|
||||
{%- set ep_sidecar_port = router.decode_sidecar_port %}
|
||||
cat > "$LLMD_DIR/epp.yaml" <<LLMD_EOF
|
||||
{% include 'llmd/epp_pd.yaml.j2' %}
|
||||
LLMD_EOF
|
||||
cat > "$LLMD_DIR/endpoints.yaml" <<LLMD_EOF
|
||||
{% include 'llmd/endpoints.yaml.j2' %}
|
||||
LLMD_EOF
|
||||
local node=0 ip
|
||||
for ((p=0; p<NUM_PREFILL_NODES; p++)); do ip=$(getent hosts "${HOSTNAMES[$((node_base + p))]}" | awk "{print \$1}"); sed -i "s|__LLMD_ADDR_${node}__|${ip}|g" "$LLMD_DIR/endpoints.yaml"; node=$((node + 1)); done
|
||||
for ((d=0; d<NUM_DECODE_NODES; d++)); do ip=$(getent hosts "${HOSTNAMES[$((node_base + NUM_PREFILL_NODES + d))]}" | awk "{print \$1}"); sed -i "s|__LLMD_ADDR_${node}__|${ip}|g" "$LLMD_DIR/endpoints.yaml"; node=$((node + 1)); done
|
||||
{%- else %}
|
||||
{%- set ep_disaggregated = false %}
|
||||
{%- set ep_num_nodes = infer_nodes_per_replica %}
|
||||
{%- set ep_dp = dp_per_node %}
|
||||
{%- set ep_backend_port = backend_port %}
|
||||
cat > "$LLMD_DIR/epp.yaml" <<LLMD_EOF
|
||||
{% include 'llmd/epp_estimate.yaml.j2' %}
|
||||
LLMD_EOF
|
||||
cat > "$LLMD_DIR/endpoints.yaml" <<LLMD_EOF
|
||||
{% include 'llmd/endpoints.yaml.j2' %}
|
||||
LLMD_EOF
|
||||
local ip
|
||||
for ((n=0; n<node_count; n++)); do ip=$(getent hosts "${HOSTNAMES[$((node_base + n))]}" | awk "{print \$1}"); sed -i "s|__LLMD_ADDR_${n}__|${ip}|g" "$LLMD_DIR/endpoints.yaml"; done
|
||||
{%- endif %}
|
||||
cat > "$LLMD_DIR/envoy.yaml" <<LLMD_EOF
|
||||
{% include 'llmd/envoy.yaml.j2' %}
|
||||
LLMD_EOF
|
||||
# grpc-health-port avoids 9003: mooncake_master runs its metrics server on 9003 and
|
||||
# shares the replica-head node with the EPP, so 9003 would fail to bind and kill the EPP.
|
||||
epp --pool-name prime-rl --pool-namespace slurm \
|
||||
--config-file "$LLMD_DIR/epp.yaml" \
|
||||
--grpc-port 9002 --grpc-health-port 9013 --metrics-port 9090 \
|
||||
--secure-serving=false --metrics-endpoint-auth=false --tracing=false \
|
||||
>> "$log" 2>&1 &
|
||||
envoy -c "$LLMD_DIR/envoy.yaml" >> "$log" 2>&1 &
|
||||
{%- else %}
|
||||
local tag="vllm-router"; [ "$mode" = pd ] && tag="vllm-router (PD)"
|
||||
echo "Starting $tag on $LOCAL_IP:$port${replica:+ for replica $replica}" | tee "$log"
|
||||
local -a cmd=(vllm-router --policy "$policy" --host 0.0.0.0 --port "$port"
|
||||
@@ -14,4 +64,5 @@ launch_router() {
|
||||
cmd+=(--worker-urls $worker_args)
|
||||
fi
|
||||
"${cmd[@]}" >> "$log" 2>&1 &
|
||||
{%- endif %}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
SLURM templates inside the per-node `bash -c` body, so NO single quotes / apostrophes.
|
||||
Requires shell vars: LOCAL_IP, INFER_NODE_RANK, OUTPUT_DIR (and SLURM env).
|
||||
Requires jinja vars: kv_offload_cpu_bytes, kv_offload_disk_path, kv_offload_device_name.
|
||||
Exports PYTHONHASHSEED + MOONCAKE_CONFIG_PATH for the vLLM process on this node. -#}
|
||||
Exports PYTHONHASHSEED + MOONCAKE_CONFIG_PATH for the vLLM process. (VLLM_RPC_BASE_PATH,
|
||||
used by the mooncake-store lookup ipc socket, is set per-rank in _launch_rank.sh.j2.) -#}
|
||||
# ---- Mooncake distributed store (shared pool across inference nodes) ----
|
||||
MC_DIR="$OUTPUT_DIR/mooncake/node_${INFER_NODE_RANK}"
|
||||
mkdir -p "$MC_DIR"
|
||||
@@ -23,9 +24,11 @@
|
||||
{%- endif %}
|
||||
if [ "$SLURMD_NODENAME" = "$MC_HEAD" ]; then
|
||||
{%- if kv_offload_disk_path %}
|
||||
mooncake_master -rpc_port=50051 -enable_http_metadata_server -http_metadata_server_host=0.0.0.0 -http_metadata_server_port=8080 -enable_offload=true -root_fs_dir={{ kv_offload_disk_path }} > "$MC_DIR/master.log" 2>&1 &
|
||||
mooncake_master -rpc_port=50051 -enable_http_metadata_server -http_metadata_server_host=0.0.0.0 -http_metadata_server_port=8080 -default_kv_lease_ttl=3600000 -enable_offload=true -root_fs_dir={{ kv_offload_disk_path }} > "$MC_DIR/master.log" 2>&1 &
|
||||
{%- else %}
|
||||
mooncake_master -rpc_port=50051 -enable_http_metadata_server -http_metadata_server_host=0.0.0.0 -http_metadata_server_port=8080 > "$MC_DIR/master.log" 2>&1 &
|
||||
# default_kv_lease_ttl raised from 5s: KV blocks were expiring before the decode side
|
||||
# reused them ("invalid KV blocks ... may have expired"), the real non-NIC config issue.
|
||||
mooncake_master -rpc_port=50051 -enable_http_metadata_server -http_metadata_server_host=0.0.0.0 -http_metadata_server_port=8080 -default_kv_lease_ttl=3600000 > "$MC_DIR/master.log" 2>&1 &
|
||||
{%- endif %}
|
||||
fi
|
||||
# Every node waits for the shared master + metadata, then contributes its segment.
|
||||
|
||||
@@ -28,7 +28,7 @@ set -e
|
||||
# Configs
|
||||
export NUM_NODES={{ num_nodes }}
|
||||
export GPUS_PER_NODE={{ gpus_per_node }}
|
||||
{% if disaggregated -%}
|
||||
{% if is_disaggregated -%}
|
||||
export NUM_PREFILL_NODES={{ num_prefill_nodes }}
|
||||
export NUM_DECODE_NODES={{ num_decode_nodes }}
|
||||
export NUM_PREFILL_REPLICAS={{ num_prefill_replicas }}
|
||||
@@ -38,10 +38,13 @@ export NODES_PER_PREFILL_REPLICA=$((NUM_PREFILL_NODES / NUM_PREFILL_REPLICAS))
|
||||
export NODES_PER_DECODE_REPLICA=$((NUM_DECODE_NODES / NUM_DECODE_REPLICAS))
|
||||
export PREFILL_PORT={{ prefill_port }}
|
||||
export DECODE_PORT={{ decode_port }}
|
||||
export ROUTER_PORT={{ router_port }}
|
||||
export ROUTER_PORT={{ router.port }}
|
||||
export RPC_PORT={{ data_parallel_rpc_port }}
|
||||
{%- if router.type == "llm-d" %}
|
||||
export DECODE_SIDECAR_PORT={{ router.decode_sidecar_port }}
|
||||
{%- endif %}
|
||||
{%- elif num_nodes > 1 %}
|
||||
export ROUTER_PORT={{ router_port }}
|
||||
export ROUTER_PORT={{ router.port }}
|
||||
export BACKEND_PORT={{ backend_port }}
|
||||
export RPC_PORT={{ data_parallel_rpc_port }}
|
||||
{%- endif %}
|
||||
@@ -70,7 +73,7 @@ uv sync --all-extras
|
||||
# Print inference URLs
|
||||
export HOSTNAMES=( $( scontrol show hostnames $SLURM_JOB_NODELIST ) )
|
||||
export HOSTNAMES_STR="${HOSTNAMES[*]}"
|
||||
{% if disaggregated -%}
|
||||
{% if is_disaggregated -%}
|
||||
# Build per-replica router URLs
|
||||
INFER_URLS=""
|
||||
ALL_ROUTER_ARGS=""
|
||||
@@ -132,6 +135,10 @@ srun bash -s <<'CLEANUP_SH'
|
||||
pkill -9 -f "[p]ython.*prime_rl" 2>/dev/null
|
||||
pkill -9 -f "[t]orchrun" 2>/dev/null
|
||||
pkill -9 -f "[v]llm-router" 2>/dev/null
|
||||
# llm-d router procs (EPP + Envoy + decode pd-sidecar) left over from a prior run.
|
||||
pkill -9 -f "[e]pp.*pool-name" 2>/dev/null
|
||||
pkill -9 -f "[e]nvoy.*envoy.yaml" 2>/dev/null
|
||||
pkill -9 -f "[p]d-sidecar" 2>/dev/null
|
||||
pkill -9 -f "[v]llm" 2>/dev/null
|
||||
pkill -9 -f "[p]rime_rl" 2>/dev/null
|
||||
# Also match prctl-set process names (kernel comm) like "vllm::router"
|
||||
@@ -144,7 +151,7 @@ srun bash -s <<'CLEANUP_SH'
|
||||
pkill -9 -x mooncake_client 2>/dev/null
|
||||
sleep 2
|
||||
rm -rf /dev/shm/vllm-* /dev/shm/vllm_* /tmp/vllm-* /tmp/vllm_* /tmp/torch-* /tmp/torchelastic_* 2>/dev/null
|
||||
procs=$(ps -eo comm,args | grep -E "python|torchrun|vllm|vllm::|mooncake_" | grep -v grep | wc -l)
|
||||
procs=$(ps -eo comm,args | grep -E "python|torchrun|vllm|vllm::|mooncake_|[e]pp |envoy|pd-sidecar" | grep -v grep | wc -l)
|
||||
gpu=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits | awk "{s+=\$1} END {print s}")
|
||||
echo "[node-cleanup] $(hostname) procs=$procs gpu_mem=${gpu}MiB"
|
||||
CLEANUP_SH
|
||||
@@ -179,7 +186,7 @@ srun --kill-on-bad-exit=1 bash -c '
|
||||
{% include "_mooncake_store.sh.j2" %}
|
||||
{%- endif %}
|
||||
|
||||
{% if disaggregated -%}
|
||||
{% if is_disaggregated -%}
|
||||
# NVSHMEM libs for DeepEP — ensure the rpath target exists on all nodes
|
||||
if [ ! -d /tmp/deepep_build/nvshmem/lib ] && [ -d "$OUTPUT_DIR/nvshmem/lib" ]; then
|
||||
mkdir -p /tmp/deepep_build/nvshmem
|
||||
@@ -247,7 +254,7 @@ srun --kill-on-bad-exit=1 bash -c '
|
||||
{% for key, value in prefill_env_overrides.items() %}
|
||||
export {{ key }}="{{ value }}"
|
||||
{% endfor %}
|
||||
ROLE_EXTRA="\"all2all_backend\": \"deepep_high_throughput\""
|
||||
ROLE_EXTRA="\"all2all_backend\": \"deepep_high_throughput\"{{ prefill_vllm_extra_json }}"
|
||||
else
|
||||
# ── Decode node ──
|
||||
export UCX_NET_DEVICES=mlx5_0:1
|
||||
@@ -262,7 +269,7 @@ srun --kill-on-bad-exit=1 bash -c '
|
||||
{% for key, value in decode_env_overrides.items() %}
|
||||
export {{ key }}="{{ value }}"
|
||||
{% endfor %}
|
||||
ROLE_EXTRA="\"all2all_backend\": \"deepep_low_latency\", \"compilation_config\": $DECODE_COMPILE_CFG"
|
||||
ROLE_EXTRA="\"all2all_backend\": \"deepep_low_latency\", \"compilation_config\": $DECODE_COMPILE_CFG{{ decode_vllm_extra_json }}"
|
||||
fi
|
||||
|
||||
echo "NODE_RANK=$INFER_NODE_RANK ROLE=$ROLE REPLICA=$REPLICA_IDX SUB_REPLICA=$SUB_REPLICA ROLE_RANK=$ROLE_RANK DP=$DP PORT=$PORT LOCAL_IP=$LOCAL_IP" \
|
||||
@@ -271,8 +278,28 @@ srun --kill-on-bad-exit=1 bash -c '
|
||||
# Start the router on the first prefill node of each replica (external LB across per-rank endpoints)
|
||||
if [ "$RANK_IN_REPLICA" -eq 0 ]; then
|
||||
REPLICA_ROUTER_ARGS=$(echo "$ALL_ROUTER_ARGS" | cut -d"|" -f$((REPLICA_IDX + 1)))
|
||||
launch_router pd "$REPLICA_ROUTER_ARGS" "$ROUTER_PORT" "{{ router_policy }}" "$OUTPUT_DIR/logs/inference/router_${REPLICA_IDX}.log" "$REPLICA_IDX"
|
||||
launch_router pd "$REPLICA_ROUTER_ARGS" "$ROUTER_PORT" "{{ router.policy }}" "$OUTPUT_DIR/logs/inference/router_${REPLICA_IDX}.log" "$REPLICA_IDX" "$REPLICA_BASE"
|
||||
fi
|
||||
{%- if router.type == "llm-d" %}
|
||||
# pd-sidecar on each decode node: EPP routes decode -> sidecar (DECODE_SIDECAR_PORT
|
||||
# + rank) -> vLLM decode (DECODE_PORT + rank) after orchestrating remote prefill.
|
||||
# Every decode node fronts its own local ranks, so launch on each (not just the
|
||||
# replica head), or decode nodes beyond the head get advertised but unserved endpoints.
|
||||
if [ "$ROLE" = "decode" ]; then
|
||||
SIDECAR_LOG="$OUTPUT_DIR/logs/inference/sidecar_${INFER_NODE_RANK}.log"
|
||||
echo "Starting pd-sidecar on $LOCAL_IP:$DECODE_SIDECAR_PORT(+rank) -> vLLM $DECODE_PORT(+rank)" | tee $SIDECAR_LOG
|
||||
export PATH="$PROJECT_DIR/third_party/llmd/bin:$PATH"
|
||||
pd-sidecar \
|
||||
--port $DECODE_SIDECAR_PORT \
|
||||
--vllm-port $DECODE_PORT \
|
||||
--kv-connector nixlv2 \
|
||||
--secure-proxy=false \
|
||||
--enable-ssrf-protection=false \
|
||||
--inference-pool prime-rl \
|
||||
--data-parallel-size {{ dp_per_node }} \
|
||||
>> $SIDECAR_LOG 2>&1 &
|
||||
fi
|
||||
{%- endif %}
|
||||
|
||||
# External-LB: one vLLM API server per local DP rank (PORT + k), each pinned to its TP
|
||||
# slice of GPUs with a unique NIXL side-channel port. Each role is its own external-LB DP
|
||||
@@ -296,7 +323,7 @@ srun --kill-on-bad-exit=1 bash -c '
|
||||
|
||||
# Start the router on node 0 (balances across per-rank endpoints — no intra-node DP header)
|
||||
if [ "$INFER_NODE_RANK" -eq 0 ]; then
|
||||
launch_router regular "$ROUTER_ARGS" "$ROUTER_PORT" "{{ router_policy }}" "$OUTPUT_DIR/logs/inference/router.log"
|
||||
launch_router regular "$ROUTER_ARGS" "$ROUTER_PORT" "{{ router.policy }}" "$OUTPUT_DIR/logs/inference/router.log" 0 0 "$NUM_NODES"
|
||||
fi
|
||||
|
||||
# External-LB: one vLLM API server per DP rank on this node (BACKEND_PORT + dp_local),
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
{# llm-d file-discovery endpoints: one entry per DP rank. Rendered (via include)
|
||||
into the sbatch; the per-node address is the __LLMD_ADDR_<node>__ placeholder,
|
||||
filled with each SLURM host's IPv4 inline in the sbatch (file-discovery rejects
|
||||
hostnames). Node ordering matches the sbatch's host loop: prefill then decode.
|
||||
The including sbatch sets ep_* via {% set %}. #}
|
||||
endpoints:
|
||||
{%- if ep_disaggregated %}
|
||||
{%- for node in range(ep_num_prefill) %}
|
||||
{%- for rank in range(ep_dp) %}
|
||||
- name: prefill-{{ node }}-rank-{{ rank }}
|
||||
address: __LLMD_ADDR_{{ node }}__
|
||||
port: "{{ ep_prefill_port + rank }}"
|
||||
namespace: default
|
||||
labels:
|
||||
llm-d.ai/pool: prime-rl
|
||||
llm-d.ai/role: prefill
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
{%- for node in range(ep_num_decode) %}
|
||||
{%- for rank in range(ep_dp) %}
|
||||
- name: decode-{{ node }}-rank-{{ rank }}
|
||||
address: __LLMD_ADDR_{{ ep_num_prefill + node }}__
|
||||
port: "{{ ep_sidecar_port + rank }}"
|
||||
namespace: default
|
||||
labels:
|
||||
llm-d.ai/pool: prime-rl
|
||||
llm-d.ai/role: decode
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
{%- else %}
|
||||
{%- for node in range(ep_num_nodes) %}
|
||||
{%- for rank in range(ep_dp) %}
|
||||
- name: backend-{{ node }}-rank-{{ rank }}
|
||||
address: __LLMD_ADDR_{{ node }}__
|
||||
port: "{{ ep_backend_port + rank }}"
|
||||
namespace: default
|
||||
labels:
|
||||
llm-d.ai/pool: prime-rl
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
{%- endif %}
|
||||
@@ -0,0 +1,97 @@
|
||||
{# Envoy data plane: EPP picks the backend (ext_proc) and sets
|
||||
x-gateway-destination-endpoint; the ORIGINAL_DST cluster routes there. Both
|
||||
/v1/ (MITO) and /inference/v1/ (TITO) go through the picker. EPP gRPC is on
|
||||
loopback 9002; the gateway listens on the configured port. #}
|
||||
admin:
|
||||
address: { socket_address: { address: 127.0.0.1, port_value: 9901 } }
|
||||
static_resources:
|
||||
listeners:
|
||||
- name: prime_rl
|
||||
address: { socket_address: { address: 0.0.0.0, port_value: {{ router.port }} } }
|
||||
filter_chains:
|
||||
- filters:
|
||||
- name: envoy.filters.network.http_connection_manager
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
|
||||
stat_prefix: prime_rl
|
||||
codec_type: AUTO
|
||||
stream_idle_timeout: 0s
|
||||
request_timeout: 0s
|
||||
route_config:
|
||||
virtual_hosts:
|
||||
- name: prime_rl
|
||||
domains: ["*"]
|
||||
routes:
|
||||
- match: { prefix: "/v1/" }
|
||||
route: { cluster: backend_cluster, timeout: 0s, idle_timeout: 86400s }
|
||||
- match: { prefix: "/inference/v1/" }
|
||||
route: { cluster: backend_cluster, timeout: 0s, idle_timeout: 86400s }
|
||||
http_filters:
|
||||
- name: envoy.filters.http.ext_proc
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.http.ext_proc.v3.ExternalProcessor
|
||||
grpc_service:
|
||||
envoy_grpc: { cluster_name: epp_cluster }
|
||||
timeout: 10s
|
||||
processing_mode:
|
||||
request_header_mode: SEND
|
||||
response_header_mode: SEND
|
||||
request_body_mode: FULL_DUPLEX_STREAMED
|
||||
response_body_mode: FULL_DUPLEX_STREAMED
|
||||
request_trailer_mode: SEND
|
||||
response_trailer_mode: SEND
|
||||
message_timeout: 1000s
|
||||
- name: envoy.filters.http.router
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
|
||||
suppress_envoy_headers: true
|
||||
clusters:
|
||||
- name: backend_cluster
|
||||
type: ORIGINAL_DST
|
||||
lb_policy: CLUSTER_PROVIDED
|
||||
original_dst_lb_config:
|
||||
use_http_header: true
|
||||
http_header_name: x-gateway-destination-endpoint
|
||||
connect_timeout: 5s
|
||||
# Default circuit breakers (~1024) overflow at high inflight concurrency (>=1536),
|
||||
# causing "reset reason: overflow" 500s. Raise far above the max concurrent rollouts.
|
||||
circuit_breakers:
|
||||
thresholds:
|
||||
- priority: DEFAULT
|
||||
max_connections: 100000
|
||||
max_pending_requests: 100000
|
||||
max_requests: 100000
|
||||
max_retries: 1000
|
||||
- priority: HIGH
|
||||
max_connections: 100000
|
||||
max_pending_requests: 100000
|
||||
max_requests: 100000
|
||||
max_retries: 1000
|
||||
- name: epp_cluster
|
||||
type: STRICT_DNS
|
||||
typed_extension_protocol_options:
|
||||
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
|
||||
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
|
||||
explicit_http_config:
|
||||
http2_protocol_options: {}
|
||||
load_assignment:
|
||||
cluster_name: epp_cluster
|
||||
endpoints:
|
||||
- lb_endpoints:
|
||||
- endpoint:
|
||||
address: { socket_address: { address: 127.0.0.1, port_value: 9002 } }
|
||||
connect_timeout: 5s
|
||||
# ext_proc (EPP) connection pool overflows at high concurrency without this — the
|
||||
# gRPC ext_proc calls are 1:1 with inflight requests, so cap well above max rollouts.
|
||||
circuit_breakers:
|
||||
thresholds:
|
||||
- priority: DEFAULT
|
||||
max_connections: 100000
|
||||
max_pending_requests: 100000
|
||||
max_requests: 100000
|
||||
max_retries: 1000
|
||||
- priority: HIGH
|
||||
max_connections: 100000
|
||||
max_pending_requests: 100000
|
||||
max_requests: 100000
|
||||
max_retries: 1000
|
||||
@@ -0,0 +1,34 @@
|
||||
{# llm-d EPP config: single-pool (non-P/D) routing with approximate prefix-cache
|
||||
scoring. The vllmhttp parser embeds the OpenAI parser and also handles
|
||||
/inference/v1/generate (token_ids), so MITO + TITO both get prefix-cache
|
||||
scoring. Included into the sbatch as a heredoc; $LLMD_DIR is the per-replica
|
||||
config dir, expanded at launch time. #}
|
||||
apiVersion: inference.networking.x-k8s.io/v1alpha1
|
||||
kind: EndpointPickerConfig
|
||||
plugins:
|
||||
- name: file-disc
|
||||
type: file-discovery
|
||||
parameters:
|
||||
path: $LLMD_DIR/endpoints.yaml
|
||||
watchFile: true
|
||||
- name: vllmhttp-parser
|
||||
type: vllmhttp-parser
|
||||
{%- for scorer in router.scorers %}
|
||||
- type: {{ scorer }}
|
||||
{%- endfor %}
|
||||
- type: max-score-picker
|
||||
- type: single-profile-handler
|
||||
schedulingProfiles:
|
||||
- name: default
|
||||
plugins:
|
||||
{%- for scorer, weight in router.scorers.items() %}
|
||||
- pluginRef: {{ scorer }}
|
||||
weight: {{ weight }}
|
||||
{%- endfor %}
|
||||
- pluginRef: max-score-picker
|
||||
requestHandler:
|
||||
parser:
|
||||
pluginRef: vllmhttp-parser
|
||||
dataLayer:
|
||||
discovery:
|
||||
pluginRef: file-disc
|
||||
@@ -0,0 +1,56 @@
|
||||
{# llm-d EPP config: prefill/decode disaggregation. disagg-profile-handler runs
|
||||
the prefill profile when prefix-based-pd-decider sees >= nonCachedTokens
|
||||
non-cached prompt tokens, else decode-only. Mirrors the upstream llm-d PD
|
||||
guide: the prefill profile uses prefill_scorers (prefix + queue/kv) and the
|
||||
decode profile uses scorers (prefix + active-request); prefill-filter /
|
||||
decode-filter select endpoints by llm-d.ai/role label. Included into the
|
||||
sbatch as a heredoc; $LLMD_DIR is the per-replica config dir, expanded at
|
||||
launch time. #}
|
||||
apiVersion: inference.networking.x-k8s.io/v1alpha1
|
||||
kind: EndpointPickerConfig
|
||||
plugins:
|
||||
- name: file-disc
|
||||
type: file-discovery
|
||||
parameters:
|
||||
path: $LLMD_DIR/endpoints.yaml
|
||||
watchFile: true
|
||||
- name: vllmhttp-parser
|
||||
type: vllmhttp-parser
|
||||
- name: pd-decider
|
||||
type: prefix-based-pd-decider
|
||||
parameters:
|
||||
nonCachedTokens: {{ router.non_cached_tokens }}
|
||||
- name: profile-handler
|
||||
type: disagg-profile-handler
|
||||
parameters:
|
||||
deciders:
|
||||
prefill: pd-decider
|
||||
- type: prefill-filter
|
||||
- type: decode-filter
|
||||
{%- for scorer in ((router.prefill_scorers.keys() | list) + (router.decode_scorers.keys() | list)) | unique %}
|
||||
- type: {{ scorer }}
|
||||
{%- endfor %}
|
||||
- type: max-score-picker
|
||||
schedulingProfiles:
|
||||
- name: prefill
|
||||
plugins:
|
||||
- pluginRef: prefill-filter
|
||||
{%- for scorer, weight in router.prefill_scorers.items() %}
|
||||
- pluginRef: {{ scorer }}
|
||||
weight: {{ weight }}
|
||||
{%- endfor %}
|
||||
- pluginRef: max-score-picker
|
||||
- name: decode
|
||||
plugins:
|
||||
- pluginRef: decode-filter
|
||||
{%- for scorer, weight in router.decode_scorers.items() %}
|
||||
- pluginRef: {{ scorer }}
|
||||
weight: {{ weight }}
|
||||
{%- endfor %}
|
||||
- pluginRef: max-score-picker
|
||||
requestHandler:
|
||||
parser:
|
||||
pluginRef: vllmhttp-parser
|
||||
dataLayer:
|
||||
discovery:
|
||||
pluginRef: file-disc
|
||||
@@ -32,7 +32,7 @@ export NODES_PER_INFER_REPLICA={{ nodes_per_infer_replica }}
|
||||
export NUM_INFER_REPLICAS={{ num_infer_replicas }}
|
||||
export GPUS_PER_NODE={{ gpus_per_node }}
|
||||
{% if num_infer_nodes > 0 -%}
|
||||
export ROUTER_PORT={{ router_port }}
|
||||
export ROUTER_PORT={{ router.port }}
|
||||
export INFERENCE_TP={{ inference_tp }}
|
||||
export INFERENCE_DP_LOCAL=$((GPUS_PER_NODE / INFERENCE_TP))
|
||||
export INFERENCE_DATA_PARALLEL_RPC_PORT={{ inference_data_parallel_rpc_port }}
|
||||
@@ -45,6 +45,9 @@ export NODES_PER_PREFILL_REPLICA=$((NUM_PREFILL_NODES / NUM_PREFILL_REPLICAS))
|
||||
export NODES_PER_DECODE_REPLICA=$((NUM_DECODE_NODES / NUM_DECODE_REPLICAS))
|
||||
export PREFILL_PORT={{ prefill_port }}
|
||||
export DECODE_PORT={{ decode_port }}
|
||||
{%- if router.type == "llm-d" %}
|
||||
export DECODE_SIDECAR_PORT={{ router.decode_sidecar_port }}
|
||||
{%- endif %}
|
||||
{%- else -%}
|
||||
export BACKEND_PORT={{ backend_port }}
|
||||
export INFERENCE_ENABLE_EXPERT_PARALLEL={{ "1" if inference_enable_expert_parallel else "0" }}
|
||||
@@ -166,6 +169,10 @@ srun bash -s <<'CLEANUP_SH'
|
||||
pkill -9 -f "[p]ython.*prime_rl" 2>/dev/null
|
||||
pkill -9 -f "[t]orchrun" 2>/dev/null
|
||||
pkill -9 -f "[v]llm-router" 2>/dev/null
|
||||
# llm-d router procs (EPP + Envoy + decode pd-sidecar) left over from a prior run.
|
||||
pkill -9 -f "[e]pp.*pool-name" 2>/dev/null
|
||||
pkill -9 -f "[e]nvoy.*envoy.yaml" 2>/dev/null
|
||||
pkill -9 -f "[p]d-sidecar" 2>/dev/null
|
||||
pkill -9 -f "[v]llm" 2>/dev/null
|
||||
pkill -9 -f "[p]rime_rl" 2>/dev/null
|
||||
# Also match prctl-set process names (kernel comm) like "vllm::router"
|
||||
@@ -178,7 +185,7 @@ srun bash -s <<'CLEANUP_SH'
|
||||
pkill -9 -x mooncake_client 2>/dev/null
|
||||
sleep 2
|
||||
rm -rf /dev/shm/vllm-* /dev/shm/vllm_* /tmp/vllm-* /tmp/vllm_* /tmp/torch-* /tmp/torchelastic_* 2>/dev/null
|
||||
procs=$(ps -eo comm,args | grep -E "python|torchrun|vllm|vllm::|mooncake_" | grep -v grep | wc -l)
|
||||
procs=$(ps -eo comm,args | grep -E "python|torchrun|vllm|vllm::|mooncake_|[e]pp |envoy|pd-sidecar" | grep -v grep | wc -l)
|
||||
gpu=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits | awk "{s+=\$1} END {print s}")
|
||||
echo "[node-cleanup] $(hostname) procs=$procs gpu_mem=${gpu}MiB"
|
||||
CLEANUP_SH
|
||||
@@ -284,7 +291,7 @@ if [ "$SLURM_PROCID" -lt "$NUM_INFER_NODES" ]; then
|
||||
{% for key, value in prefill_env_overrides.items() %}
|
||||
export {{ key }}="{{ value }}"
|
||||
{% endfor %}
|
||||
ROLE_EXTRA="\"all2all_backend\": \"deepep_high_throughput\""
|
||||
ROLE_EXTRA="\"all2all_backend\": \"deepep_high_throughput\"{{ prefill_vllm_extra_json }}"
|
||||
else
|
||||
export UCX_NET_DEVICES=mlx5_0:1
|
||||
ROLE="decode"
|
||||
@@ -298,7 +305,7 @@ if [ "$SLURM_PROCID" -lt "$NUM_INFER_NODES" ]; then
|
||||
{% for key, value in decode_env_overrides.items() %}
|
||||
export {{ key }}="{{ value }}"
|
||||
{% endfor %}
|
||||
ROLE_EXTRA="\"all2all_backend\": \"deepep_low_latency\", \"compilation_config\": $DECODE_COMPILE_CFG"
|
||||
ROLE_EXTRA="\"all2all_backend\": \"deepep_low_latency\", \"compilation_config\": $DECODE_COMPILE_CFG{{ decode_vllm_extra_json }}"
|
||||
fi
|
||||
|
||||
echo "ROLE=$ROLE REPLICA=$REPLICA_IDX SUB_REPLICA=$SUB_REPLICA ROLE_RANK=$ROLE_RANK DP=$DP PORT=$PORT" \
|
||||
@@ -307,8 +314,28 @@ if [ "$SLURM_PROCID" -lt "$NUM_INFER_NODES" ]; then
|
||||
# Start the router on the first node of each replica (PD mode, external LB across per-rank endpoints)
|
||||
if [ "$RANK_IN_REPLICA" -eq 0 ]; then
|
||||
REPLICA_ROUTER_ARGS=$(echo "$ALL_ROUTER_ARGS" | cut -d"|" -f$((REPLICA_IDX + 1)))
|
||||
launch_router pd "$REPLICA_ROUTER_ARGS" "$ROUTER_PORT" consistent_hash "$OUTPUT_DIR/logs/inference/router_${REPLICA_IDX}.log" "$REPLICA_IDX"
|
||||
launch_router pd "$REPLICA_ROUTER_ARGS" "$ROUTER_PORT" "{{ router.policy }}" "$OUTPUT_DIR/logs/inference/router_${REPLICA_IDX}.log" "$REPLICA_IDX" "$REPLICA_BASE"
|
||||
fi
|
||||
{%- if router.type == "llm-d" %}
|
||||
# pd-sidecar on each decode node: EPP routes decode -> sidecar (DECODE_SIDECAR_PORT
|
||||
# + rank) -> vLLM decode (DECODE_PORT + rank) after orchestrating remote prefill.
|
||||
# Every decode node fronts its own local ranks, so launch on each (not just the
|
||||
# replica head), or decode nodes beyond the head get advertised but unserved endpoints.
|
||||
if [ "$ROLE" = "decode" ]; then
|
||||
SIDECAR_LOG="$OUTPUT_DIR/logs/inference/sidecar_${INFER_NODE_RANK}.log"
|
||||
echo "Starting pd-sidecar on $LOCAL_IP:$DECODE_SIDECAR_PORT(+rank) -> vLLM $DECODE_PORT(+rank)" | tee $SIDECAR_LOG
|
||||
export PATH="$PROJECT_DIR/third_party/llmd/bin:$PATH"
|
||||
pd-sidecar \
|
||||
--port $DECODE_SIDECAR_PORT \
|
||||
--vllm-port $DECODE_PORT \
|
||||
--kv-connector nixlv2 \
|
||||
--secure-proxy=false \
|
||||
--enable-ssrf-protection=false \
|
||||
--inference-pool prime-rl \
|
||||
--data-parallel-size $INFERENCE_DP_LOCAL \
|
||||
>> $SIDECAR_LOG 2>&1 &
|
||||
fi
|
||||
{%- endif %}
|
||||
|
||||
# External-LB: one vLLM API server per local DP rank (PORT + k), each pinned to its TP
|
||||
# slice of GPUs with a unique NIXL side-channel port. Each role is its own external-LB DP
|
||||
@@ -325,7 +352,7 @@ if [ "$SLURM_PROCID" -lt "$NUM_INFER_NODES" ]; then
|
||||
# Start the router on the first node of each replica
|
||||
if [ "$RANK_IN_REPLICA" -eq 0 ]; then
|
||||
REPLICA_ROUTER_ARGS=$(echo "$ALL_ROUTER_ARGS" | cut -d"|" -f$((REPLICA_IDX + 1)))
|
||||
launch_router regular "$REPLICA_ROUTER_ARGS" "$ROUTER_PORT" consistent_hash "$OUTPUT_DIR/logs/inference/router_${REPLICA_IDX}.log" "$REPLICA_IDX"
|
||||
launch_router regular "$REPLICA_ROUTER_ARGS" "$ROUTER_PORT" "{{ router.policy }}" "$OUTPUT_DIR/logs/inference/router_${REPLICA_IDX}.log" "$REPLICA_IDX" "$((REPLICA_IDX * NODES_PER_INFER_REPLICA))" "$NODES_PER_INFER_REPLICA"
|
||||
fi
|
||||
|
||||
# External-LB: one vLLM API server per DP rank on this node (BACKEND_PORT + d),
|
||||
|
||||
Reference in New Issue
Block a user