Run Magpie on a Ray cluster#
2026-07-17
8 min read time
Ray integration lets you offload Magpie’s analyze, compare, and benchmark workloads to remote GPU nodes without changing the evaluation logic—the same AnalyzeMode, CompareMode, and BenchmarkMode code runs on the worker as it would run locally, driven by a RayJobExecutor that the driver submits to the cluster. This is useful when the GPUs, software stack, or model weights you need are on a dedicated cluster node rather than the machine running the CLI or MCP server. This page covers how to configure the cluster connection, set up shared storage, run kernel and benchmark workloads on Ray, and troubleshoot common problems.
Goals and scope#
Offload compilation, correctness checks, profilers, and LLM serving to machines that actually have the GPUs and software stack you need.
Reuse the same mode code (
AnalyzeMode,CompareMode,BenchmarkMode) on the worker; Ray only changes how the task is launched (RayJobExecutor+run_taskon a worker).Rely on shared storage (typically NFS) so Hugging Face caches, InferenceX checkouts, and benchmark artifacts are visible to both driver and workers.
Ray integration does not require the Ray Dashboard or Jobs API—only connectivity to the cluster (ray.init with auto or ray://…).
Prerequisites#
Requirement |
Notes |
|---|---|
Python |
|
GPU worker nodes registered with Ray |
Nodes expose |
Magpie importable on workers |
Default |
Shared filesystem (strongly recommended) |
Same mount path on driver and workers for model cache, InferenceX, and benchmark results. |
Kernel / project paths (analyze and compare) |
Paths in YAML (for example, |
Connect to the cluster (cluster_address)#
RayConfig.cluster_address (and the analyze/compare path: values taken from kernel YAML ray_config.cluster_address into SchedulerConfig.ray_cluster_address) is passed to ray.init(address=…).
Value |
When to use |
|---|---|
|
Driver runs on the Ray head or in the same Ray network namespace so the local GCS is discoverable. |
IP/hostname of head (for example, |
Explicit GCS address when |
|
Driver is remote; connect using Ray Client (typical client port |
Using auto from a laptop that is not attached to the cluster will not reach remote workers—use ray://… or run the driver on the head node.
Analyze and compare on Ray#
The following sections describe how to configure and run kernel analyze and compare workloads on a Ray cluster.
Enable Ray for kernel modes#
Add a top-level
ray_config:block to the kernel YAML.load_kernel_configinMagpie/main.pysetsscheduler.environmenttoraywhenray_configis present (unless overridden).Or set
scheduler.environment: rayin frameworkconfig.yaml/ kernel YAMLscheduler:and supply connection details (see below).
Fields read from kernel YAML into the scheduler#
_get_scheduler_config maps:
ray_config.cluster_address→SchedulerConfig.ray_cluster_addressray_config.shared_storage_path→SchedulerConfig.ray_shared_storage_path
The scheduler then constructs a RayConfig for RayJobExecutor with those fields (and defaults for all other RayConfig attributes such as install_magpie, entrypoint_num_cpus, pip_packages). Extra keys under kernel YAML ray_config are not merged into that executor RayConfig in the current implementation—treat comments in examples as hints for future alignment or for benchmark YAML where merging differs.
Override environment on the CLI#
For any kernel config that implies Ray, you can force local execution:
python -m Magpie analyze --kernel-config examples/ck_gemm_add_ray.yaml -e local
Priority is CLI --environment > kernel YAML > Magpie/config.yaml scheduler (Magpie/main.py _get_scheduler_config).
Remote execution path#
run_analyze/run_comparebuilds kernel configs and callsscheduler.run_analyze/run_compare.Schedulercreates aTaskwithModeType.ANALYZEorCOMPAREandexecutor.execute(task).RayJobExecutor._submit_ray_taskserializestask.to_dict()intojob_payload, merges benchmark-onlyray_configoverrides if present (usually empty for kernel tasks), and callsrun_task.remote(job_payload).On the worker,
run_taskruns_run_analyzeor_run_compare(Magpie/remote/tasks.py)—same classes as locally.
Result shape: the driver receives a dict; main.run_analyze unwraps nested results when Ray returns {"task_id", "results": [...]}.
Example#
See examples/ck_gemm_add_ray.yaml: ray_config.cluster_address, shared_storage_path, plus kernel paths using ${CK_HOME} on the worker.
python -m Magpie analyze --kernel-config examples/ck_gemm_add_ray.yaml --no-perf
Benchmark on Ray#
The following sections describe how to configure and run framework-level benchmarks on a Ray cluster.
Configuration#
In benchmark YAML set:
benchmark:
run_mode: ray
ray_config:
cluster_address: "auto" # or ray://head:10001
shared_storage_path: "/shared_nfs/magpie"
entrypoint_num_cpus: 32
install_magpie: false # common when image already has Magpie
Full RayConfig fields are documented in Magpie/modes/benchmark/config.py. For BenchmarkConfig, ray_config is required when run_mode is ray.
Worker-side behavior#
_run_benchmark (Magpie/remote/tasks.py):
Sets
run_modefromraytolocalso the worker runsBenchmarkModeon that node (Docker or local subprocess), not another Ray hop.Fills default
inferencex_path/hf_cache_pathfromshared_storage_pathwhen omitted.Sets
output_dirto{results_dir}/{task_id}(defaults under shared storage).
The driver does not run vLLM/SGLang; it waits on ray.get and maps the returned dict into BenchmarkResult (benchmarker._populate_result_from_ray).
Tensor parallelism and multi-node hints#
For benchmark payloads only, run_task calls _configure_tp_isolation:
If
TP≤ GPUs on the current Ray node, it clearsRAY_ADDRESSin the worker env and can append vLLM--distributed-executor-backend mpso the child uses local multiprocessing.If
TPexceeds local GPUs, it keepsRAY_ADDRESSand can append vLLM--distributed-executor-backend rayor SGLang--use-ray --nnodes N.
Logic is in Magpie/remote/tasks.py (_get_local_gpu_count, _configure_tp_isolation). Tune EXTRA_VLLM_ARGS / EXTRA_SGLANG_ARGS in YAML if you need overrides.
Entry points on the driver#
Entry |
Location |
Behavior |
|---|---|---|
CLI / MCP |
|
Creates |
|
|
Injects |
Example YAML#
examples/benchmarks/benchmark_vllm_dsr1_ray.yaml shows a full vLLM benchmark targeting Ray with shared storage and install_magpie: false.
Scheduling, GPUs, and the outer num_gpus=0 task#
RayJobExecutor._submit_ray_task declares the remote function with num_gpus=0 but pins it to a node that has GPUs using NodeAffinitySchedulingStrategy (ray.util.scheduling_strategies). RayJobExecutor._find_gpu_node prefers a non-head GPU worker when possible.
Why num_gpus=0? Frameworks such as vLLM might spawn their own Ray or multiprocessing workers and need to control CUDA_VISIBLE_DEVICES / HIP_VISIBLE_DEVICES. Reserving all GPUs on the outer task would conflict with that model.
After the task starts, _clear_hidden_gpus removes Ray-imposed empty visibility env vars so child processes see the node GPUs again (Magpie/remote/tasks.py).
Note
gpu_selection is disabled under Ray. The benchmark YAML’s
gpu_selection block (auto idle-GPU picker) is a no-op when
run_mode: ray: Ray schedules devices itself using num_gpus, and a
driver-side rocm-smi or nvidia-smi scan does not reflect worker nodes.
To restrict the cluster to specific cards, export
ROCR_VISIBLE_DEVICES or CUDA_VISIBLE_DEVICES in the shell before
starting ray start on each node.
Asynchronous benchmark submit (MCP and advanced)#
BenchmarkMode.submit_ray_benchmark(executor) submits a Ray task without blocking; MCP and scripts can poll with the same RayJobExecutor instance. Related MCP tools (see Magpie/mcp/server.py):
ray_task_status: running / succeeded / failedray_task_result: cached result dict after completionray_task_cancel: cancel an object refray_task_list: tracked task IDs
RayConfig reference#
Defined in Magpie/modes/benchmark/config.py (@dataclass RayConfig).
Field |
Role |
|---|---|
|
|
|
Root for HF cache, InferenceX, results layout on workers |
|
CPUs requested on the outer remote task |
|
Declared on |
|
Used when building |
|
Extra pip specs in |
|
Extra env for remote task |
|
If true, adds Magpie project + |
|
Override root used for editable Magpie install |
Derived helpers: results_dir, hf_cache_dir, inferencex_dir.
Source map#
Area |
File |
|---|---|
CLI scheduler / kernel YAML Ray hints |
|
Scheduler, |
|
|
|
Worker entry and mode runners |
|
Benchmark Ray orchestration |
|
|
|
MCP Ray task tools |
|