Skip to content

[llm][mx] Add ModelExpress support to Ray Serve LLM - #67316

Merged
kouroshHakha merged 21 commits into
ray-project:masterfrom
kouroshHakha:kourosh/mx-integration
Nov 5, 2026
Merged

kouroshHakha merged 21 commits into
ray-project:masterfrom
kouroshHakha:kourosh/mx-integration

Conversation

@kouroshHakha

@kouroshHakha kouroshHakha commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds ModelExpress (MX) support to Ray Serve LLM. With engine_kwargs={"load_format": "modelexpress"}, a new LLMServer replica 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" ==> W2
Loading
  1. MX server. The mx app runs one ModelExpressServer replica on the head node, next to the Serve controller. It launches the modelexpress-server binary on port 8931. It is a registry of which replica serves which model, and is control plane only.
  2. Discovery. At engine start, each LLMServer replica calls address() on the mx app's deployment handle. It puts the result into MX_SERVER_ADDRESS along with the rest of the MX_* env its vLLM workers read.
  3. Readiness. Each replica serves a /ready endpoint that returns 503 until its engine has started, then 200. Its own vLLM workers poll it.
  4. Publish. Once /ready returns 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.
  5. Lookup. A new replica (replica 2) asks the server which replicas are READY sources for the model, and gets replica 1.
  6. Transfer. Replica 2's workers pull the weights and the torch.compile, Triton and FlashInfer caches from replica 1 over NIXL, GPU to GPU. The bytes never go through the MX server. Once replica 2 is up, it goes through steps 3 and 4 and becomes a second source.

Startup: serve run (no peer yet)

sequenceDiagram
  participant C as Serve controller
  participant S as mx: ModelExpressServer
  participant R as llm: LLMServer replica 1
  participant W as replica 1's vLLM workers
  C->>S: start replica
  S->>S: spawn modelexpress-server, wait for :8931
  C->>R: start replica (node init skips safetensors)
  R->>S: handle.address()
  R->>R: set MX_* env, start /ready (503)
  R->>W: start engine
  W->>S: find READY sources for the model
  S-->>W: none
  W->>W: load weights from storage (mirror / HF), compile
  R->>R: engine started, /ready returns 200
  W->>R: poll /ready gets 200
  W->>S: publish as source (READY), heartbeat every 30 s
  W->>S: publish JIT caches once cache dirs settle (5 s)
Loading

Scale-out: autoscaler adds a replica

sequenceDiagram
  participant C as Serve controller
  participant S as mx: ModelExpressServer
  participant W1 as replica 1's workers (source)
  participant R as llm: LLMServer replica 2
  participant W as replica 2's workers
  C->>R: start replica (any node, any GPU index)
  R->>S: handle.address()
  R->>R: set MX_* env, start /ready (503)
  R->>W: start engine
  W->>S: find READY sources for the model
  S-->>W: replica 1
  W1->>W: NIXL transfer: weights + torch.compile / Triton / FlashInfer caches
  W->>W: compile cache hit (device-neutral), warm-up
  R->>R: engine started, /ready returns 200
  W->>S: publish as second source
Loading

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

Piece Where What
mx app ray.serve.llm.mx.build_mx_app (alpha), serving_patterns/model_express/ One-replica deployment on the head node that runs modelexpress-server on RAY_MX_SERVER_PORT (8931) and exposes address().
Server + client docker/ray-llm/Dockerfile Builder stage compiles modelexpress-server and the matching Python client wheel at one pinned commit; the image ships the binary at /usr/local/bin/modelexpress-server (RAY_MX_SERVER_BINARY_PATH overrides) and installs the client.
Replica setup engines/vllm/model_express.py, called from VLLMEngine.start() Sets the MX client env: server address from the mx handle, port bases, peer identity (MX_MODEL_NAME_OVERRIDE), the /ready URL, and copies MX_* to vLLM's Ray workers.
Node init llm_config.py load_format="modelexpress" skips safetensors downloads; weights come from a peer.
Compile-cache backport engines/vllm/patches/compile_cache_compat.py Makes the torch.compile cache device-neutral so a replica on another GPU index can reuse it: rewrites Inductor output on torch 2.13, and turns on vLLM's opt-in VLLM_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

from ray import serve
from ray.serve.llm import LLMConfig, build_openai_app
from ray.serve.llm.mx import build_mx_app

serve.run(build_mx_app(), name="mx", route_prefix=None)
serve.run(
    build_openai_app({"llm_configs": [LLMConfig(
        model_loading_config=dict(model_id="Qwen/Qwen3-0.6B"),
        deployment_config=dict(autoscaling_config=dict(min_replicas=1, max_replicas=2)),
        engine_kwargs=dict(load_format="modelexpress"),
    )]}),
    name="llm", route_prefix="/",
)

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)

Stage Replica 1 (cold, Hugging Face) Replica 2 (scale-out via MX)
Weights 336 s 31.6 s: P2P over EFA, 29.76 GB per GPU in 1.1 s (218 Gbps); ~18 s is NIXL registration
torch.compile 83 s 1.1 s (cache from replica 1)
CUDA graph capture 210 s ~50 s (DeepGEMM, Triton, FlashInfer caches from replica 1)
Engine init total 477 s 111 s
Replica start to RUNNING ~15.5 min ~4.1 min

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)

Step Weights torch.compile cache
Replica 1 (GPU 0), no peer From Hugging Face Compiled (16.4 s)
Scale out: replica 2 (GPU 1) P2P from replica 1: 1.2 GB in 0.055 s Reused on cuda:1 (0.51 s)
Replica 1 restart P2P from replica 2 Reused (0.22 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

  • Cold start: replica 1 still spends ~8 min compiling kernels (DeepGEMM, FlashInfer) on a fresh node. Shipping prebuilt FlashInfer kernels (flashinfer-jit-cache) in the ray-llm image would cut this.
  • 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.

🤖 Generated with Claude Code

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]>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

kouroshHakha and others added 9 commits October 23, 2026 18:49
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]>
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
@kouroshHakha kouroshHakha added the go add ONLY when ready to merge, run all tests label Oct 26, 2026
kouroshHakha and others added 3 commits October 25, 2026 19:55
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]>
@kouroshHakha kouroshHakha changed the title [llm] Add ModelExpress support to Ray Serve LLM [llm][mx] Add ModelExpress support to Ray Serve LLM Oct 27, 2026
@kouroshHakha
kouroshHakha marked this pull request as ready for review October 27, 2026 22:28
@kouroshHakha
kouroshHakha requested review from a team as code owners October 27, 2026 22:28

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue llm labels Oct 28, 2026
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]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

@jeffreywang88 jeffreywang88 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread docker/ray-llm/Dockerfile Resolved
Comment thread docker/ray-llm/Dockerfile Resolved
…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]>
kouroshHakha and others added 2 commits October 29, 2026 13:02
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]>
@kouroshHakha
kouroshHakha requested a review from a team as a code owner October 29, 2026 20:02
@kouroshHakha

Copy link
Copy Markdown
Contributor Author

@jeffreywang88 thanks for the review. Addressed:

  • Fractional GPUs (ec3fee9): setup_model_express now raises a ValueError when a worker would get less than one GPU, from either placement_group_config or VLLM_RAY_PER_WORKER_GPUS. MX registers whole GPUs with NIXL. Unit tests cover both.
  • Release test (80d07a2): llm_serve_model_express_scaleout, nightly on llm_2x_2xh100.yaml. It deploys the mx app and Qwen3-8B with load_format: modelexpress from a production-style Serve config (configs/serve_qwen3_8b_mx_scaleout.yaml: autoscaling 1 to 2, TP=2 so each replica fills a node), scales to 2 replicas under load, and checks from the vLLM worker logs that the second replica loaded its weights from the first over P2P. It prints both start times.

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]>
@kouroshHakha

Copy link
Copy Markdown
Contributor Author

@jeffreywang88 on removing vllm-device-aware-compile-cache.patch: not yet. On the image's torch 2.13, compile_cache_compat.py makes the compile cache device-neutral, so the patch is no longer needed for correctness. But it's been the safety net for all Serve LLM users for a while, and keeping both is safe: we only lose compile-cache reuse across different GPU indices (e.g. two replicas on one node). Once the image moves to a vLLM with vllm-project/vllm#63247 (torch ≥ 2.14), the backport turns itself off, and we'll remove both the patch and compile_cache_compat.py in one change (per its TODO).

@jeffreywang88 jeffreywang88 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kouroshHakha
kouroshHakha enabled auto-merge (squash) October 30, 2026 05:44
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]>
@github-actions
github-actions Bot disabled auto-merge October 30, 2026 05:53
@kouroshHakha
kouroshHakha enabled auto-merge (squash) October 30, 2026 05:54
@github-actions
github-actions Bot disabled auto-merge October 30, 2026 06:17
@kouroshHakha
kouroshHakha enabled auto-merge (squash) October 30, 2026 17:14
kouroshHakha added a commit that referenced this pull request Oct 30, 2026
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
@github-actions
github-actions Bot disabled auto-merge November 4, 2026 22:42
@kouroshHakha
kouroshHakha enabled auto-merge (squash) November 4, 2026 23:00
return
from ray.llm._internal.serve.engines.vllm.patches import compile_cache_compat

compile_cache_compat.apply()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/load and StaticallyLaunchedCudaKernel get monkeypatched.
  • torch >= 2.14: VLLM_COMPILE_ON_ONE_RANK=1 / compile_on_one_rank=True gets 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 existing torch.compile cache 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is fine for the patch to be applied unconditionally.

_CURRENT_DEVICE = "__import__('torch').cuda.current_device()"


def apply() -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@kouroshHakha
kouroshHakha merged commit e65c2e2 into ray-project:master Nov 5, 2026
7 checks passed
kouroshHakha added a commit that referenced this pull request Nov 7, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests llm serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants