Contents
1. Vertex AI の概要と 2026 年の位置づけ
| 項目 | 内容 |
|---|---|
| 提供形態 | 完全マネージド型 ML ライフサイクル(データ管理・実験・パイプライン・デプロイ) |
| 主な利点 | - UI と REST/GRPC API が統一 - 同一 SDK で モデル作成 → デプロイ をシームレスに実行 - 従来の AI Platform に比べ、サンプルコードの 行数が約 80 % 短縮(公式ブログに記載)【1】 |
| 2026 年の注目点 | - Vertex AI Pipelines が KFP (Kubeflow Pipelines) と完全互換化 - VPC Service Controls、CMEK 対応が標準装備 - 将来的に対話型エージェント向け機能(Gemini 系)を統合予定【2】 |
2. GCP 環境の構築手順
2.1 プロジェクトと請求アカウントの作成
|
1 2 3 4 5 6 |
# ① プロジェクト作成 gcloud projects create my-vertex-project --name="Vertex AI Project" gcloud config set project my-vertex-project # ② 請求アカウント紐付け(コンソール > 請求 → プロジェクトを選択) |
2.2 必要な API の有効化
|
1 2 3 4 5 6 7 8 |
gcloud services enable \ vertexai.googleapis.com \ cloudbuild.googleapis.com \ artifactregistry.googleapis.com \ storage.googleapis.com \ bigquery.googleapis.com \ alloydb.googleapis.com |
参考:Google Cloud の API 有効化手順【3】
2.3 IAM ロールの最小権限設定
| 役割 | 推奨ロール(現行) | 主な権限 |
|---|---|---|
| Vertex AI 管理者 | roles/aiplatform.admin (旧称 Vertex AI Administrator) |
モデル作成・パイプライン管理 |
| Cloud Build ビルダー | roles/cloudbuild.builds.builder |
ビルド実行、Artifact Registry へのプッシュ |
| ストレージ閲覧者 | roles/storage.objectViewer |
バケット内オブジェクトの読み取り |
| BigQuery データエディタ | roles/bigquery.dataEditor |
テーブルの CRUD |
| AlloyDB クライアント | roles/alloydb.client |
PostgreSQL 接続(IAM 認証) |
サービス アカウント作成例
|
1 2 3 4 5 6 7 8 9 |
gcloud iam service-accounts create vertex-pipeline-sa \ --display-name "Vertex AI Pipeline SA" PROJECT_ID=$(gcloud config get-value project) gcloud projects add-iam-policy-binding $PROJECT_ID \ --member="serviceAccount:vertex-pipeline-sa@$PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/aiplatform.admin" |
ベストプラクティス:ロールはリソース単位で付与し、不要な権限は削除する【4】
3. データソースとの統合(Cloud Storage・BigQuery・AlloyDB)
3.1 Cloud Storage からのデータ取得
|
1 2 3 4 5 6 7 8 9 |
from google.cloud import storage def download_blob(bucket_name: str, src: str, dst_path: str): client = storage.Client() bucket = client.bucket(bucket_name) blob = bucket.blob(src) blob.download_to_filename(dst_path) print(f"✅ {src} → {dst_path}") |
3.2 BigQuery テーブルの直接読み込み
|
1 2 3 4 5 6 7 8 9 10 |
from google.cloud import bigquery def query_bq(sql: str): client = bigquery.Client() df = client.query(sql).to_dataframe() return df # 使用例 df = query_bq("SELECT * FROM `my_dataset.training_data` LIMIT 1000") |
3.3 AlloyDB (PostgreSQL) への接続
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import psycopg2, os def alloydb_conn(): # サービス アカウントキーは環境変数で指定 os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/sa-key.json" return psycopg2.connect( host="my-alloydb-instance.region.googleapis.com", port=5432, dbname="mydb", user="postgres", # IAM 認証有効時は同名ユーザー sslmode="require" ) |
3.4 チェックリスト
- [ ] Cloud Storage バケットに Object Viewer 権限を付与
- [ ] BigQuery データセットへパイプライン SA に
bigquery.dataEditorを付与 - [ ] AlloyDB インスタンスで IAM 認証と
roles/alloydb.clientロールを有効化【5】 - [ ] 使用 SDK のバージョンは最新(例:
google-cloud-storage>=2.15,google-cloud-bigquery>=3.12,psycopg2-binary>=2.9)
4. Vertex AI Pipelines と CI/CD の実装
4.1 Python SDK でパイプラインを定義(簡易例)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# pipeline.py from kfp import dsl, components import google.cloud.aiplatform as aiplatform @components.create_component_from_func def preprocess_op(input_path: str, output_path: str): # 実装は省略 ... @components.create_component_from_func def train_model_op(train_data: str, model_dir: str): # 実装は省略 ... @dsl.pipeline(name="vertex-ml-pipeline") def ml_pipeline(bucket: str): pre = preprocess_op( input_path=f"gs://{bucket}/raw/", output_path=f"gs://{bucket}/processed/" ) train = train_model_op( train_data=pre.output, model_dir=f"gs://{bucket}/model/" ) if __name__ == "__main__": aiplatform.init(project="my-vertex-project", location="us-central1") from kfp import compiler compiler.Compiler().compile(pipeline_func=ml_pipeline, package_path="pipeline.yaml") |
pipeline.yamlが Vertex AI Pipelines 用の KFP 互換テンプレートになります【6】
4.2 Cloud Build による CI/CD パイプライン
cloudbuild.yaml(抜粋)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
steps: - name: 'gcr.io/cloud-builders/docker' args: ['build', '-t', 'us-central1-docker.pkg.dev/$PROJECT_ID/vertex-pipeline/pipeline-image', '.'] dir: 'pipeline' # Dockerfile が格納されているディレクトリ - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' entrypoint: 'bash' args: - '-c' - | docker push us-central1-docker.pkg.dev/$PROJECT_ID/vertex-pipeline/pipeline-image gcloud ai pipelines run \ --project=$PROJECT_ID \ --region=us-central1 \ --display-name="CI/CD Run $(date +%s)" \ --pipeline-file=pipeline.yaml \ --parameter-values=bucket=my-data-bucket images: - 'us-central1-docker.pkg.dev/$PROJECT_ID/vertex-pipeline/pipeline-image' |
CI/CD 実装時のポイント
| 項目 | 推奨設定 |
|---|---|
| Artifact Registry アクセス権 | roles/artifactregistry.writer をビルド SA に付与 |
| パイプライン実行権限 | roles/aiplatform.admin または roles/aiplatform.user |
| ビルド環境変数 | $PROJECT_ID, $REGION は Cloud Build の置換変数を使用 |
| 通知 | Cloud Build の 通知 機能で Slack / Email に結果を送信(任意) |
5. デプロイ・運用:エンドポイント作成、モニタリング、セキュリティ
5.1 エンドポイントの作成とモデルデプロイ
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
from google.cloud import aiplatform def deploy(model_resource: str, endpoint_name: str): aiplatform.init(project="my-vertex-project", location="us-central1") model = aiplatform.Model(model_name=model_resource) endpoint = model.deploy( machine_type="n1-standard-4", min_replica_count=0, # アイドル時は自動スケールダウン max_replica_count=5, traffic_split={"0": 100}, deployed_model_display_name=endpoint_name, ) print(f"✅ Endpoint: {endpoint.resource_name}") return endpoint # 実行例 endpoint = deploy( model_resource="projects/my-vertex-project/locations/us-central1/models/1234567890123456789", endpoint_name="customer-churn-predictor" ) |
5.2 オンライン予測の呼び出し
|
1 2 3 4 5 6 7 8 9 10 |
def predict(endpoint, instances): resp = endpoint.predict(instances=instances) return resp.predictions result = predict( endpoint, [{"age": 35, "income": 72000, "usage_months": 12}] ) print("🔎 Prediction:", result) |
5.3 モニタリング・アラート設定
| メトリクス | 推奨閾値(例) |
|---|---|
aiplatform.googleapis.com/prediction/latency (秒) |
> 0.5 秒 → アラート |
aiplatform.googleapis.com/prediction/request_count |
前日比 +30 % 以上の急増 |
cpu/utilization(エンドポイント VM) |
> 80 % が 5 分以上続く |
Alert Policy (YAML)
|
1 2 3 4 5 6 7 8 |
displayName: "Vertex AI High Latency" combinationRule: conditionThreshold: filter: 'metric.type="aiplatform.googleapis.com/prediction/latency" AND resource.type="vertex_ai_endpoint"' comparison: COMPARISON_GT thresholdValue: 0.5 # 秒単位(500 ms) duration: 300s # 5 分間継続 |
詳細は Cloud Monitoring の公式ガイドをご参照ください【7】
5.4 セキュリティ・コスト最適化チェックリスト
- IAM:エンドポイントへのアクセスは
roles/aiplatform.endpointUserのみ付与し、必要に応じて VPC Service Controls でネットワーク制限 - 暗号化:Cloud Storage / BigQuery は顧客管理キー(CMEK)を有効化【8】
- プライベート接続:Private Service Connect により VPC 内からのみエンドポイントにアクセス
- スケーリング:
min_replica_count=0でアイドル時は自動停止 → コスト削減 - ログ保持:Cloud Logging の保存期間を 30 日に設定し、不要な長期保管を回避
- 予算アラート:Billing の予算機能で月間上限の 80 % に達したらメール/Slack 通知
6. 参考文献(リンク先はすべて公式ドキュメント)
| 番号 | タイトル / 内容 | URL |
|---|---|---|
| [1] | 「Vertex AI が UI と API を統一、コード量が約 80 % 短縮」ブログ記事(Google Cloud Official Blog) | https://cloud.google.com/blog/products/ai-platform/vertex-ai-unifies-ui-and-api |
| [2] | 2026 年の Google I/O 発表スライド(Gemini 系機能は「検討中」) | https://events.google.com/io/ |
| [3] | API 有効化手順(gcloud コマンド) | https://cloud.google.com/endpoints/docs/openapi/enable-api |
| [4] | IAM の最小権限ベストプラクティス | https://cloud.google.com/iam/docs/best-practices |
| [5] | AlloyDB for PostgreSQL – IAM 認証とロール設定 | https://cloud.google.com/alloydb/docs/authentication |
| [6] | Vertex AI Pipelines の KFP 互換性ガイド | https://cloud.google.com/vertex-ai/docs/pipelines/kfp-compatibility |
| [7] | Cloud Monitoring – カスタムアラートポリシー作成方法 | https://cloud.google.com/monitoring/alerts/concepts-indepth |
| [8] | Customer‑Managed Encryption Keys (CMEK) の設定手順 | https://cloud.google.com/kms/docs/cmek |
まとめ
- Vertex AI は 2026 年においても、データ取得からモデルデプロイまでを単一プラットフォームで完結できる唯一のマネージドサービスです。
- 最小権限 IAM と API 有効化 を正しく行うことで、セキュアかつスケーラブルな開発基盤がすぐに構築できます。
- データソース(Storage・BigQuery・AlloyDB) は公式 SDK が直接利用でき、パイプライン内で統一的に扱える点が大きな利点です。
- CI/CD には Cloud Build + Artifact Registry の組み合わせを採用し、
pipeline.yamlを自動生成してコード変更から本番デプロイまでを完全自動化します。 - 運用フェーズ ではエンドポイントのモニタリングと IAM/ネットワーク制御を徹底し、コストはスケーリング設定で最適化できます。
この手順に沿って環境を整備すれば、2026 年でも最新のベストプラクティスに則った 安全・高速・コスト効率的 な機械学習システムを構築できるでしょう。