sakamomo554101 / study

勉強用のリポジトリ(記事とかのリンクを貼ったりしていく)
0 stars 0 forks source link

VertexAIのサンプルコードを理解してみる #14

Open sakamomo554101 opened 2 years ago

sakamomo554101 commented 2 years ago

https://github.com/GoogleCloudPlatform/vertex-ai-samples 上記からピックアップ(構造化データで良いかな)

sakamomo554101 commented 2 years ago

https://github.com/reproio/lab_sample_pipelines 上記も参考になりそう

sakamomo554101 commented 2 years ago

reproのサンプルを見ている。

pipeline構築について

各オペレーター(パイプラインの要素)ごとにDockerコンテナが作れるように独立した構成となっている。 オペレーターは下記。

それぞれのOpのコードは別途読むとして、パイプライン(今回はKubeflowを採用)のオペレーター定義は、 yamlでやっている模様。

例えば、trainerだと下記。 https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/components/trainer/src/trainer.yaml

上記のyamlを下記のパイプライン構築時のオペレーター作成時に読み込んでいる。 https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/pipeline.py#L78-L84

ちなみに、kfp.components.load_component_from_textはkfpのAPIとなっている。 https://www.kubeflow.org/docs/components/pipelines/sdk/component-development/

sakamomo554101 commented 2 years ago

https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/pipeline.py#L22-L27

なるほど、上記でyamlの出力ファイルのキーを設定しておいて、各オペレーターに渡す入力値(直前やその前のオペレーターの出力値を入力とするため)を指定する際に使っているのか。

sakamomo554101 commented 2 years ago

ローカルでVertexAIの各オペレーターをデバッグする際のベストプラクティスはないのだろうか。 ※ReproのサンプルはDockerコンテナ化をそれぞれのオペレーターでできるようにし、デバッグしやすくするイメージかと思う。

sakamomo554101 commented 2 years ago

https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/DEPLOYMENT.md パイプライン全体をデプロイする手順がまとまっているが、これでいけるのか? ※ローカルで全部セットアップが完結する?(ローカルで作業して、GCP上(VertexAI上)で処理が実行される?)

sakamomo554101 commented 2 years ago

https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/pipeline.py#L109-L135 上記見ると、パイプラインとしては、推論エンドポイントの作成まではなさそう。 ※deploy処理がないため。

下記のcompile処理でVertexAI上にパイプライン自体は構築される? https://www.kubeflow.org/docs/components/pipelines/sdk/build-pipeline/ https://kubeflow-pipelines.readthedocs.io/en/latest/source/kfp.compiler.html

sakamomo554101 commented 2 years ago

https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/DEPLOYMENT.md#compile-pipeline-python-dsl dsl-compileとは?

sakamomo554101 commented 2 years ago

https://www.kubeflow.org/docs/components/pipelines/sdk/install-sdk/ kubeflow SDKを入れる際に付属されているコマンドっぽい。 パイプラインを作る際に用いると思うが・・

sakamomo554101 commented 2 years ago

https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/deploy_all_component.sh 上記は各オペレーターのdockerイメージをGCRにあげるスクリプト。

sakamomo554101 commented 2 years ago

うーむ、、パイプラインのjsonを作った後に、下記の処理がどこにあるかが不明。

sakamomo554101 commented 2 years ago

例えば、GoogleのVertexAIのサンプルコードだと、以下のようなPipelineを実行する処理が入っているが、 ReproのサンプルだとPipelineを実行する処理がないように見える。

https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/pipelines/google_cloud_pipeline_components_automl_tabular.ipynb


## 下記でパイプラインをjsonやyamlに書き込む

from kfp.v2 import compiler  # noqa: F811

compiler.Compiler().compile(
    pipeline_func=pipeline,
    package_path="tabular regression_pipeline.json".replace(" ", "_"),
)

## 下記でパイプラインの実行処理を行う。

DISPLAY_NAME = "cal_housing_" + TIMESTAMP

job = aip.PipelineJob(
    display_name=DISPLAY_NAME,
    template_path="tabular regression_pipeline.json".replace(" ", "_"),
    pipeline_root=PIPELINE_ROOT,
)

job.run()
sakamomo554101 commented 2 years ago

https://www.kubeflow.org/docs/components/pipelines/reference/component-spec/#example-of-a-component-specification

なるほど。 上記のようにパイプラインの各オペレーターをyamlで定義するが、その際にimplementationにDocker ImageのURLを書くことが可能。

下記では、tagged_nameを書き換えて、Docker ImageのURLを指定している。 https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/pipeline.py#L45-L52

sakamomo554101 commented 2 years ago

Trainerについて調査する。

https://github.com/reproio/lab_sample_pipelines/blob/cf39b2c682d6ab7ec862a76203866ad211bf92fa/kfp/components/trainer/src/trainer.py#L100-L111

上記でnumpyのAPiを利用して、読み込んでいる

sakamomo554101 commented 2 years ago

pythonでVertexAI(ai platform)のSDKを使う場合は、下記のようにインストールすれば良さそう。 https://pypi.org/project/google-cloud-aiplatform/