Anda harus men-deploy model ke endpoint sebelum Anda dapat menggunakan model tersebut untuk menyajikan prediksi online. Men-deploy model akan mengaitkan resource fisik untuk menayangkan prediksi online dengan latensi rendah.
Halaman ini menjelaskan langkah-langkah yang harus Anda ikuti untuk men-deploy model ke endpoint menggunakan Prediksi Online.
Sebelum memulai
Sebelum men-deploy model ke endpoint, ekspor artefak model untuk prediksi dan pastikan Anda memenuhi semua prasyarat dari halaman tersebut.
Membuat kumpulan resource
Dengan resource kustom ResourcePool
, Anda dapat mengontrol perilaku model secara terperinci. Anda dapat menentukan setelan seperti berikut:
- Konfigurasi penskalaan otomatis.
- Jenis mesin, yang menentukan persyaratan CPU dan memori.
- Opsi akselerator seperti resource GPU.
Jenis mesin sangat penting untuk permintaan spesifikasi node pool yang Anda kirim untuk membuat cluster prediksi.
Untuk pool resource model yang di-deploy, jumlah dan jenis akselerator
menentukan penggunaan GPU. Jenis mesin hanya menentukan resource CPU dan memori yang diminta. Oleh karena itu, saat menyertakan akselerator GPU dalam spesifikasi
ResourcePool
, kolom machineType
mengontrol persyaratan CPU dan
memori untuk model, sedangkan kolom acceleratorType
mengontrol
GPU. Selain itu, kolom acceleratorCount
mengontrol jumlah slice GPU.
Ikuti langkah-langkah berikut untuk membuat resource kustom ResourcePool
:
Buat file YAML yang menentukan resource kustom
ResourcePool
. Contoh berikut berisi file YAML untuk kumpulan resource dengan akselerator GPU (model berbasis GPU) dan tanpa akselerator GPU (model berbasis CPU):Model berbasis GPU
apiVersion: prediction.aiplatform.gdc.goog/v1 kind: ResourcePool metadata: name: RESOURCE_POOL_NAME namespace: PROJECT_NAMESPACE spec: resourcePoolID: RESOURCE_POOL_NAME enableContainerLogging: false dedicatedResources: machineSpec: # The system adds computing overhead to the nodes for mandatory components. # Choose a machineType value that allocates fewer CPU and memory resources # than those used by the nodes in the prediction cluster. machineType: a2-highgpu-1g-gdc acceleratorType: nvidia-a100-80gb # The accelerator count is a slice of the requested virtualized GPUs. # The value corresponds to one-seventh of 80 GB of GPUs for each count. acceleratorCount: 2 autoscaling: minReplica: 2 maxReplica: 10
Model berbasis CPU
apiVersion: prediction.aiplatform.gdc.goog/v1 kind: ResourcePool metadata: name: RESOURCE_POOL_NAME namespace: PROJECT_NAMESPACE spec: resourcePoolID: RESOURCE_POOL_NAME enableContainerLogging: false dedicatedResources: machineSpec: # The system adds computing overhead to the nodes for mandatory components. # Choose a machineType value that allocates fewer CPU and memory resources # than those used by the nodes in the prediction cluster. machineType: n2-highcpu-8-gdc autoscaling: minReplica: 2 maxReplica: 10
Ganti kode berikut:
RESOURCE_POOL_NAME
: nama yang ingin Anda berikan ke file definisiResourcePool
.PROJECT_NAMESPACE
: nama namespace project yang terkait dengan cluster prediksi.
Ubah nilai di kolom
dedicatedResources
sesuai dengan kebutuhan resource Anda dan ketersediaan di cluster prediksi.Terapkan file definisi
ResourcePool
ke cluster prediksi:kubectl --kubeconfig PREDICTION_CLUSTER_KUBECONFIG apply -f RESOURCE_POOL_NAME.yaml
Ganti kode berikut:
PREDICTION_CLUSTER_KUBECONFIG
: jalur ke file kubeconfig di cluster prediksi.RESOURCE_POOL_NAME
: nama file definisiResourcePool
.
Saat Anda membuat resource kustom ResourcePool
, Kubernetes API dan layanan webhook akan memvalidasi file YAML dan melaporkan keberhasilan atau kegagalan. Operator prediksi menyediakan dan mencadangkan resource Anda dari kumpulan resource saat Anda men-deploy model ke endpoint.
Men-deploy model ke endpoint
Jika memiliki kumpulan resource, Anda dapat men-deploy lebih dari satu model ke satu endpoint, dan Anda dapat men-deploy model ke lebih dari satu endpoint. Men-deploy model prediksi yang menargetkan container yang didukung. Bergantung pada apakah endpoint sudah ada atau belum, pilih salah satu dari dua metode berikut:
Men-deploy model ke endpoint baru
Ikuti langkah-langkah berikut untuk men-deploy model prediksi ke endpoint baru:
Buat file YAML yang menentukan resource kustom
DeployedModel
:TensorFlow
File YAML berikut menunjukkan contoh konfigurasi untuk model TensorFlow:
apiVersion: prediction.aiplatform.gdc.goog/v1 kind: DeployedModel metadata: name: DEPLOYED_MODEL_NAME namespace: PROJECT_NAMESPACE spec: # The endpoint path structure is endpoints/<endpoint-id> endpointPath: endpoints/PREDICTION_ENDPOINT modelSpec: # The artifactLocation field must be the s3 path to the folder that # contains the various model versions. # For example, s3://my-prediction-bucket/tensorflow artifactLocation: s3://PATH_TO_MODEL # The value in the id field must be unique to each model. id: img-detection-model modelDisplayName: my_img_detection_model # The model resource name structure is models/<model-id>/<model-version-id> modelResourceName: models/img-detection-model/1 # The model version ID must match the name of the first folder in # the artifactLocation bucket, inside the 'tensorflow' folder. # For example, if the bucket path is # s3://my-prediction-bucket/tensorflow/1/, # then the value for the model version ID is "1". modelVersionID: "1" modelContainerSpec: args: - --model_config_file=/models/models.config - --rest_api_port=8080 - --port=8500 - --file_system_poll_wait_seconds=30 - --model_config_file_poll_wait_seconds=30 command: - /bin/tensorflow_model_server # The image URI field must contain one of the following values: # For CPU-based models: gcr.io/aiml/prediction/containers/tf2-cpu.2-14:latest # For GPU-based models: gcr.io/aiml/prediction/containers/tf2-gpu.2-14:latest imageURI: gcr.io/aiml/prediction/containers/tf2-gpu.2-14:latest ports: - 8080 grpcPorts: - 8500 resourcePoolRef: kind: ResourcePool name: RESOURCE_POOL_NAME namespace: PROJECT_NAMESPACE
Ganti kode berikut:
DEPLOYED_MODEL_NAME
: nama yang ingin Anda berikan ke file definisiDeployedModel
.PROJECT_NAMESPACE
: nama namespace project yang terkait dengan cluster prediksi.PREDICTION_ENDPOINT
: nama yang ingin Anda berikan ke endpoint baru, sepertimy-img-prediction-endpoint
.PATH_TO_MODEL
: jalur ke model Anda di bucket penyimpanan.RESOURCE_POOL_NAME
: nama yang Anda berikan ke file definisiResourcePool
saat Anda membuat kumpulan resource untuk menghosting model.
Ubah nilai di kolom yang tersisa sesuai dengan model prediksi Anda.
PyTorch
File YAML berikut menunjukkan contoh konfigurasi untuk model PyTorch:
apiVersion: prediction.aiplatform.gdc.goog/v1 kind: DeployedModel metadata: name: DEPLOYED_MODEL_NAME namespace: PROJECT_NAMESPACE spec: endpointPath: PREDICTION_ENDPOINT endpointInfo: id: PREDICTION_ENDPOINT modelSpec: # The artifactLocation field must be the s3 path to the folder that # contains the various model versions. # For example, s3://my-prediction-bucket/pytorch artifactLocation: s3://PATH_TO_MODEL # The value in the id field must be unique to each model. id: "pytorch" modelDisplayName: my-pytorch-model # The model resource name structure is models/<model-id>/<model-version-id> modelResourceName: models/pytorch/1 modelVersionID: "1" modelContainerSpec: # The image URI field must contain one of the following values: # For CPU-based models: gcr.io/aiml/prediction/containers/pytorch-cpu.2-4:latest # For GPU-based models: gcr.io/aiml/prediction/containers/pytorch-gpu.2-4:latest imageURI: gcr.io/aiml/prediction/containers/pytorch-cpu.2-4:latest ports: - 8080 grpcPorts: - 7070 sharesResourcePool: false resourcePoolRef: kind: ResourcePool name: RESOURCE_POOL_NAME namespace: PROJECT_NAMESPACE
Ganti kode berikut:
DEPLOYED_MODEL_NAME
: nama yang ingin Anda berikan ke file definisiDeployedModel
.PROJECT_NAMESPACE
: nama namespace project yang terkait dengan cluster prediksi.PREDICTION_ENDPOINT
: nama yang ingin Anda berikan ke endpoint baru, sepertimy-img-prediction-endpoint
.PATH_TO_MODEL
: jalur ke model Anda di bucket penyimpanan.RESOURCE_POOL_NAME
: nama yang Anda berikan ke file definisiResourcePool
saat Anda membuat kumpulan resource untuk menghosting model.
Ubah nilai di kolom yang tersisa sesuai dengan model prediksi Anda.
Terapkan file definisi
DeployedModel
ke cluster prediksi:kubectl --kubeconfig PREDICTION_CLUSTER_KUBECONFIG apply -f DEPLOYED_MODEL_NAME.yaml
Ganti kode berikut:
PREDICTION_CLUSTER_KUBECONFIG
: jalur ke file kubeconfig di cluster prediksi.DEPLOYED_MODEL_NAME
: nama file definisiDeployedModel
.
Saat Anda membuat resource kustom
DeployedModel
, Kubernetes API dan layanan webhook akan memvalidasi file YAML dan melaporkan keberhasilan atau kegagalan. Operator prediksi merekonsiliasi resource kustomDeployedModel
dan menayangkannya di cluster prediksi.Buat file YAML yang menentukan resource kustom
Endpoint
.File YAML berikut menunjukkan contoh konfigurasi:
apiVersion: aiplatform.gdc.goog/v1 kind: Endpoint metadata: name: ENDPOINT_NAME namespace: PROJECT_NAMESPACE spec: createDns: true id: PREDICTION_ENDPOINT destinations: - serviceRef: kind: DeployedModel name: DEPLOYED_MODEL_NAME namespace: PROJECT_NAMESPACE trafficPercentage: 50 grpcPort: 8501 httpPort: 8081 - serviceRef: kind: DeployedModel name: DEPLOYED_MODEL_NAME_2 namespace: PROJECT_NAMESPACE trafficPercentage: 50 grpcPort: 8501 httpPort: 8081
Ganti kode berikut:
ENDPOINT_NAME
: nama yang ingin Anda berikan ke file definisiEndpoint
.PROJECT_NAMESPACE
: nama namespace project yang terkait dengan cluster prediksi.PREDICTION_ENDPOINT
: nama endpoint baru. Anda menentukan nama ini di file definisiDeployedModel
.DEPLOYED_MODEL_NAME
: nama yang Anda berikan ke file definisiDeployedModel
.
Anda dapat memiliki satu atau beberapa tujuan
serviceRef
. Jika Anda memiliki objekserviceRef
kedua, tambahkan ke file YAML di kolomdestinations
dan gantiDEPLOYED_MODEL_NAME_2
dengan nama yang Anda berikan ke file definisiDeployedModel
kedua yang Anda buat. Terus tambahkan atau hapus objekserviceRef
sesuai kebutuhan, bergantung pada jumlah model yang Anda deploy.Tetapkan kolom
trafficPercentage
berdasarkan cara Anda ingin membagi traffic di antara model pada endpoint ini. Ubah nilai di kolom lainnya sesuai dengan konfigurasi endpoint Anda.Terapkan file definisi
Endpoint
ke cluster prediksi:kubectl --kubeconfig PREDICTION_CLUSTER_KUBECONFIG apply -f ENDPOINT_NAME.yaml
Ganti
ENDPOINT_NAME
dengan nama file definisiEndpoint
.
Untuk mendapatkan jalur URL endpoint untuk model prediksi, jalankan perintah berikut:
kubectl --kubeconfig PREDICTION_CLUSTER_KUBECONFIG get endpoint PREDICTION_ENDPOINT -n PROJECT_NAMESPACE -o jsonpath='{.status.endpointFQDN}'
Ganti kode berikut:
PREDICTION_CLUSTER_KUBECONFIG
: jalur ke file kubeconfig di cluster prediksi.PREDICTION_ENDPOINT
: nama endpoint baru.PROJECT_NAMESPACE
: nama namespace project prediksi.
Men-deploy model ke endpoint yang sudah ada
Anda hanya dapat men-deploy model ke endpoint yang sudah ada jika sebelumnya Anda men-deploy model lain ke endpoint tersebut saat endpoint itu baru. Sistem memerlukan langkah sebelumnya ini untuk membuat endpoint.
Ikuti langkah-langkah berikut untuk men-deploy model prediksi ke endpoint yang ada:
Buat file YAML yang menentukan resource kustom
DeployedModel
.File YAML berikut menunjukkan contoh konfigurasi:
apiVersion: prediction.aiplatform.gdc.goog/v1 kind: DeployedModel metadata: name: DEPLOYED_MODEL_NAME namespace: PROJECT_NAMESPACE spec: # The endpoint path structure is endpoints/<endpoint-id> endpointPath: endpoints/PREDICTION_ENDPOINT modelSpec: # The artifactLocation field must be the s3 path to the folder that # contains the various model versions. # For example, s3://my-prediction-bucket/tensorflow artifactLocation: s3://PATH_TO_MODEL # The value in the id field must be unique to each model. id: img-detection-model-v2 modelDisplayName: my_img_detection_model # The model resource name structure is models/<model-id>/<model-version-id> modelResourceName: models/img-detection-model/2 # The model version ID must match the name of the first folder in # the artifactLocation bucket, # inside the 'tensorflow' folder. # For example, if the bucket path is # s3://my-prediction-bucket/tensorflow/2/, # then the value for the model version ID is "2". modelVersionID: "2" modelContainerSpec: args: - --model_config_file=/models/models.config - --rest_api_port=8080 - --port=8500 - --file_system_poll_wait_seconds=30 - --model_config_file_poll_wait_seconds=30 command: - /bin/tensorflow_model_server # The image URI field must contain one of the following values: # For CPU-based models: gcr.io/aiml/prediction/containers/tf2-cpu.2-6:latest # For GPU-based models: gcr.io/aiml/prediction/containers/tf2-gpu.2-6:latest imageURI: gcr.io/aiml/prediction/containers/tf2-gpu.2-6:latest ports: - 8080 grpcPorts: - 8500 resourcePoolRef: kind: ResourcePool name: RESOURCE_POOL_NAME namespace: PROJECT_NAMESPACE
Ganti kode berikut:
DEPLOYED_MODEL_NAME
: nama yang ingin Anda berikan ke file definisiDeployedModel
.PROJECT_NAMESPACE
: nama namespace project yang terkait dengan cluster prediksi.PREDICTION_ENDPOINT
: nama endpoint yang ada, sepertimy-img-prediction-endpoint
.PATH_TO_MODEL
: jalur ke model Anda di bucket penyimpanan.RESOURCE_POOL_NAME
: nama yang Anda berikan ke file definisiResourcePool
saat Anda membuat kumpulan resource untuk menghosting model.
Ubah nilai di kolom yang tersisa sesuai dengan model prediksi Anda.
Terapkan file definisi
DeployedModel
ke cluster prediksi:kubectl --kubeconfig PREDICTION_CLUSTER_KUBECONFIG apply -f DEPLOYED_MODEL_NAME.yaml
Ganti kode berikut:
PREDICTION_CLUSTER_KUBECONFIG
: jalur ke file kubeconfig di cluster prediksi.DEPLOYED_MODEL_NAME
: nama file definisiDeployedModel
.
Saat Anda membuat resource kustom
DeployedModel
, Kubernetes API dan layanan webhook akan memvalidasi file YAML dan melaporkan keberhasilan atau kegagalan. Operator prediksi merekonsiliasi resource kustomDeployedModel
dan menayangkannya di cluster prediksi.Tampilkan detail resource kustom
Endpoint
yang ada:kubectl --kubeconfig PREDICTION_CLUSTER_KUBECONFIG describe -f ENDPOINT_NAME.yaml
Ganti
ENDPOINT_NAME
dengan nama file definisiEndpoint
.Perbarui file YAML definisi resource kustom
Endpoint
dengan menambahkan objekserviceRef
baru di kolomdestinations
. Pada objek baru, sertakan nama layanan yang sesuai berdasarkan resource kustomDeployedModel
yang baru dibuat.File YAML berikut menunjukkan contoh konfigurasi:
apiVersion: aiplatform.gdc.goog/v1 kind: Endpoint metadata: name: ENDPOINT_NAME namespace: PROJECT_NAMESPACE spec: createDns: true id: PREDICTION_ENDPOINT destinations: - serviceRef: kind: DeployedModel name: DEPLOYED_MODEL_NAME namespace: PROJECT_NAMESPACE trafficPercentage: 40 grpcPort: 8501 httpPort: 8081 - serviceRef: kind: DeployedModel name: DEPLOYED_MODEL_NAME_2 namespace: PROJECT_NAMESPACE trafficPercentage: 50 grpcPort: 8501 httpPort: 8081 - serviceRef: kind: DeployedModel name: DEPLOYED_MODEL_NAME_3 namespace: PROJECT_NAMESPACE trafficPercentage: 10 grpcPort: 8501 httpPort: 8081
Ganti kode berikut:
ENDPOINT_NAME
: nama file definisiEndpoint
yang ada.PROJECT_NAMESPACE
: nama namespace project yang terkait dengan cluster prediksi.PREDICTION_ENDPOINT
: nama endpoint yang ada. Anda mereferensikan nama ini pada file definisiDeployedModel
.DEPLOYED_MODEL_NAME
: nama file definisiDeployedModel
yang dibuat sebelumnya.DEPLOYED_MODEL_NAME_2
: nama yang Anda berikan ke file definisiDeployedModel
yang baru dibuat.
Anda dapat memiliki satu atau beberapa tujuan
serviceRef
. Jika Anda memiliki objekserviceRef
ketiga, tambahkan ke file YAML di kolomdestinations
dan gantiDEPLOYED_MODEL_NAME_3
dengan nama yang Anda berikan ke file definisiDeployedModel
ketiga yang Anda buat. Terus tambahkan atau hapus objekserviceRef
sesuai kebutuhan, bergantung pada jumlah model yang Anda deploy.Tetapkan kolom
trafficPercentage
berdasarkan cara Anda ingin membagi traffic di antara model endpoint ini. Ubah nilai di kolom lainnya sesuai dengan konfigurasi endpoint Anda.Terapkan file definisi
Endpoint
ke cluster prediksi:kubectl --kubeconfig PREDICTION_CLUSTER_KUBECONFIG apply -f ENDPOINT_NAME.yaml
Ganti
ENDPOINT_NAME
dengan nama file definisiEndpoint
.
Untuk mendapatkan jalur URL endpoint untuk model prediksi, jalankan perintah berikut:
kubectl --kubeconfig PREDICTION_CLUSTER_KUBECONFIG get endpoint PREDICTION_ENDPOINT -n PROJECT_NAMESPACE -o jsonpath='{.status.endpointFQDN}'
Ganti kode berikut:
PREDICTION_CLUSTER_KUBECONFIG
: jalur ke file kubeconfig di cluster prediksi.PREDICTION_ENDPOINT
: nama endpoint.PROJECT_NAMESPACE
: nama namespace project prediksi.