Ray集群搭建 Python Demo
目錄
- 準(zhǔn)備條件(基于linux環(huán)境)
- 參考文獻(xiàn)
- 例子-python Ray集群
-
- 1.部署head節(jié)點(diǎn)
- 2.部署worker節(jié)點(diǎn)
- 部署Ray集群
- 安裝Ray(在所有節(jié)點(diǎn)上安裝)
- Ray工作原理
- Ray的優(yōu)勢(shì)
- Ray簡(jiǎn)介
準(zhǔn)備條件(基于linux環(huán)境)
- 這里部署2個(gè)節(jié)點(diǎn)的集群,準(zhǔn)備2個(gè)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簡(jiǎn)介
Ray是用于構(gòu)建和運(yùn)行分布式應(yīng)用程序的快速,簡(jiǎn)單的框架。
Ray與以下庫(kù)打包在一起,以加快機(jī)器學(xué)習(xí)的工作量:
Tune:可伸縮超參數(shù)調(diào)整
RLlib:可擴(kuò)展的強(qiáng)化學(xué)習(xí)
Distributed Training :分布式培訓(xùn)
Ray的優(yōu)勢(shì)
- 更省時(shí),高效
普通的執(zhí)行方式是這樣的:
Ray:
Ray工作原理
該圖片引用來(lái)自參考文獻(xiàn)1:
安裝Ray(在所有節(jié)點(diǎn)上安裝)
pip3 install ray
部署Ray集群
1.部署head節(jié)點(diǎn)
手動(dòng)在head節(jié)點(diǎn)上啟動(dòng):
firewall-cmd --add-port=6379/tcp ray start --head --redis-port=6379
在這個(gè)節(jié)點(diǎn)上啟動(dòng)Ray。您可以通過(guò)調(diào)用向集群添加其他節(jié)點(diǎn):
(Started Ray on this node. You can add additional nodes to the cluster by calling)
您可以通過(guò)運(yùn)行Python將一個(gè)驅(qū)動(dòng)程序連接到集群
(from the node you wish to add. You can connect a driver to the cluster from Python by running
)
如果從不同的機(jī)器連接有問(wèn)題,請(qǐng)檢查防火墻的配置是否正確。如果希望終止已啟動(dòng)的進(jìn)程,請(qǐng)運(yùn)行
(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é)點(diǎn)
注意:這里的ip 192.168.2.220 是步驟1中head節(jié)點(diǎn)的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個(gè)CPU)。
time2=time.time()
ray.get([ f2.remote() for _ in range(50)])
print(time.time()-time2)
如上述博客有任何錯(cuò)誤或者疑問(wèn),請(qǐng)加VX:1755337994,及時(shí)告知!萬(wàn)分感激!?
總結(jié)
以上是生活随笔為你收集整理的Ray集群搭建 Python Demo的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C语言小白适合入门的项目——扫雷
- 下一篇: Zabbix配置模板监控指定服务器主机