Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

自己紹介 杉山 阿聖 (@K_Ryuichirou) Software Engineer @ Repro 機械学習基盤の設計構 築 Advisor @ moneyforward TensorFlow User Group TFX & Kubeflow Pipeline 機械学習図鑑 共著

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

ML Metadata

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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}

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

#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()

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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