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

機械学習パイプラインの要件と Vertex Pipelines / Kubeflow Pipelines V2 による実装

機械学習パイプラインの要件と Vertex Pipelines / Kubeflow Pipelines V2 による実装

Asei Sugiyama

August 25, 2021
Tweet

More Decks by Asei Sugiyama

Other Decks in Technology

Transcript

  1. 機械学習パイプラインの要件と Vertex
    Pipelines / Kubeflow Pipelines V2 によ
    る実装
    Asei Sugiyama

    View Slide

  2. Abstract
    機械学習パイプラインの基本的な要件は「オーケストレーション」「デ
    ータとコードの管理」「可視化」
    Kubeflow Pipelines を使うと、機械学習パイプラインを Python で実装
    できる
    Vertex Pipelines を使うと、機械学習パイプラインをサーバーレスに動か
    せる

    View Slide

  3. 自己紹介
    杉山 阿聖 (@K_Ryuichirou)
    Software Engineer @ Repro
    機械学習基盤の設計構

    Advisor @ moneyforward
    TensorFlow User Group
    TFX & Kubeflow
    Pipeline
    機械学習図鑑 共著

    View Slide

  4. Agenda
    ML Pipelines for Software Engineers <-
    Vertex Pipelines / Kubeflow Pipelines V2
    Recap

    View Slide

  5. ML Pipelines for Software Engineers
    ML Pipelines のこれまでの経緯の振り返り
    MLOps : ML & DevOps
    Hidden Technical Debt in Machine Learning Systems
    TensorFlow Extended
    ML systems break. All the time.
    Continuous Training
    Recap

    View Slide

  6. MLOps : ML & DevOps
    MLOps は ML とソフトウェア開発の間の
    対立を解消する取り組み
    具体的なプラクティスはいくつか出てき
    たものの、プラクティスに従うことでは
    なく自分たちの問題解決が重要 (自分たち
    が考える MLOps で良い)
    言い換えると、機械学習により顧客に価
    値提供ができるチーム作りだと言える

    View Slide

  7. Hidden Technical Debt in Machine Learning Systems
    機械学習システムはとにかく複雑
    Sculley, D. and Holt, Gary and Golovin, Daniel and Davydov, Eugene and Phillips, Todd and Ebner, Dietmar and Chaudhary, Vinay and Young, Michael and
    Crespo, Jean-Fran\c{c}ois and Dennison, Dan (2015) Hidden Technical Debt in Machine Learning Systems, Advances in Neural Information Processing
    Systems 28 (NIPS 2015) https://proceedings.neurips.cc/paper/2015/hash/86df7dcfd896fcaf2674f757a2463eba-Abstract.html

    View Slide

  8. TFX (TensorFlow Extended)
    Akshay Naresh Modi and Chiu Yuen Koo and Chuan Yu Foo and Clemens Mewald and Denis M. Baylor and Eric Breck and Heng-Tze Cheng and Jarek
    Wilkiewicz and Levent Koc and Lukasz Lew and Martin A. Zinkevich and Martin Wicke and Mustafa Ispir and Neoklis Polyzotis and Noah Fiedel and Salem
    Elie Haykal and Steven Whang and Sudip Roy and Sukriti Ramesh and Vihan Jain and Xin Zhang and Zakaria Haque TFX: A TensorFlow-Based Production-
    Scale Machine Learning Platform, KDD 2017 (2017) https://proceedings.neurips.cc/paper/2015/hash/86df7dcfd896fcaf2674f757a2463eba-Abstract.html

    View Slide

  9. Continuous Training
    機械学習システムのデプロ
    イを自動化するためには
    CI/CD だけでは足りない
    継続的な学習も必要
    MLOps: 機械学習における継続的デリバリーと自動化のパイプライン - Google
    Cloud https://cloud.google.com/architecture/mlops-continuous-delivery-
    and-automation-pipelines-in-machine-learning

    View Slide

  10. Case Study : Alphabet
    毎時間〜毎日更新される機
    械学習モデルが数多くある
    このような間隔で学習する
    ためには自動化が必須
    Denis Baylor and Kevin Haas and Konstantinos Katsiapis and Sammy Leong
    and Rose Liu and Clemens Menwald and Hui Miao and Neoklis Polyzotis and
    Mitchell Trott and Martin Zinkevich, Continuous Training for Production ML
    in the TensorFlow Extended (TFX) Platform, 2019 {USENIX} Conference on
    Operational Machine Learning (OpML 19) (2019)
    https://www.usenix.org/conference/opml19/presentation/baylor

    View Slide

  11. ML Pipeline Spec
    オーケストレーション
    パイプラインを構成するタスクの実行順の管理
    コードとデータの管理
    モデルの振る舞いを決めるものを同時に管理
    可視化
    入出力と合わせてそれを可視化したもの(典型的にはグラフ)を管理

    View Slide

  12. ML systems break. All
    the time. (1/2)
    機械学習システムはしょっ
    ちゅう壊れる
    原因は ML だけにとどまら
    ない
    Daniel Papasian and Todd Underwood, How ML Breaks: A Decade of
    Outages for One Large ML Pipeline, USENIX Association 2020
    https://www.usenix.org/conference/opml20/presentation/papasian

    View Slide

  13. ML systems
    break. All the
    time. (2/2)
    結局はチームづ
    くり
    Daniel Papasian and Todd Underwood, How
    of Outages for One Large ML Pipeline, USEN
    https://www.usenix.org/conference/opml20/p

    View Slide

  14. Recap
    ML Pipeline は機械学習の複雑さに対する取り組みのひとつ
    CI/CD に加えて学習も考慮する必要がある
    機械学習システムはしょっちゅう壊れるのでチーム作りが必要

    View Slide

  15. Agenda
    ML Pipelines for Software Engineers
    Vertex Pipelines / Kubeflow Pipelines V2 <-
    Recap

    View Slide

  16. Vertex Pipelines / Kubeflow Pipelines V2
    Kubeflow Pipelines
    Kubeflow Pipelines Pros & Cons
    Vertex Pipelines
    Vertex Pipelines & KFP v2 SDK
    Lab Sample Pipeline
    How To Build Components
    How To Build Pipeline
    Vertex Pipeline Pros & Cons

    View Slide

  17. Kubeflow Pipelines
    (1/2)
    Kubeflow の機能の 1 つ
    機械学習パイプラインに特
    化したオーケストレーター
    Kubernetes クラスターにデ
    プロイ
    Kubeflow Pipelines だけで
    デプロイ可能

    View Slide

  18. Kubeflow Pipelines
    (2/2)
    オーケストレーション: Argo
    workflow
    コードとデータの管理:
    MLMetadata
    可視化: WebUI
    右は v1 のアーキテクチャ

    View Slide

  19. Kubeflow Pipelines Pros & Cons
    Pros
    コンテナベースで開発しやすい
    パイプラインを Python で定義できる
    主要な要件を満たす
    Cons
    Kubeflow Pipelines のデプロイが複雑 (アップデートはほぼ不可能)
    運用のために Kubernetes の知識やスキルが必要

    View Slide

  20. Vertex Pipelines
    機械学習パイプラインを実
    行するGCPのサービス
    サーバーレスにパイプライ
    ンを実行
    Kubeflow Pipelines SDK を
    用いてパイプラインを開発

    View Slide

  21. Orchestration
    機械学習パイプラインで定
    義した順にコンテナを逐次
    起動
    コンテナには任意のライブ
    ラリを利用可能
    起動するインスタンスの計
    算資源も指定可能 (CPU,
    Mem, GPU)

    View Slide

  22. ML Metadata

    View Slide

  23. 可視化
    可視化は実装
    が進行中
    Confusion
    matrix
    ROC Curve
    右のような可
    視化を動かす
    だけでも相当
    の知識が必要

    View Slide

  24. Vertex Pipelines & KFP v2 SDK
    Vertex Pipelines は KFP v2 SDK を用いる
    KFP v2 SDK は KFP v1 SDK と非互換
    KFP v2 (バックエンド) は実装が進行中
    ドキュメントやサンプルが乏しい
    仕様を知りたかったらソースコードを読む & 記述方法を知りたかったら
    テストコードを読む

    View Slide

  25. Lab Sample Pipeline
    Vertex Pipelines で動作する
    サンプルパイプライン
    ETL - 前処理 - 訓練 - 評価と
    いう典型的なパイプライン
    を実装
    解説記事 Vertex Pipelines
    で動く Kubeflow Pipelines
    のサンプルを公開しました -
    Repro Tech Blog

    View Slide

  26. How To Build Components
    1. CLI アプリケーションを書く
    2. コンテナイメージを作成し、コンテナレジストリにデプロイする
    3. ComponentSpec を書く

    View Slide

  27. ComponentSpec
    コンポーネントの入出力を定義した YAML ファイル
    name: trainer

    inputs:

    - {name: transformed_train_data_path, type: {GCPPath: {data_type: CSV}}}

    - {name: suffix, type: String}

    outputs:

    - {name: trained_model_path, type: {GCPPath: {data_type: PKL}}}

    implementation:

    container:

    image: gcr.io/kfp-sample-trainer:v0.0.0

    args:

    - {inputPath: transformed_train_data_path}

    - {inputValue: suffix}

    - {outputPath: trained_model_path}

    View Slide

  28. How To Build Pipeline
    1. 定義したコンポーネントを読み込む
    2. パイプラインを定義する
    3. コンパイルする

    View Slide

  29. #1 Load Component
    記述した ComponentSpec を元に Component を作成する
    ファイルパスから作成も可能
    from kfp.components import load_component_from_text

    # ComponentSpec
    を文字列として取得

    component_spec = get_component_spec(name)

    # ComponentSpec
    からコンポーネントを生成するファクトリ関数を作成

    data_generator_op = load_component_from_text(component_spec)

    #
    ファクトリ関数からコンポーネントを生成

    data_generator = data_generator_op()

    View Slide

  30. #2 Define ML
    Pipeline
    Component の
    依存関係を定
    義する
    入出力により
    依存関係が定
    義される
    明示的な定義
    も可能

    View Slide

  31. #3 Compile
    SDK を用いてコンパイルする
    出力は PipelineSpec というスキーマに従う JSON (KFP IR とも)
    compiler.Compiler().compile(

    pipeline_func=kfp_sample_pipeline,

    package_path="kfp_sample_pipeline.json",

    )

    View Slide

  32. Vertex Pipeline Pros & Cons (1/2)
    Pros
    移行したら普通に動いた
    運用の手間はたしかにない
    Kubernetes の知識はたしかにいらない

    View Slide

  33. Vertex Pipeline Pros & Cons (2/2)
    Cons
    Kubeflow Pipelines v2 についてのドキュメントやサンプルが乏しく、ソ
    ースコードの完全理解が必要
    可視化周りは今手を出すのは時期尚早 ( ExecutorInput
    ,
    ExecutorOutput
    というドキュメント化されていないものの仕様と、
    Vertex Pipelines での扱いを理解する必要がある)

    View Slide

  34. Hands on!
    Colab で動くハン
    ズオン
    今日の資料の内容
    をすべて含んでい
    ます
    GCP の設定は必要
    ですが、実際に
    Vertex Pipelines で
    実行できます

    View Slide

  35. まとめ
    Kubeflow Pipelines (KFP) は ML パイプラインを実行するオーケストレ
    ーター
    Vertex Pipelines は KFP と同じパイプラインをサーバーレスに動かせる
    クラウドサービス
    Vertex Pipelines / KFP v2 ともに基本機能は実際に利用できるものの、
    可視化周りは開発中
    サンプルも解説も公開済み

    View Slide

  36. Recap
    機械学習パイプラインの基本的な要件は「オーケストレーション」「デ
    ータとコードの管理」「可視化」
    Kubeflow Pipelines を使うと、機械学習パイプラインを Python で実装
    できる
    Vertex Pipelines を使うと、機械学習パイプラインをサーバーレスに動か
    せる

    View Slide