最近、XGBoost を使用して、オンライン サービングに使用する Python モデルをトレーニングしました。モデル予測サービスは、Google Kubemetes Engine (GKE) クラスタで実行されている Golang で実装されたバックエンド サービスによって呼び出されます。モデルには前処理と後処理の手順が必要です。処理手順は、サービング時に実行されるように実装する必要があります。コードの変更とインフラストラクチャのメンテナンスを最小限に抑え、できるだけ早くモデルを本番環境にデプロイしたいと考えています。どうすればよいでしょうか。
正解: C
処理手順を実装してサービス提供時に実行し、コードの変更とインフラストラクチャのメンテナンスを最小限に抑え、モデルをできるだけ早く本番環境にデプロイするための最適なオプションは、Predictor インターフェースを使用してカスタム予測ルーチンを実装することです。カスタム コンテナを構築し、コンテナを Vertex AI Model Registry にアップロードして、Vertex AI エンドポイントにデプロイします。このオプションを使用すると、Vertex AI のパワーとシンプルさを活用して、最小限の労力とカスタマイズで XGBoost モデルを提供できます。Vertex AI は、Google Cloud で機械学習ソリューションを構築およびデプロイするための統合プラットフォームです。Vertex AI は、トレーニング済みの XGBoost モデルをオンライン予測エンドポイントにデプロイして、個々のインスタンスに対して低レイテンシの予測を提供できます。カスタム予測ルーチン (CPR) は、入力データの前処理、予測の実行、出力データの後処理のロジックを定義する Python スクリプトです。CPR を使用すると、モデルの予測動作をカスタマイズし、複雑なデータ形式や標準以外のデータ形式を処理できます。また、CPR を使用すると、予測ロジックを実装するためにいくつかの関数を記述するだけで済むため、コードの変更を最小限に抑えることができます。 Predictor インターフェースは、基本クラス aiplatform.Predictor から継承され、抽象メソッド predict() と preprocess() を実装するクラスです。Predictor インターフェースは、モデルの前処理と予測ロジックを定義することで CPR を作成するのに役立ちます。コンテナ イメージは、モデル、CPR、および依存関係を含むパッケージです。コンテナ イメージを使用すると、コンテナ イメージを Vertex AI Model Registry にアップロードして Vertex AI Endpoints にデプロイするだけで済むため、デプロイ プロセスを標準化して簡素化できます。Predictor インターフェースを使用して CPR を実装し、カスタム コンテナを構築して、コンテナを Vertex AI Model Registry にアップロードし、Vertex AI エンドポイントにデプロイすることで、処理手順を実装してサービス提供時に実行できるようにし、コードの変更とインフラストラクチャのメンテナンスを最小限に抑え、モデルをできるだけ早く本番環境にデプロイできます1。
他のオプションは、次の理由によりオプション C ほど優れていません。
オプション A: FastAPI を使用して HTTP サーバーを実装し、HTTP サーバーを実行する Docker イメージを作成して、組織の GKE クラスタにデプロイするには、Predictor インターフェースを使用して CPR を実装し、カスタム コンテナを構築し、コンテナを Vertex AI Model Registry にアップロードして、Vertex AI エンドポイントにデプロイするよりも多くのスキルと手順が必要です。FastAPI は、Python でウェブ アプリケーションと API を構築するためのフレームワークです。FastAPI を使用すると、予測リクエストとレスポンスを処理し、データの前処理と後処理を実行できる HTTP サーバーを実装できます。Docker イメージは、モデル、HTTP サーバー、依存関係を含むパッケージです。Docker イメージは、Docker イメージをビルドして実行するだけなので、デプロイ プロセスを標準化して簡素化できます。GKE は、Google Cloud で Kubernetes クラスタを作成および管理できるサービスです。GKE を使用すると、Google Cloud で Docker イメージをデプロイおよびスケーリングし、高可用性とパフォーマンスを実現できます。ただし、FastAPI を使用して HTTP サーバーを実装し、HTTP サーバーを実行する Docker イメージを作成して組織の GKE クラスタにデプロイするには、Predictor インターフェースを使用して CPR を実装し、カスタム コンテナを構築し、コンテナを Vertex AI Model Registry にアップロードして Vertex AI エンドポイントにデプロイするよりも多くのスキルと手順が必要になります。コードの記述、HTTP サーバーの作成と構成、Docker イメージの構築とテスト、GKE クラスタの作成と管理、Docker イメージのデプロイとモニタリングが必要になります。さらに、このオプションでは、Google Cloud サービスとネイティブに統合されたオンライン予測を提供できる Vertex AI のパワーとシンプルさを活用できません2。
オプション B: FastAPI を使用して HTTP サーバーを実装し、HTTP サーバーを実行する Docker イメージを作成し、そのイメージを Vertex AI Model Registry にアップロードして Vertex AI エンドポイントにデプロイするには、Predictor インターフェースを使用して CPR を実装し、カスタム コンテナを構築し、そのコンテナを Vertex AI Model Registry にアップロードして Vertex AI エンドポイントにデプロイするよりも多くのスキルと手順が必要になります。FastAPI は、Python でウェブ アプリケーションと API を構築するためのフレームワークです。FastAPI を使用すると、予測リクエストとレスポンスを処理し、データの前処理と後処理を実行できる HTTP サーバーを実装できます。Docker イメージは、モデル、HTTP サーバー、依存関係を含むパッケージです。Docker イメージは、Docker イメージを構築して実行するだけなので、デプロイ プロセスを標準化して簡素化できます。Vertex AI Model Registry は、Google Cloud で機械学習モデルを保存および管理できるサービスです。Vertex AI Model Registry を使用すると、Docker イメージをアップロードして整理し、モデルのバージョンとメタデータを追跡できます。 Vertex AI Endpoints は、Google Cloud 上の機械学習モデルのオンライン予測を提供できるサービスです。Vertex AI Endpoints を使用すると、Docker イメージをオンライン予測エンドポイントにデプロイして、個々のインスタンスの低レイテンシ予測を提供できます。ただし、FastAPI を使用して HTTP サーバーを実装し、HTTP サーバーを実行する Docker イメージを作成し、そのイメージを Vertex AI Model Registry にアップロードして Vertex AI エンドポイントにデプロイするには、Predictor インターフェースを使用して CPR を実装し、カスタム コンテナを構築し、そのコンテナを Vertex AI Model Registry にアップロードして Vertex AI エンドポイントにデプロイするよりも多くのスキルと手順が必要になります。コードを記述し、HTTP サーバーを作成して構成し、Docker イメージを構築してテストし、その Docker イメージを Vertex AI Model Registry にアップロードして、その Docker イメージを Vertex AI Endpoints にデプロイする必要があります。さらに、このオプションでは、Google Cloud サービスとネイティブに統合されたオンライン予測を提供できる Vertex AI のパワーとシンプルさを活用できません2。
Option D: Using the XGBoost prebuilt serving container when importing the trained model into Vertex AI, deploying the model to a Vertex AI endpoint, working with the backend engineers to implement the pre- and postprocessing steps in the Golang backend service would not allow you to implement the processing steps so that they run at serving time, and could increase the code changes and infrastructure maintenance. A XGBoost prebuilt serving container is a container image that is provided by Google Cloud, and contains the XGBoost framework and the dependencies. A XGBoost prebuilt serving container can help you deploy a XGBoost model without writing any code, but it also limits your customization options. A XGBoost prebuilt serving container can only handle standard data formats, such as JSON or CSV, and cannot perform any preprocessing or postprocessing on the input or output data. If your input data requires any transformation or normalization before running the prediction, you cannot use a XGBoost prebuilt serving container. A Golang backend service is a service that is implemented in Golang, a programming language that can be used for web development and system programming. A Golang backend service can help you handle the prediction requests and responses from the frontend, and communicate with the Vertex AI endpoint. However, using the XGBoost prebuilt serving container when importing the trained model into Vertex AI, deploying the model to a Vertex AI endpoint, working with the backend engineers to implement the pre- and postprocessing steps in the Golang backend service would not allow you to implement the processing steps so that they run at serving time, and could increase the code changes and infrastructure maintenance. You would need to write code, import the trained model into Vertex AI, deploy the model to a Vertex AI endpoint, implement the pre- and postprocessing steps in the Golang backend service, and test and monitor the Golang backend service. Moreover, this option would not leverage the power and simplicity of Vertex AI, which can provide online prediction natively integrated with Google Cloud services2.
Reference:
Preparing for Google Cloud Certification: Machine Learning Engineer, Course 3: Production ML Systems, Week 2: Serving ML Predictions Google Cloud Professional Machine Learning Engineer Exam Guide, Section 3: Scaling ML models in production, 3.1 Deploying ML models to production Official Google Cloud Certified Professional Machine Learning Engineer Study Guide, Chapter 6: Production ML Systems, Section 6.2: Serving ML Predictions Custom prediction routines Using pre-built containers for prediction Using custom containers for prediction