Ray 分布式计算框架
Ray 提供分布式任务、Actor、训练、超参搜索和模型服务。AI 场景常用 Ray Train、Ray Tune、Ray Serve 和 Ray Data,适合把 Python 负载扩展到多机多卡。
安装并启动本地集群:
pip install "ray[default]"
ray start --head --port=6379
ray status
连接集群:
ray start --address=10.0.0.10:6379
提交任务:
ray job submit --address http://127.0.0.1:8265 -- python job.py
分布式任务示例:
import ray
ray.init(address="auto")
@ray.remote
def square(x):
return x * x
print(ray.get([square.remote(i) for i in range(10)]))
Ray Serve:
from ray import serve
serve.start()
@serve.deployment
def hello(request):
return "hello"
serve.run(hello.bind())
ray.init(address="auto") 在集群外运行,找不到 GCS。@ray.remote(num_gpus=1) 中声明,调度不到 GPU。