Skip to content

vllm.v1.executor.ray_executor_v2

Classes:

  • RayExecutorV2 –

    Ray-based distributed executor using MessageQueue communication.

  • RayWorkerHandle –

    Handle for a Ray worker actor, compatible with MultiprocExecutor.

  • RayWorkerProc –

    Worker process that runs inside a Ray actor.

RayExecutorV2

Bases: MultiprocExecutor

Ray-based distributed executor using MessageQueue communication.

Inherits from MultiprocExecutor to reuse the MQ-based control plane and NCCL data plane. Workers are Ray actors.

Async scheduling is enabled, inherited from MultiprocExecutor. This is cricitcal for RayExecutorV2 to be performant.

Methods:

  • shutdown –

    Properly shut down the executor and its workers.

  • start_worker_monitor –

    Monitor worker liveness via ray.wait() on run() ObjectRefs.

_build_runtime_env()

Build a runtime_env dict for RayWorkerProc actors.

Driver env vars are applied separately via initialize_worker with setdefault semantics.

_get_actor_resource_kwargs() staticmethod

Return Ray actor resource kwargs for the current platform.

_init_executor()

Initialize the RayExecutorV2 executor.

_join_monitor_thread()

Wait for the monitor thread to exit.

Must be called before tearing down Ray resources — the monitor may be inside ray.wait() which would segfault if Ray is shut down underneath it. When the monitor itself calls shutdown() on worker death, we skip the join because the thread is about to return anyway.

shutdown()

Properly shut down the executor and its workers.

start_worker_monitor(inline=False)

Monitor worker liveness via ray.wait() on run() ObjectRefs.

RayWorkerHandle dataclass

Handle for a Ray worker actor, compatible with MultiprocExecutor.

Methods:

  • run –

    Start the worker's busy loop.

Attributes:

  • actor (ActorHandle) –

    Ray worker actor

  • bundle_id_idx (int) –

    Placement group bundle index for the worker

  • local_rank (int) –

    Local rank of the worker

  • node_id (str) –

    Node ID of the worker

  • rank (int) –

    Rank of the worker

  • run_ref (ObjectRef | None) –

    run() ObjectRef used as a sentinel for health monitoring

actor instance-attribute

Ray worker actor

bundle_id_idx = -1 class-attribute instance-attribute

Placement group bundle index for the worker

local_rank instance-attribute

Local rank of the worker

node_id instance-attribute

Node ID of the worker

rank instance-attribute

Rank of the worker

run_ref = None class-attribute instance-attribute

run() ObjectRef used as a sentinel for health monitoring

run()

Start the worker's busy loop.

RayWorkerProc

Bases: WorkerProc

Worker process that runs inside a Ray actor.

Initialization is split into two phases: 1. init: lightweight setup, stores init args (no device/model init) 2. initialize_worker: called after GPU IDs are discovered, completes the full WorkerProc initialization with the correct local_rank and logical-to-physical GPU mapping.

GPU assignment flow:

  1. RayExecutorV2 enables RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES so Ray does not set CUDA_VISIBLE_DEVICES on RayWorkerProc actors at creation time.
  2. Each actor is scheduled with a placement group and bundle index; Ray resolves the physical GPU ID for that bundle at placement time.
  3. After placement, the executor discovers each worker's GPU ID and passes the node's logical-to-physical mapping (assigned_physical_gpu_ids) to initialize_worker(); CUDA_VISIBLE_DEVICES is never modified.

Scheduling must complete before the mapping is known when the placement group is externally managed: only then is the GPU tied to the worker's bundle resolved.

This sequence allows multiple vLLM instances to coexist on the same node: each instance is unaware which physical devices others hold, and the externally managed placement group avoids device assignment conflicts by binding workers to specific placement group bundles.

Methods:

_init_message_queues(input_shm_handle, vllm_config)

Workers on the same node as the executor use shared memory for both the broadcast (input) MQ and the response MQ. Workers on different nodes use TCP (n_local_reader=0).

get_node_and_physical_gpu_ids()

Return (node_id, physical_gpu_ids) assigned to this actor by Ray.

initialize_worker(local_rank, env_vars, distributed_init_method, driver_env_vars=None, assigned_physical_gpu_ids=None)

Complete initialization after GPU assignment is known.

driver_env_vars are applied with setdefault — they fill in missing vars but never overwrite node-local values. env_vars always overwrite. assigned_physical_gpu_ids maps local_rank to physical CUDA device ID.

run()

Main entry point called via actor.run.remote().

wait_for_init()

Respond to the driver's wait_until_ready() barrier.