Closed nokoxxx1212 closed 4 months ago
https://tech.timee.co.jp/entry/2023/07/21/114309
# Vertex AI Pipelines開発用のテンプレート
.
├── .github
│ ├── PULL_REQUEST_TEMPLATE.md
│ └── workflows
│ ├── CI/CDのyamlファイル
├── .gitignore
├── Makefile
├── README.md
├── pyproject.toml
├── src
│ └── pipeline_template
│ ├── components
│ │ └── component
│ │ ├── パイプラインを構成するコンポーネントのソースコードとDockerfile
│ ├── pipelines
│ │ ├── パイプラインをコンパイル、実行するためのソースコード
│ ├── pyproject.toml
└── tests
├── テストコード
https://tech.layerx.co.jp/entry/2023/11/16/185944
├── poetry.lock
├── pyproject.toml
├── tasks.py
├── {{ project-name-a }}
│ ├── invoke.yaml
│ ├── invoke_prd.yaml
│ ├── tasks.py
│ ├── yamls
│ │ ├── preprocess.yaml
│ │ ├── train.yaml
│ │ ├── pipelines.yaml
│ └── ...
│ ├── pipelines
│ │ ├── train_pipeline.py
│ │ └── ...
│ ├── components
│ ├── preprocess
│ ├── train
│ └── ...
├── {{ project-name-b }}
├── libs
└── layerx-ml-utils
├── pyproject.toml
└── layerx_ml_utils
├── vertex_pipeline.py
├── bq.py
├── invoke.py
└── ...
├── {{ project-name-a }}
│ ├── pipelines
│ │ ├── sample_pipeline.py
│ │ ├── train_pipeline.py
│ │ └── ...
│ ├── components
│ | ├── sample/
| | | |── Dockerfile
| | | |── pyproject.toml
| | | └── sample.py
│ | ├── preprocess/
│ | ├── train/
│ | └── ...
| ├── tests
├── {{ project-name-b }}
| ├── data
| │ ├── external
| │ ├── raw
| │ ├── interim
| │ └── processed
他 libs notebooks reports とか
->
.
├── .github
│ ├── PULL_REQUEST_TEMPLATE.md
│ └── workflows
│ ├── CI/CDのyamlファイル
├── .gitignore
├── README.md
├── pyproject.toml
├── src
│ └── pipeline_template
│ ├── components
│ │ └── component
│ │ ├── パイプラインを構成するコンポーネントのソースコードとDockerfile
│ ├── pipelines
│ │ ├── パイプラインをコンパイル、実行するためのソースコード
└── tests
├── テストコード
mkdir src/sample
mkdir src/sample/components
mkdir src/sample/components/sample
touch src/sample/components/sample/Dockerfile
touch src/sample/components/sample/sample.py
mkdir src/sample/pipelines
touch src/sample/pipelines/sample_pipeline.py
docker build -t khsampledocker .
docker run -itd -v $(pwd):/opt/mnt khsampledocker
docker exec -it 17ce /bin/bash
> [2/6] COPY ../../../../pyproject.toml ./:
------
failed to compute cache key: "/pyproject.toml" not found: not found
-> > [4/6] RUN poetry config virtualenvs.create false && poetry install --no-root --extras "test lint sample":
if __name__ == '__main__':
results = is_prime()
print(type(results))
clickライブラリを使用してコマンドラインインターフェースを作成すると、通常、コマンド関数(この場合はis_prime)の戻り値は無視されます。その代わり、結果は通常、click.echo()やprint()などの関数を使用して直接出力されます。
したがって、results = is_prime()というコードは、is_prime関数の戻り値をresultsに代入しようとしますが、is_prime関数はclickによってコマンドとして実行され、その結果は出力されますが戻り値としては返されません。そのため、resultsはNoneになります。
外側のコンテナから実行
root@17ce359b7df3:/opt/mnt/src/sample/pipelines# python sample_pipeline.py
Traceback (most recent call last):
File "/opt/mnt/src/sample/pipelines/sample_pipeline.py", line 1, in
-> poetry add google_cloud_pipeline_components --group sample
root@17ce359b7df3:/opt/mnt# poetry add google_cloud_pipeline_components --group sample
For google-cloud-pipeline-components, a possible solution would be to set the `python` property to ">=3.9,<3.12.0"
コピーした方のtomlを修正してしまっていた -> google-cloud-pipeline-componentsパッケージがPython 3.12以降をサポートしていない
Dockerを3.11に
-> from src.sample.components.sample.sample_components import sample ModuleNotFoundError: No module named 'src'
poetry installをもう一度実行(なぜ?)
-> NameError: name 'khsampledocker' is not defined
Googleログイン Google Cloud SDKをインストールします: gcloud init gcloud auth application-default loginコマンドを実行して、新しい認証情報を取得します: gcloud auth application-default login
GCSバケット作成
-> AttributeError: module 'kfp.dsl' has no attribute 'ContainerOp
from google.cloud import aiplatform
from kfp import dsl
from kfp.v2 import compiler
from kfp.v2.dsl import ContainerSpec
# コンポーネントを定義
@dsl.container_component
def sample_component() -> ContainerSpec:
return ContainerSpec(
image='python:3.7',
command=['python', 'sample.py'],
)
# パイプラインを定義
@dsl.pipeline(
name='sample-pipeline',
description='A pipeline that runs the sample.py script.'
)
def sample_pipeline():
# コンポーネントのインスタンスを作成
sample_task = sample_component()
# パイプラインをコンパイル
compiler.Compiler().compile(
pipeline_func=sample_pipeline,
package_path='sample_pipeline_job.json'
)
# パイプラインを実行
def run_pipeline(project: str, location: str, pipeline_root: str):
# Vertex AI clientを初期化
aiplatform.init(project=project, location=location)
# パイプラインを実行
job = aiplatform.PipelineJob(
display_name='sample-pipeline',
template_path='sample_pipeline_job.json',
pipeline_root=pipeline_root,
)
job.run()
# パイプラインを実行するためのパラメータ
PROJECT_ID = 'keiba-hacke'
LOCATION = 'us-central1'
PIPELINE_ROOT = 'gs://dev-kh-gcs-bucket/sample/pipeline_root'
if __name__ == '__main__':
run_pipeline(PROJECT_ID, LOCATION, PIPELINE_ROOT)
PROJECT_ID = 'XXX'
LOCATION = 'us-central1'
PIPELINE_ROOT = 'gs://XXX/sample/pipeline_root'
COPY . /opt/mnt に変更 poetry add python-dotenv --group sample addした後にinstallすることが必要
poetry install --no-root --with test,lint,sampleがエラーになりました dotenvをインストールしたいです • Installing dotenv (0.0.5): Failed ChefBuildError Backend 'setuptools.build_meta:legacy' is not available. Note: This error originates from the build backend, and is likely not a problem with poetry but with dotenv (0.0.5) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "dotenv (==0.0.5)"'.
GitHub Copilot: Google Container Registry(GCR)にDockerイメージをpushするには、以下の手順を実行します。
docker build -t gcr.io/your-project-id/your-image-name .
->
docker build -t gcr.io/your-project-id/khsampledocker .
gcloud
コマンドラインツールを使用して、GCRに認証します。gcloud auth configure-docker
docker push gcr.io/your-project-id/your-image-name
これらのコマンドを実行する前に、Google Cloud SDKがインストールされていること、gcloud
が正しく設定されていること(gcloud init
を実行)、そして適切な権限を持つGCPプロジェクトが存在することを確認してください。
image_uriを変数で渡すのに失敗 TypeError: Components must be instantiated using keyword arguments. Positional parameters are not allowed (found 1 such parameters for component "sample-component").
message: "Failed to create pipeline job. Error: Image gcr.io/keiba-hacke/khsampledocker not found."
"The replica workerpool0-0 exited with a non-zero status of 1. Termination reason: Error. To find out more about why your job exited please check the logs: https://console.cloud.google.com/logs/viewer?project=216392008494&resource=ml_job%2Fjob_id%2F2858859356114386944&advancedFilter=resource.type%3D%22ml_job%22%0Aresource.labels.job_id%3D%222858859356114386944%22"
lsに変えてもエラー exec /usr/bin/ls: exec format error https://github.com/kubeflow/pipelines/issues/8883 Macでビルドしたことが原因?
lsは2分でジョブが完了した
sample.pyは TypeError: Unexpected argument "3" of type <class 'int'>.
command=["python3", "sample.py", "--number", "3"],にした。argsで分けずに
-> 3 is prime も正しく出力されていた
🧑 Story
🔨 Acceptance Criteria
📝 Task List
📚 Resources
🎯 Deliverables
🔜 Remaining Tasks