Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kubeflow Pipelines v2 で変わる機械学習パイプライン開発
Search
Asei Sugiyama
March 20, 2024
Technology
7
1.6k
Kubeflow Pipelines v2 で変わる機械学習パイプライン開発
第39回 MLOps 勉強会の発表資料です
https://mlops.connpass.com/event/312260/
Asei Sugiyama
March 20, 2024
Tweet
Share
More Decks by Asei Sugiyama
See All by Asei Sugiyama
MLOps の現場から
asei
8
870
LLMOps: Eval-Centric を前提としたMLOps
asei
7
620
The Rise of LLMOps
asei
13
2.9k
生成AIの活用パターンと継続的評価
asei
15
2.4k
最近の Citadel AI の取り組みのご紹介 (Nov, 2024)
asei
2
110
仕事で取り組む 生成 AI 時代の対話の品質評価
asei
2
81
MLOps の処方箋ができるまで
asei
3
620
LLM を現場で評価する
asei
5
990
生成 AI の評価方法
asei
8
2.3k
Other Decks in Technology
See All in Technology
RSNA2024振り返り
nanachi
0
580
アジャイル開発とスクラム
araihara
0
170
技術的負債解消の取り組みと専門チームのお話 #技術的負債_Findy
bengo4com
1
1.3k
現場の種を事業の芽にする - エンジニア主導のイノベーションを事業戦略に装着する方法 -
kzkmaeda
2
2.1k
CZII - CryoET Object Identification 参加振り返り・解法共有
tattaka
0
360
関東Kaggler会LT: 人狼コンペとLLM量子化について
nejumi
3
580
Developer Summit 2025 [14-D-1] Yuki Hattori
yuhattor
19
6.2k
スタートアップ1人目QAエンジニアが QAチームを立ち上げ、“個”からチーム、 そして“組織”に成長するまで / How to set up QA team at reiwatravel
mii3king
2
1.5k
レビューを増やしつつ 高評価維持するテクニック
tsuzuki817
1
710
開発組織のための セキュアコーディング研修の始め方
flatt_security
3
2.4k
全文検索+セマンティックランカー+LLMの自然文検索サ−ビスで得られた知見
segavvy
2
100
TAMとre:Capセキュリティ編 〜拡張脅威検出デモを添えて〜
fujiihda
2
240
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
182
22k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.8k
What's in a price? How to price your products and services
michaelherold
244
12k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Building Adaptive Systems
keathley
40
2.4k
YesSQL, Process and Tooling at Scale
rocio
172
14k
A Tale of Four Properties
chriscoyier
158
23k
Automating Front-end Workflow
addyosmani
1368
200k
GraphQLとの向き合い方2022年版
quramy
44
13k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
100
18k
Transcript
Kubeflow Pipelines v2 で変わる 機械学習パイプライン開発 Asei Sugiyama
自己紹介 杉山 阿聖 (@K_Ryuichirou) Software Engineer @ Citadel AI Google
Cloud Innovators Champion @ Cloud AI/ML MLSE 機械学習オペレーション WG 機械学習図鑑 共著 決闘者 @ マスターデュエル
主旨 KFP SDK v2 がリリースされて推奨されるパイプラインの書き方がだい ぶ変わりました KFP SDK v1 の書き方をしたパイプラインもしばらく使えますが、
Vertex Pipelines では2024年12月に EOF を迎えます Fun-in といった新しい機能も使えるようになったので、リリースを確認 し、マイグレーションを計画するとよいでしょう
TOC Basics of Kubeflow Pipelines <- Migration from v1 to
v2
Basics of Kubeflow Pipelines Vertex AI と TFX Vertex Pipelines
3 つの書き方 Lightweight Python Component Hello, world コンポーネントのつなげかた 複雑なパイプライン
TFX, Kubeflow, Vertex AI 設計思想は同一 TFX は Google の機械学習基盤 Kubeflow
は TFX の OSS 版 TFX をクラウドサービスとして 提供しているのが Vertex AI MLOps on Vertex AI https://cloud.google.com/vertex-ai/docs/start/introduction- mlops
Vertex Pipelines Vertex AI の機械学習パイプ ラインを実行するためのサ ービス コンテナを立ち上げて、バ ッチ処理し、コンテナを終 了するだけ
記述には KFP (Kubeflow Pipelines) SDK を用いる MLOps: 機械学習における継続的デリバリーと自動化のパイプライン https://cloud.google.com/architecture/mlops-continuous-delivery-and- automation-pipelines-in-machine-learning
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
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
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")
Hello, world: コンポーネントの定義 @component(base_image="python:3.9") def hello_world(text: str) -> str: print(text)
return text コンポーネントを定義 宣言したコンポーネントはパイプラインのなかで呼ぶ
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 と呼ばれる パイプラインのデコレーターの引数は保存先の指定だけ必要 (あとでも 良い)
Hello, world: パイプラインのコンパイル # コンパイルする compiler.Compiler().compile( pipeline_func=pipeline, package_path="intro_pipeline.yaml" ) Python
で定義したパイプラインを、Vertex Pipelines にわたすための設 定ファイル (YAML) にコンパイル 生成される intro_pipeline.yaml は pipeline_spec という中間言語 になっている
Hello, world: パイプ ラインの実行 YAML ファイルを アップロード パイプラインの名 前や、実行結果の 保存先を指定
Hello, world: 結果 作成したパイプラ インを表示 コンポーネントご とに入出力が表示 される (右下)
コンポーネントの繋げ方: パイプラインの定義 @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) コンポーネントの出力を次のコンポーネントにわたすには、そのまま出 力を渡してあげれば良い
コンポーネントの繋 げ方: 実行結果 実行順から依存関 係が解析され、パ イプラインが定義 される 条件分岐や fun- out,
fun-in も可能
複雑なパイプライン 実際の構築に当たってはチュー トリアルを見ておくと良い 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
TOC Basics of Kubeflow Pipelines Migration from v1 to v2
<-
Migration from v1 to v2 Timeline V1 Component YAML support
Container Op Pythonic artifact syntax Fan-out, Fan-in Containerized Python Components
Timeline Vertex Pipelines における KFP SDK 1.8 のサポートは 2024 年
12 月 20 日に終了 KFP SDK v2 を用いても v1 と同じ記述はできるもの の、warning が発生する Supported frameworks list | Vertex AI | Google Cloud https://cloud.google.com/vertex-ai/docs/supported-frameworks- list#pipelines
V1 Component YAML support 今までは YAML をコンポー ネントの定義のために書い ていた 既存の
YAML ファイルは後 方互換性のためサポートさ れる とはいえ移行を考えたほう が良い Migrate from KFP SDK v1 | Kubeflow https://www.kubeflow.org/docs/components/pipelines/v2/migration/
Container Op docker run のような記述ができるコンポーネント Container Components | Kubeflow https://www.kubeflow.org/docs/components/pipelines/v2/components/container-components/
Pythonic artifact syntax (1/2) これまでは入出力を関数の引数として定義する必要があった @dsl.component(base_image="python:3.10") def id_func(input: Input[int], metric:
Output[Metrics]): Path(metric.path).write_text(str(input)) return metric
Pythonic artifact syntax (1/2) v2 では通常の Python 関数のように出力を返り値として定義可能 @dsl.component(base_image="python:3.10") def
id_func(input: int) -> Metrics: from pathlib import Path metric = Metrics( uri=dsl.get_uri(), metadata={'value':input} ) Path(metric.path).write_text(str(input)) return metric
Fan-out, Fan-in (1/4) このようなコンポーネントを用意 @dsl.component(base_image="python:3.10") def id_func(input: int) -> Metrics:
from pathlib import Path metric = Metrics( uri=dsl.get_uri(), metadata={'value':input} ) Path(metric.path).write_text(str(input)) return metric @dsl.component(base_image="python:3.10") def calc_average(models: list[Metrics]) -> float: return sum([float(model.metadata['value']) for model in models]) / len(models)
Fan-out, Fan-in (2/4) Fan-out のために dsl.ParallelFor を利用 Fan-in のために dsl.Collected
を利用 @dsl.pipeline def fanin_pipeline(): with dsl.ParallelFor( items=[i for i in range(10)], ) as item: id_func_task = id_func(input=item) calc_average(models=dsl.Collected(id_func_task.output))
Fan-out, Fan-in (3/4) コンポーネントには Artifact の list が渡される @dsl.component(base_image="python:3.10") def
calc_average(models: list[Metrics]) -> float: # 略
Fan-out, Fan-in (4/4) パイプラインの実行結果は右の ようになる
Containerized Python Components 今回は時間の都合上割愛 解説を書きました Kubeflow Pipelines v2 で Pipeline
の書き方がかなり変わる件について https://zenn.dev/asei/articles/introduction-to-kfp-v2
Resource Migrate from KFP SDK v1 は必読 LayerX のブログ記事がかな り実践的
Vertex AI Pipelinesを用いて爆速ML開発の仕組みを構築する #LayerXテックア ドカレ - LayerX エンジニアブログ https://tech.layerx.co.jp/entry/2023/11/16/185944
まとめ KFP SDK v2 がリリースされて推奨されるパイプラインの書き方がだい ぶ変わりました KFP SDK v1 の書き方をしたパイプラインもしばらく使えますが、
Vertex Pipelines では2024年12月に EOF を迎えます Fun-in といった新しい機能も使えるようになったので、リリースを確認 し、マイグレーションを計画するとよいでしょう