Ray
Ray
A distributed ML framework. Parallel training, hyperparameter tuning.
Ray
A distributed ML framework. Parallel training, hyperparameter tuning.
Ray is an open-source framework for distributed computing that makes it easy to run machine learning workloads in parallel across multiple machines. Developed at UC Berkeley's RISELab, it is popular among ML engineers because Python code can be run in a distributed environment with only minimal modifications.
Ray started at UC Berkeley in 2017, and in 2019 the commercial service Anyscale was founded. Existing distributed frameworks such as Spark and Dask are optimized for specific workloads, but Ray aims at general-purpose distributed computing and supports a variety of ML tasks such as reinforcement learning, hyperparameter tuning, and model serving.
The core of Ray is a distributed programming model based on Tasks (functions) and Actors (classes). A single @ray.remote decorator can turn a function into a distributed task, and Ray provides ML-specific libraries such as Ray Tune (hyperparameter tuning), Ray Train (distributed training), and Ray Serve (model serving).
In practice, Ray is becoming the standard for large-scale ML training pipelines. It is used by global companies such as OpenAI, Uber, and Shopify, and is especially active in LLM fine-tuning and reinforcement learning. With Anyscale's managed service, you can easily operate Ray clusters in the cloud.
This is an example of distributed hyperparameter tuning using Ray.
# pip install ray[tune] torch
import ray
from ray import tune
from ray.tune.schedulers import ASHAScheduler
# Ray μ΄κΈ°ν
ray.init()
# νμ΅ ν¨μ μ μ
def train_model(config):
"""νμ΄νΌνλΌλ―Έν° configλ‘ λͺ¨λΈ νμ΅"""
import torch
import torch.nn as nn
model = nn.Sequential(
nn.Linear(10, config["hidden"]),
nn.ReLU(),
nn.Linear(config["hidden"], 1)
)
optimizer = torch.optim.Adam(model.parameters(), lr=config["lr"])
for epoch in range(10):
loss = torch.rand(1).item() # μ€μ λ‘λ νμ΅ λ‘μ§
tune.report({"loss": loss, "epoch": epoch})
# νμ΄νΌνλΌλ―Έν° κ²μ 곡κ°
search_space = {
"lr": tune.loguniform(1e-4, 1e-2),
"hidden": tune.choice([32, 64, 128, 256]),
}
# ASHA μ€μΌμ€λ¬ (μ‘°κΈ° μ’
λ£)
scheduler = ASHAScheduler(max_t=10, grace_period=1, reduction_factor=2)
# λΆμ° νμ΄νΌνλΌλ―Έν° νλ μ€ν
tuner = tune.Tuner(
train_model,
param_space=search_space,
tune_config=tune.TuneConfig(
metric="loss",
mode="min",
num_samples=20, # 20κ° μλ
scheduler=scheduler,
),
)
results = tuner.fit()
print(f"Best config: {results.get_best_result().config}")
As of January 2025, here is the pricing information for Ray and Anyscale.
| Option | Price | Features |
|---|---|---|
| Ray OSS (Open Source) | Free | Self-hosted, community support |
| Anyscale Platform | ~$0.50/hour~ | Managed service, Pay-as-you-go |
| Anyscale Enterprise | Custom quote | SLA, dedicated support, governance |
Cost-saving tips:
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free