Share
Embed
Rayで分散処理
sakami
April 08, 2026
Transcript
24 slides
-
4 ▪ 分散処理を行うためのPythonライブラリ Rayとは? https://github.com/ray-project/ray • シンプルで柔軟なAPI: 既存のPythonコードからの書き換えが簡単 • 分散処理への書き換え:
ローカルとほとんど同じコードで分散処理を実行できる • リソース管理機能: orchestration, scheduling, fault-tolerance, auto-scaling -
5 ▪ Rayで動作するライブラリ群 ▪ 機械学習ワークロードをすべてカバーする Ray AI Libaries • Ray
Data: データ処理 • Ray Train: 分散学習 • Ray Tune: ハイパラチューニング • RLlib: 強化学習 • Ray Serve: 推論サービング https://www.youtube.com/watch?v=oH9pJavu-PU -
8 ▪ ローカルで並列処理を実行するコード ▪ 各処理はTaskと呼ばれる ▪ ray.get はすべての処理が完了するまで待ち、結果を取得する関数 Tasks 1.
並列処理したい関数に @ray.remote デコレータをつける 2. ray.init() を呼んで Ray を起動する 3. <関数名>.remote() を呼んで、タスクを実行する 4. ray.get() を呼んで、結果を取得する -
9 Tasksの機能 task1 task2 task3 依存関係のあるタスク実行 ray.wait Rayはタスクの依存関係を自動的に解析し、 処理の順序を適切にスケジューリングする ray.get
とは異なり、実行が完了したタスク から順に結果を受け取る -
11 ▪ プロセスに状態を持たせることができる ▪ 各プロセスはActorと呼ばれる ▪ 簡単に各プロセスと情報をやり取りできる Actors 1. クラスに
@ray.remote デコレータをつける 2. <クラス名>.remote() を呼んでプロセスを初期化する 3. <クラス名>.<関数名>.remote() を呼んで処理を実行する -
14 ▪ 複数の計算ノードを束ねるクラスタ ▪ AWS, GCPやオンプレサーバー上にクラスタを構成する ▪ Kubernetesクラスタ上で実行することもできる Ray Cluster
https://docs.ray.io/en/latest/cluster/key-concepts.html#ray-cluster https://docs.ray.io/en/latest/cluster/kubernetes/index.html -
15 Ray Dashboard https://docs.ray.io/en/latest/ray-observability/getting-started.html ▪ Ray Cluster用のダッシュボード ▪ ノードごとのCPU/GPU使用率やメモリ、ディスクが表示される ▪
py-spy、PyTorch Profiler、Nsight Systemsなど外部Profilerとの連携 ▪ ログやRayタスクの進行状況も確認できる -
16 ▪ クラスタ構成の設定を行うYamlファイルを作成 ▪ 以下のリンクからファイルをコピーし、設定を編集する ▪ https://github.com/ray-project/ray/blob/master/python/ray/autoscaler/gcp/ex ample-full.yaml ▪ $
ray up ~~.yaml を実行する Ray Clusterを立ち上げる -
17 ▪ 実行したいPythonコードのray.initの引数に address=”auto”を追加 ▪ Ray Clusterを立ち上げた状態で、$ ray submit ~~.yaml
~~.py を実行する Ray ClusterでPythonコードを実行する ray.init の引数に address=”auto” を追加 -
18 ▪ Ray Clusterを立ち上げた状態で、$ ray dashboard ~~.yaml を実行する ▪ ブラウザで
http://localhost:8265 を開く Ray Dashboardを開く -
20 ▪ Ray Distributed Debbuger ▪ Ray + vLLM ▪
Ray on Vertex AI 応用編 -
22 ▪ vLLMはRayを使って実装されているため、Ray Cluster上で実行すれば自動で 分散処理を行ってくれる ▪ Ray側にもvLLMとのインテグレーション関数が用意されている Ray + vLLM
https://github.com/vllm-project/vllm https://www.youtube.com/watch?v=HDSy09hrm2I -
23 ▪ Vertex AI上にRay Clusterを構成する ▪ Ray Clusterと比較したメリット ▪ BigQueryやVertex
AI Notebooks などのGoogle Cloudサービスとの 連携が効率的にできる ▪ インスタンスの外部ポートを 開けなくてもよい Ray on Vertex AI https://cloud.google.com/vertex-ai/docs/open-source/ray-on-vertex-ai/overview -
24 ▪ GitHub - ray-project/ray ▪ Welcome to Ray! —
Ray 2.49.2 ▪ Getting Started with Ray Clusters ▪ Ray, a Unified Distributed Framework for the Modern AI Stack | Ion Stoica ▪ Ray Summit 2025 ▪ GitHub - ray-project/ray-educational-materials ▪ The Modern AI Stack: Ray ▪ GitHub - vllm-project/vllm ▪ [Ray Meetup] Ray + vLLM in Action: Lessons from Pinterest and Large Scale Distributed Inference ▪ Ray on Vertex AI overview | Google Cloud ▪ Ray on Vertex AI 入門 参考リンク