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

Vertex AI ではじめる MLOps

Asei Sugiyama
January 27, 2024
100

Vertex AI ではじめる MLOps

Jagu'e'r AI/ML 分科会 #6 用の資料です、MLOps についてこれから取り組む人向けに、全体像の概説と Vertex Pipelines を用いた機械学習パイプラインの構築方法の初歩を説明しています。

Asei Sugiyama

January 27, 2024
Tweet

Transcript

  1. 機械学習までのス テップ 1. 小さく始める 2. 標準化 3. システム化 4. データ分析

    5. 機械学習 機械学習とビジネス プロセス (How Google Does Machine Learning 日本語版) - Coursera https://www.coursera.org/learn/google-machine-learning- jp/lecture/G8qKf/ji-jie-xue-xi-tobizinesu-purosesu
  2. MLOps の分野 DevOps の 3 つの分野で整理できる 1. 技術 2. プロセス

    3. 文化 DORA | DevOps capabilities https://dora.dev/devops-capabilities/
  3. 機械学習パイプラインとは 機械学習のモデル更新に必 要なさまざまなタスクをパ イプラインとして実装した もの 次の内容を実現する バージョン管理 CI/CD/CT 自動テスト MLOps:

    機械学習における継続的デリバリーと自動化のパイプライン https://cloud.google.com/architecture/mlops-continuous-delivery-and- automation-pipelines-in-machine-learning
  4. 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
  5. Data Validation 入手したデータの検証を行 う null チェックや値域のチェ ックなど Akshay Naresh Modi

    and Chiu Yuen Koo and Chuan Yu Foo and Clemens Me Denis M. Baylor and Eric Breck and Heng-Tze Cheng and Jarek Wilkiewicz an Koc and Lukasz Lew and Martin A. Zinkevich and Martin Wicke and Mustafa I Neoklis Polyzotis and Noah Fiedel and Salem Elie Haykal and Steven Whang Roy and Sukriti Ramesh and Vihan Jain and Xin Zhang and Zakaria Haque TF TensorFlow-Based Production-Scale Machine Learning Platform, KDD 2017 ( https://proceedings.neurips.cc/paper/2015/hash/86df7dcfd896fcaf2674f757 -Abstract.html
  6. Model Training 訓練データを用いてモデル を訓練 Model Evaluation 評価データを用いてモデル を評価 評価指標は Accuracy

    など の精度指標 Basic text classification - TensorFlow Core https://www.tensorflow.org/tutorials/keras/text_classification
  7. Don't just Do TFX, Do YOUR MLOps. これまでに紹介したコンポーネントをすべてカバーしようとするのは現 実的でない 直面している課題に対しての解決策として上記のコンポーネントの導入

    を検討する Don't 画像を扱っているのですがデータのバリデーションって何をすれば やったことになりますか? DO 入力が画像で正規化処理を前処理で行うので、ファイルの形式やサ イズなど簡単な検査のみにとどめます
  8. Vertex Pipelines Vertex AI と TFX Vertex Pipelines 3 つの書き方

    Lightweight Python Component Hello, world コンポーネントのつなげかた 複雑なパイプライン
  9. Vertex AI と TFX 設計思想は同一 TFX をクラウドサービスとして 提供しているのが Vertex AI

    MLOps on Vertex AI https://cloud.google.com/vertex-ai/docs/start/introduction- mlops
  10. Vertex Pipelines Vertex AI の機械学習パイプ ラインを実行するためのサ ービス コンテナを立ち上げて、バ ッチ処理し、コンテナを終 了するだけ

    記述には KFP (Kubeflow Pipelines) SDK を用いる MLOps: 機械学習における継続的デリバリーと自動化のパイプライン https://cloud.google.com/architecture/mlops-continuous-delivery-and- automation-pipelines-in-machine-learning
  11. 3 つの書き方 Lightweight Python Components Containerized Python Components Container Components

    第一選択は Lightweight Python Components Kubeflow Pipelines v2 で Pipeline の書き方がかなり変わる件について https://zenn.dev/asei/articles/introduction-to-kfp-v2
  12. Lightweight Python Component 次のような Python の関数を用意 def hello_world(text: str) ->

    str: print(text) return text デコレーターを用いてコンポーネント化 @component(base_image="python:3.9") def hello_world(text: str) -> str: print(text) return text
  13. Hello, world: 全体像 @component(base_image="python:3.9") def hello_world(text: str) -> str: print(text)

    return text @dsl.pipeline( name="intro-pipeline-unique", description="A simple intro pipeline", pipeline_root=PIPELINE_ROOT, ) def pipeline(text: str = "hi there"): hw_task = hello_world(text=text) compiler.Compiler().compile( pipeline_func=pipeline, package_path="intro_pipeline.yaml")
  14. Hello, world: コンポーネントの定義 @component(base_image="python:3.9") def hello_world(text: str) -> str: print(text)

    return text コンポーネントを定義 宣言したコンポーネントはパイプラインのなかで呼ぶ
  15. Hello, world: パイプラインの定義 @dsl.pipeline( name="intro-pipeline-unique", # 名前の指定 description="A simple intro

    pipeline", # 処理内容のコメント pipeline_root="gs://your-ml-bucket", # 結果の保存先 (GCS) ) def pipeline(text: str = "hi there"): # 先程定義したコンポーネント hello_world を呼び出す hw_task = hello_world(text=text) # 返り値は PipelineTask と呼ばれる パイプラインのデコレーターの引数は保存先の指定だけ必要 (あとでも 良い)
  16. Hello, world: パイプラインのコンパイル # コンパイルする compiler.Compiler().compile( pipeline_func=pipeline, package_path="intro_pipeline.yaml" ) Python

    で定義したパイプラインを、Vertex Pipelines にわたすための設 定ファイル (YAML) にコンパイル 生成される intro_pipeline.yaml は pipeline_spec という中間言語 になっている
  17. コンポーネントの繋げ方: パイプラインの定義 @dsl.pipeline( pipeline_root="gs://your-ml-bucket", ) def pipeline(text: str = "hi

    there"): first_task = hello_world(text=text) second_task = hello_world(text=first_task.output) コンポーネントの出力を次のコンポーネントにわたすには、そのまま出 力を渡してあげれば良い
  18. 複雑なパイプライン 実際の構築に当たってはチュー トリアルを見ておくと良い Vertex AI Pipelines: Pipelines introduction for KFP

    Vertex AI Pipelines: Lightweight Python function-based components, and component I/O Vertex AI Pipelines Jupyter notebooks https://cloud.google.com/vertex- ai/docs/pipelines/notebooks