Repository navigation
[llm][mx] Add ModelExpress support to Ray Serve LLM - #67316
Conversation
With `load_format="modelexpress"`, a new LLMServer replica loads its weights and JIT caches from an already-serving replica over NIXL instead of from storage, which makes scale-out fast. - model_express.py: before the engine starts, set the MX client env for the replica: server address (head node), NIXL/worker gRPC ports offset by the replica's local rank, advertised host, model name, and the env prefixes vLLM must copy into its Ray workers. A per-replica HTTP endpoint reports readiness once the engine has started; MX publishes the replica's JIT caches only after that. - model_express_server.py: the MX server as a one-replica Serve deployment pinned to the head node. - Node init downloads only non-weight files for the modelexpress load format. - compile_cache_compat.py (temporary): a scaled-out replica on another GPU index crashes when it reuses a peer's torch.compile cache, because Inductor bakes the device index into it. Backport of vllm-project/vllm#63247 for vLLM 0.31 / torch 2.13, applied from Serve LLM's worker setup hook. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Build the ModelExpress server (memory, Redis and Kubernetes metadata backends) in a builder stage on the ray-llm base image and install it at /usr/local/bin/modelexpress-server. The `mx` deployment no longer takes a binary path: it reads RAY_MX_SERVER_BINARY_PATH, which defaults to the image path and can point at a custom image's binary. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Serve config import_path builders take exactly one argument (the `args` dict), like build_openai_app. Take the ModelExpressServer kwargs as a single dict so the `mx` app can be deployed from a Serve config file. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Follow the serving_patterns/data_parallel layout: - envs.py: get_mx_server_binary() (RAY_MX_SERVER_BINARY_PATH, defaulting to the ray-llm image path) and RAY_MX_SERVER_HEALTH_CHECK_PERIOD_S. - mx_server.py: the ModelExpressServer deployment. It listens on a free port unless one is passed, and closes its copy of the log file after spawning; without log_path the server's output goes to the replica's log. - builder.py: build_model_express_app. LLM replicas now discover the server through the `mx` app's deployment handle (app name configurable via experimental_configs MX_APP_NAME) instead of assuming the head node and a fixed port. An explicit MX_SERVER_ADDRESS still wins. Discovery is async, so MX setup moved from VLLMEngine.__init__ to the start of VLLMEngine.start. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Listen on RAY_MX_SERVER_PORT (default 8931) instead of a free port, and advertise it through address(), so replicas still don't assume where the server runs. Drop the port, log_path and cache_dir arguments: the server's output goes to the replica's log and its cache uses the MX default. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
get_mx_app_name() reads RAY_MX_APP_NAME (default "mx"), next to the other MX server settings. An LLMConfig's experimental_configs MX_APP_NAME still overrides it per deployment. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Replace the experimental_configs keys (MX_APP_NAME, MX_METADATA_PORT_BASE, MX_WORKER_GRPC_PORT_BASE, MX_READY_PORT_BASE) with RAY_MX_* env vars in serving_patterns/model_express/envs.py; set them on the LLM app's runtime_env for per-deployment values. The MX_* names that remain are the MX client's own. Log every MX_*/MODEL_EXPRESS_* env var the replica ends up with instead of a fixed list. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
MX already adds each worker's device index to MX_METADATA_PORT and MX_WORKER_GRPC_PORT, and vLLM's Ray workers address GPUs by physical index, so those ports are unique per node without a rank-based offset. The ready endpoint is per replica, and deployment-scoped ranks let two deployments on one node pick the same port; bind it to a free port instead and drop RAY_MX_READY_PORT_BASE. Signed-off-by: Kourosh Hakhamaneshi <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D
Public alpha builder for the ModelExpress server app, documented in the Serve LLM API reference. Signed-off-by: Kourosh Hakhamaneshi <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D
The CUDA base image ships wget but not curl, so the builder stage failed with `curl: command not found`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
load_format="modelexpress" imports the MX client in vLLM's workers, but the image only shipped the server binary. Build the client wheel in the same builder stage, from the same commit as the server (0.8.0 is not on PyPI), and install it with --no-deps: its import-time dependencies are already in the image. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
A rolling update starts the new ModelExpressServer replica while the one it replaces can still hold the server port (up to its graceful shutdown), so the new server failed to bind and the replica crash-looped until the old one exited. Wait for the port to be released, then for the new server to listen, within startup_timeout_s (now 60 s). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request integrates ModelExpress (MX) with the vLLM engine, enabling replicas to load weights and JIT caches from already-serving peers over NIXL. It adds the MX server as a Ray Serve deployment, updates the Dockerfile to build the MX server and client, and introduces a device-neutral torch.compile cache backport. The review feedback highlights several critical improvements for IPv6 compatibility, including enclosing IPv6 addresses in square brackets for HTTP URLs and gRPC addresses, supporting IPv6 in the readiness HTTP server, and using 'localhost' instead of '127.0.0.1' for port checks. Additionally, it suggests adding robust error handling when retrieving the MX server deployment handle.
The replica set MX_WORKER_HOST to its own node IP and vLLM copied it into every worker, so when a replica's workers span nodes (TP/PP across nodes), workers on other nodes advertised the wrong host for P2P metadata and NIXL. Set MX_WORKER_HOST per worker in Serve LLM's worker setup hook instead, when MX is enabled (MX_SERVER_ADDRESS is set) and the user hasn't set it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cfd371c. Configure here.
There was a problem hiding this comment.
- we should fail loudly when fractional GPU serving is configured with model express.
- can we add a cold-start -> peer-start release test, ideally with the configs in yaml reflecting how we'll set up in production? you can use this compute: https://github.com/ray-project/ray/blob/master/release/llm_tests/serve/llm_2x_2xh100.yaml.
ray-llm compile-cache patch: vllm-device-aware-compile-cache.patch keys the cache by GPU index, which limits cache reuse to replicas on the same index. The backport makes it unnecessary.
should we remove vllm-device-aware-compile-cache.patch then?
…ER_HOST hook - Pin the MX server with ray._common.constants.HEAD_NODE_RESOURCE_NAME. - Remove the worker setup hook that set MX_WORKER_HOST: vLLM's Ray executor applies the replica's MX_* env in initialize_worker(), after the hook runs, so it never fired. The replica still leaves MX_WORKER_HOST unset, so each worker's MX client detects its own host. - Note why _ReadyHandler.do_GET has that name. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
MX registers each worker's GPU with NIXL and transfers whole GPU state, so replicas fail early with a clear error when placement_group_config or VLLM_RAY_PER_WORKER_GPUS gives a worker less than one GPU. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
llm_serve_model_express_scaleout (nightly, 2x 2xH100): deploys the mx app and Qwen3-8B with load_format=modelexpress (TP=2, one replica per node) from a production-style Serve config, scales from 1 to 2 replicas under load, and checks from the vLLM worker logs that the second replica loaded its weights from the first over P2P. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
|
@jeffreywang88 thanks for the review. Addressed:
|
A replica with load_format=modelexpress now fails with an error naming the missing app, build_mx_app, and RAY_MX_APP_NAME instead of Serve's bare KeyError. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
|
@jeffreywang88 on removing |
vllm-project/vllm#63247 now makes VLLM_COMPILE_ON_ONE_RANK opt-in and applies torch's compile_on_one_rank during its own compile (overriding the global setting), and only on torch >= 2.14. The backport skipped itself whenever vLLM had the flag, which would leave the compile cache device-specific again. Now: on torch >= 2.14 with that vLLM, set VLLM_COMPILE_ON_ONE_RANK=1 unless the user set it; on older vLLM set torch's flag; on torch 2.13 keep the codegen backport. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019GPW5Lsj3QJecCMyigWk5D Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Adds a Ray Serve LLM user guide for ModelExpress fast scale-out (`load_format="modelexpress"`). Stacked on #67316: the base is `kourosh/mx-integration`, so the diff shows only the docs. - New page `doc/source/serve/llm/user-guides/model-express.md`: how the `mx` app and LLM replicas interact, deployment in YAML and Python, requirements (image, NIXL backend, RDMA), configuration (`RAY_MX_*`), example results from a 2x 8xH100 run, and limitations. - Listed under **Configure and deploy** in the user guide index, next to Deployment initialization. - Deployment initialization gets a short "Load from a running replica" section and a See also link pointing to the new page. --------- Signed-off-by: Kourosh Hakhamaneshi <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Kourosh Hakhamaneshi <[email protected]> # Conflicts: # release/release_tests.yaml
| return | ||
| from ray.llm._internal.serve.engines.vllm.patches import compile_cache_compat | ||
|
|
||
| compile_cache_compat.apply() |
There was a problem hiding this comment.
This runs for every Serve LLM deployment, not just load_format="modelexpress" ones: _worker_process_setup_hook is registered by default (RAYLLM_ENABLE_WORKER_PROCESS_SETUP_HOOK defaults to 1, llm_server.py), and this calls apply() whenever vllm imports.
So on any existing non-MX deployment:
- torch 2.13:
PyCodeCache.write/loadandStaticallyLaunchedCudaKernelget monkeypatched. - torch >= 2.14:
VLLM_COMPILE_ON_ONE_RANK=1/compile_on_one_rank=Truegets turned on. - Both paths add
_add_compile_cache_factor(or vLLM's own one-rank key), so the compile-cache hash changes and everyone's existingtorch.compilecache is invalidated on upgrade.
It also makes the previously no-op hook import vllm (and torch) in every process with this runtime env, including the small node-init tasks.
Could this be gated to MX deployments only, e.g. have the MX path set an env var in the runtime env and check it here before importing anything? If the intent is to apply it to all deployments, I think that needs its own callout and testing on the non-MX path.
There was a problem hiding this comment.
it is fine for the patch to be applied unconditionally.
| _CURRENT_DEVICE = "__import__('torch').cuda.current_device()" | ||
|
|
||
|
|
||
| def apply() -> None: |
There was a problem hiding this comment.
apply() has no error handling and runs inside worker_process_setup_hook. It reaches into private torch/vLLM internals (torch._inductor.codecache.PyCodeCache, torch._inductor.runtime.static_triton_launcher.StaticallyLaunchedCudaKernel, envs.compile_factors). If any of those move or are missing in a given torch 2.13.x / vLLM build, the ImportError/AttributeError fails the setup hook, which fails worker startup. Combined with the hook running for every deployment (comment on __init__.py), that would crash-loop all Serve LLM apps, not just MX ones.
Since this is a best-effort backport, could it catch exceptions and log a warning instead (similar to the existing "no backport for torch %s" branch), so a missing symbol degrades to "cache not device-neutral" rather than "replica can't start"?
There was a problem hiding this comment.
the patch is temporary till vllm releases and we bump. so we should go ahead with the current approach (only way possible at this vllm version)
…67921) ## Description ModelExpress's metadata and worker gRPC ports default to 15555 and 16555 (plus each worker's GPU index). Both sit inside Ray's default worker port range, 10002–19999, where any Ray worker process may already be listening. **What we hit:** two DeepSeek-V4.1-Flash TP4 replicas on one node. One TP rank failed with `Failed to bind to address [::]:16556`; `ss` showed an idle Ray worker (`ray::IDLE`) holding the port. That rank never started its MX gRPC server, so the replica could not act as a P2P source, and its publisher retried every second for the full 30-minute timeout. **Fix:** default to 21555 and 22555 — above Ray's worker range and below the Linux ephemeral range (32768+). The `RAY_MX_*_PORT_BASE` overrides are unchanged. ## Related issues Follow-up to #67316. ## Additional information AI assistance was used. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Kourosh Hakhamaneshi <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>

Description
Adds ModelExpress (MX) support to Ray Serve LLM. With
engine_kwargs={"load_format": "modelexpress"}, a newLLMServerreplica loads its weights, and its torch.compile/Triton/FlashInfer caches, from an already-serving replica over NIXL instead of from storage. Scale-out then skips the download and most of the warm-up.Overview
flowchart LR subgraph head["Head node"] CTL["Serve controller"] subgraph mxapp["Serve app: mx"] S["(1) ModelExpressServer replica<br/>runs modelexpress-server :8931"] end end subgraph llmapp["Serve app: llm"] subgraph n1["Worker node 1"] subgraph R1["LLMServer replica 1 (serving)"] E1["VLLMEngine<br/>(3) /ready endpoint"] W1["vLLM workers<br/>MX loader + publisher"] end end subgraph n2["Worker node 2"] subgraph R2["LLMServer replica 2 (starting)"] E2["VLLMEngine<br/>/ready endpoint"] W2["vLLM workers<br/>MX loader"] end end end E1 & E2 -. "(2) handle.address()" .-> S W1 -. "(3) poll /ready" .-> E1 W1 -- "(4) publish source + heartbeat" --> S W2 -- "(5) find READY sources" --> S W1 == "(6) NIXL: weights + JIT caches" ==> W2mxapp runs oneModelExpressServerreplica on the head node, next to the Serve controller. It launches themodelexpress-serverbinary on port 8931. It is a registry of which replica serves which model, and is control plane only.LLMServerreplica callsaddress()on themxapp's deployment handle. It puts the result intoMX_SERVER_ADDRESSalong with the rest of theMX_*env its vLLM workers read./readyendpoint that returns 503 until its engine has started, then 200. Its own vLLM workers poll it./readyreturns 200, replica 1's workers register it with the server as a READY source and heartbeat every 30 s. After the compile caches settle, they also publish its JIT caches.Startup:
serve run(no peer yet)Scale-out: autoscaler adds a replica
If no source is READY (cold start, or every source is dead), the loader falls back to storage as in the first flow. A dead source stays registered until its heartbeat times out (90 s); a load that tries it falls back to a live peer.
Changes
mxappray.serve.llm.mx.build_mx_app(alpha),serving_patterns/model_express/modelexpress-serveronRAY_MX_SERVER_PORT(8931) and exposesaddress().docker/ray-llm/Dockerfilemodelexpress-serverand the matching Python client wheel at one pinned commit; the image ships the binary at/usr/local/bin/modelexpress-server(RAY_MX_SERVER_BINARY_PATHoverrides) and installs the client.engines/vllm/model_express.py, called fromVLLMEngine.start()mxhandle, port bases, peer identity (MX_MODEL_NAME_OVERRIDE), the/readyURL, and copiesMX_*to vLLM's Ray workers.llm_config.pyload_format="modelexpress"skips safetensors downloads; weights come from a peer.engines/vllm/patches/compile_cache_compat.pyVLLM_COMPILE_ON_ONE_RANK(vllm-project/vllm#63247) on torch >= 2.14. Reduces to setting that variable once Serve LLM requires such a vLLM.All Ray-side settings are
RAY_MX_*env vars (serving_patterns/model_express/envs.py);MX_*are the MX client's own.Related issues
Related to vllm-project/vllm#63247.
Additional information
Usage
Validation: multi-node (Anyscale service, 2x 8xH100 with EFA, Qwen3-235B-A22B-Instruct-2507-FP8, TP=8 + EP, one replica per node, HAProxy + direct streaming, autoscaling 0 to 2)
Requests during scale-out: 279, TTFT p50 0.1 s. This uses
moe_backend: triton: on Hopper with block FP8 and EP, vLLM 0.31's default FlashInfer CUTLASS MoE JIT-builds 248 CUDA files on first use (~16 min), and the parallel build exhausts the node's 2 TB of RAM.Validation: single node (2x H100, vLLM 0.31, Qwen3-0.6B)
cuda:1(0.51 s)200/200 requests succeeded. Without the backport, replica 2 crash-loops with
CUDA driver error: invalid argument, with or without MX. Also verified behind HAProxy with direct streaming. Unit tests:test_model_express.py.The ray-llm image with the MX server binary and client builds in CI (release build 112235).
Open items
flashinfer-jit-cache) in the ray-llm image would cut this.vllm-device-aware-compile-cache.patchkeys the cache by GPU index, which limits cache reuse to replicas on the same index. The backport makes it unnecessary.🤖 Generated with Claude Code