Ray集群搭建 Python Demo
目錄
- 準備條件(基于linux環(huán)境)
- 參考文獻
- 例子-python Ray集群
-
- 1.部署head節(jié)點
- 2.部署worker節(jié)點
- 部署Ray集群
- 安裝Ray(在所有節(jié)點上安裝)
- Ray工作原理
- Ray的優(yōu)勢
- Ray簡介
準備條件(基于linux環(huán)境)
- 這里部署2個節(jié)點的集群,準備2個linux環(huán)境,ip為
-
安裝 python3:yum install python3
-
Ray學(xué)習(xí)文檔地址:https://ray.readthedocs.io/en/latest/index.html
-
github地址:https://github.com/ray-project/ray
Ray簡介
Ray是用于構(gòu)建和運行分布式應(yīng)用程序的快速,簡單的框架。
Ray與以下庫打包在一起,以加快機器學(xué)習(xí)的工作量:
Tune:可伸縮超參數(shù)調(diào)整
RLlib:可擴展的強化學(xué)習(xí)
Distributed Training :分布式培訓(xùn)
Ray的優(yōu)勢
- 更省時,高效
普通的執(zhí)行方式是這樣的:
Ray:
Ray工作原理
該圖片引用來自參考文獻1:
安裝Ray(在所有節(jié)點上安裝)
pip3 install ray
部署Ray集群
1.部署head節(jié)點
手動在head節(jié)點上啟動:
firewall-cmd --add-port=6379/tcp ray start --head --redis-port=6379
在這個節(jié)點上啟動Ray。您可以通過調(diào)用向集群添加其他節(jié)點:
(Started Ray on this node. You can add additional nodes to the cluster by calling)
您可以通過運行Python將一個驅(qū)動程序連接到集群
(from the node you wish to add. You can connect a driver to the cluster from Python by running
)
如果從不同的機器連接有問題,請檢查防火墻的配置是否正確。如果希望終止已啟動的進程,請運行
(If you have trouble connecting from a different machine, check that your firewall is configured properly. If you wish to terminate the processes that have been started, run
)
2.部署worker節(jié)點
注意:這里的ip 192.168.2.220 是步驟1中head節(jié)點的ip
firewall-cmd --add-port=6379/tcp ray start --redis-address 192.168.2.220:6379日志存放目錄:
/tmp/ray
例子-python Ray集群
# -*- coding: utf-8 -*-
import time
import ray
ray.init(redis_address="192.168.2.220:6379")def f1():time.sleep(1)@ray.remote
def f2():time.sleep(1)#以下需要十秒。
time1=time.time()
[ f1() for _ in range(50)]
print(time.time()-time1)#以下需要一秒(假設(shè)系統(tǒng)至少有10個CPU)。
time2=time.time()
ray.get([ f2.remote() for _ in range(50)])
print(time.time()-time2)
如上述博客有任何錯誤或者疑問,請加VX:1755337994,及時告知!萬分感激!?
總結(jié)
以上是生活随笔為你收集整理的Ray集群搭建 Python Demo的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言小白适合入门的项目——扫雷
- 下一篇: python-视频分帧多帧合成视频