Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2022-06-18 Ray Trainの紹介@機械学習の社会実装勉強会第12回

2022-06-18 Ray Trainの紹介@機械学習の社会実装勉強会第12回

Naka Masato

June 18, 2022
Tweet

More Decks by Naka Masato

Other Decks in Technology

Transcript

  1. Ray Trainの紹介
    2022-06-18
    Naka Masato

    View Slide

  2. 自己紹介
    名前 那珂将人
    経歴
    ● アルゴリズムエンジニアとしてレコメンドエンジン開発
    ● インフラ基盤整備
    GitHub:
    https://github.com/nakamasato
    Twitter: https://twitter.com/gymnstcs

    View Slide

  3. Rayを紹介
    UC Berkeley RISE Lab
    で開発されたオープン
    ソースのプロジェクト
    As a general-purpose and universal distributed compute framework,
    you can flexibly run any compute-intensive Python workload —
    1. from distributed training or
    2. hyperparameter tuning to
    3. deep reinforcement learning and
    4. production model serving.
    Deep learning
    から
    Model Serving
    まで開発者が
    簡単にスケールできる
    https://www.ray.io/

    View Slide

  4. 前回 - Ray Components
    さまざまな
    Package
    がある
    1. Core:
    コア ← 前前回
    2. Tune: Scalable hyperparameter tuning
    3. RLlib: Reinforcement learning
    4. Train: Distributed deep learning (PyTorch, TensorFlow, Horovod)
    ← 今回
    5. Datasets: Distributed data loading and compute
    6. Serve: Scalable and programmable serving
    ← 前回
    7. Workflows: Fast, durable application flows

    View Slide

  5. Ray Train
    Ray: Python

    Framework
    依存なしに簡単にスケーラブルにするライブラリ
    ● メイン
    : Distributed Training

    Tensorflow

    Pytorch

    Distributed Training
    を簡単に使える
    もちろん
    Distributed Training
    以外も使えるが、その場合は
    Ray
    を使う意味があまりない

    View Slide

  6. Distributed Training

    Pytorch

    DistributedDataParallel

    Tensorflow

    MultiWorkerMirroredStrategy
    同じモデルを複数のプロセスにもたせて、プロセスごとに異なるデータを与えて学習し、モデルレプリカを同期す
    ることで分散学習する方法
    Ray Train
    では、
    tensorflow or torch

    Trainer
    で指定するだけで必要な設定を自動的にしてくれる

    View Slide

  7. TensorflowのDistributed Training
    以前も紹介済み
    1. 2022-02-26 TensorFlow Training (TFJob)


    2. 2022-03-26 Tensorflow Parameter Server
    Training

    View Slide

  8. Trainの基本的な使い方
    1. Trainer
    を初期化
    a. from ray.train import Trainer
    b. trainer = Trainer(backend="tensorflow", num_workers=2)
    2.
    メインロジックを
    train_func (
    関数
    )
    に記述
    3. Trainer
    を実行
    a. trainer.start() # set up resources
    b. trainer.run(train_func)
    c. trainer.shutdown() # clean up resources

    View Slide

  9. Demo: simple example

    train_func
    ○ 与えられた
    num_epochs
    分、配列
    results

    item i
    を追加

    trainer.run
    で異なる
    num_epochs
    を入れて
    train_func
    を実行

    num_workers

    2
    なので同じもの

    2
    回呼ばれている

    View Slide

  10. ML例: main
    main:
    1. trainer
    の作成
    (backend

    worker
    数の指定、
    gpu
    使用有無など
    )
    2. train.start()
    3. trainer.run(train_func, config)
    4. trainer.shutdown()

    View Slide

  11. ML例: train_func
    1.
    学習条件
    a. per_worker_batch_size: 64 (default)
    i. SGD

    1
    ステップにいくつ
    Example
    を使うか
    b. epochs: 3 (default)
    c. steps_per_epoch: 70 (default)
    i.

    epoch
    でのステップの数
    (batches
    of samples)
    d. num_workers: 2
    2. strategy =
    tf.distribute.MultiWorkerMirroredStr
    ategy()
    3. strategy.scope():
    モデルをこの
    scope
    の中で定義することで
    distribute
    training
    を使える

    View Slide

  12. fitの中身
    keras.Model
    などの
    Distributed Training
    の実装に含まれている
    iterator (data)
    step
    tf.function (remote
    function)
    sync
    model
    step
    tf.function (remote
    function)
    step
    tf.function (remote
    function)

    View Slide

  13. まとめ

    Ray
    を使うと、
    framework
    に関係なく
    Distributed Training
    を活用できる
    ● 使い方もシンプル

    trainer = Trainer(backend="tensorflow", num_workers=2)

    trainer.start()

    trainer.run(train_func)

    trainer.shutdown()
    ● 実際の
    Distributed Training
    の実装自体は各
    Framework
    内にある

    Ray

    Configuration

    Trainer
    でラップ

    View Slide