Ray支援構建可擴充的人工智慧(AI)和Python應用程式,廣泛應用於機器學習領域。您可以基於ACK叢集建立Ray Cluster,並在本地提交Job執行分布式任務,用於訓練模型、資料處理、模型評估等情境。在本地RayCluster提交Ray Job。
前提條件
Ray Cluster內運行Job作業有多種方式。更多資訊,請參見how do you use the ray-client和quick start useing the ray job cli。
執行以下命令,查詢Ray Cluster的Pod資訊。
kubectl get pod -n ${RAY_CLUSTER_NS}預期輸出:
NAME READY STATUS RESTARTS AGE myfirst-ray-cluster-head-v7pbw 2/2 Running 0 39m執行以下命令,您可以在本地終端串連到Pod內部的Bash Shell。
請將Pod名稱替換為您實際的Pod的名稱。
kubectl exec -it -n ${RAY_CLUSTER_NS} myfirst-ray-cluster-head-v7pbw -- bash在Head Pod中使用
echo或cat命令,儲存my_script.py檔案。import ray import os # 串連本地或者遠程ray cluster ray.init() @ray.remote(num_cpus=1) class Counter: def __init__(self): self.name = "test_counter" self.counter = 0 def increment(self): self.counter += 1 def get_counter(self): return "{} got {}".format(self.name, self.counter) counter = Counter.remote() for _ in range(10000): counter.increment.remote() print(ray.get(counter.get_counter.remote()))運行
my_script.py指令碼,執行分布式任務。python my_script.py # 預期輸出 2024-01-24 04:25:27,286 INFO worker.py:1329 -- Using address 127.0.0.1:6379 set in the environment variable RAY_ADDRESS 2024-01-24 04:25:27,286 INFO worker.py:1458 -- Connecting to existing Ray cluster at address: 172.16.0.236:6379... 2024-01-24 04:25:27,295 INFO worker.py:1633 -- Connected to Ray cluster. View the dashboard at http://172.16.0.236:8265 test_counter got 0 test_counter got 1 test_counter got 2 test_counter got 3 ...
相關操作
您可以在本地訪問Ray的可視化Web介面DashBoard,請參見本地訪問Ray DashBoard。
關於如何在普通ECS節點或虛擬ECI節點中結合Ray autoscaler實現Auto Scaling,請參見基於Ray autoscaler與ACK autoscaler實現Auto Scaling、結合Ray autoscaler實現ECI節點的Auto Scaling。