Prompts Forms Resume Reports ★ Saved ★ Saved★ + Submit a tool
Tools and frameworks

Ray Distributed Framework

About 3943 characters Updated Nov 30, 2026 27 views AI wiki

Ray is an open-source distributed computing framework incubated at UC Berkeley RISELab and later commercialized by Anyscale, extending single-machine code smoothly into cluster code with Python primitives. It is currently the de facto parallel scheduling layer in AI infrastructure: Tune for hyperparameter search, Train for distributed training, Data for data pipelines and Serve for online inference, with all libraries sharing the same resource scheduling and runtime.

Core Principles

Ray has only three kinds of abstraction. A Task is a stateless remote function decorated with @ray.remote, returning an object reference immediately without blocking. An Actor is a stateful remote class whose instance resides on a node and can hold model weights, connection pools or any context that must be preserved. An Object is a distributed immutable object stored in the shared-memory object store of each node. These three primitives are enough to express the vast majority of parallel patterns at low learning cost.

Underneath is a distributed runtime: a global control store holds cluster metadata and object locations, the raylet on each node manages local resources and the object store, and a resource-aware scheduler matches tasks to nodes by CPU, GPU, memory and custom resources. Tasks form a data dependency graph through object references, producing a dynamic DAG that the scheduler uses for pipelined execution; data transfer favors zero-copy and locality-aware reads to avoid the network, which is its most critical design for performance.

The upper-layer libraries are built on these primitives: Train uses actors for data parallelism and model sharding, integrating PyTorch DDP, DeepSpeed and FSDP; Tune uses algorithms such as ASHA, PBT and HyperBand for search; Data uses streaming operators for batch inference and ETL with operator fusion and pipelining; Serve builds inference replicas and routing on actors, supporting composite model graphs and autoscaling.

Key Points

Resource declaration: @ray.remote(num_gpus=1), @ray.remote(resources={"TPU": 1}), and Ray uses these for placement and isolation, achieving GPU exclusivity by setting visible device environment variables. A cluster can be started with ray start --head and ray start --address=..., and in production it is more often orchestrated on Kubernetes via KubeRay, managing the cluster as a CRD.

Integration with vLLM is a current hotspot: vLLM offers a Ray distributed execution backend option, and cross-node tensor parallelism and pipeline parallelism rely on Ray to launch workers; Ray Serve is often the outer gateway for multi-model deployment, canary release and elastic scaling. This differs from the paths of DeepSpeed, Horovod and Spark - Ray emphasizes native Python and mixed scheduling of tasks and actors, Spark is strong in batch processing and SQL, and Horovod only handles gradient synchronization during training.

Judgment criteria: if the task is a heterogeneous, dynamic Python workflow requiring frequent scheduling (agent orchestration, reinforcement learning training, batch inference, hyperparameter search), Ray fits well; for purely static large-scale data warehouse analysis, Spark is more mature; and if it is only single-machine training, using Ray actually adds complexity.

For cluster operations, Ray provides a dashboard that visualizes node resources, task topology, object store usage and the distribution of actors, which is very useful for troubleshooting. Production deployment must also consider fault tolerance semantics: by default, if a worker dies, the actors running on that node are also lost, so restart policies must be set via max_restarts and critical state must be persisted to disk or external storage, otherwise long-running jobs will be wasted.

Common Misconceptions

Misconception one is treating Ray as a universal accelerator; in fact it does no optimization inside a single task, and the speedup comes from parallelism and scheduling, so when granularity is too fine the scheduling overhead exceeds the gain. Misconception two is overusing actors, leaving many persistent processes occupying memory. Misconception three is ignoring object store growth: large objects that accumulate without release can drag down a node or even trigger OOM, so references must be released after fetching values.

Application Scenarios

Large-scale hyperparameter search, distributed model training, batch offline inference, reinforcement learning training and environment parallelism, multi-model service orchestration, data ETL and vectorized pipelines, and agent workflow scheduling.