ray

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())

易错点与排错