本頁面說明如何取得永久性資源清單,以及如何透過 Google Cloud 控制台、Google Cloud CLI、適用於 Python 的 Vertex AI SDK 和 REST API,取得特定永久性資源的相關資訊。
必要的角色
如要取得取得持續性資源資訊所需的權限,請要求管理員為您授予專案的 Vertex AI 檢視者 (roles/aiplatform.viewer
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這個預先定義的角色包含取得永久資源資訊所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要取得永久性資源資訊,您必須具備下列權限:
-
aiplatform.persistentResources.get
-
aiplatform.persistentResources.list
取得永久性資源清單
請選取下列任一分頁標籤,瞭解如何取得現有持續性資源的清單。
控制台
如要在 Google Cloud 控制台中查看永久性資源清單,請前往「永久性資源」頁面。
gcloud
使用下列任何指令資料之前,請先替換以下項目:
- PROJECT_ID:您要取得持久性資源清單的 Google Cloud 專案 ID。
- LOCATION:您要建立永久性資源的區域。如需支援地區的清單,請參閱「功能適用地區」。
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud ai persistent-resources list \ --project=PROJECT_ID \ --region=LOCATION
Windows (PowerShell)
gcloud ai persistent-resources list ` --project=PROJECT_ID ` --region=LOCATION
Windows (cmd.exe)
gcloud ai persistent-resources list ^ --project=PROJECT_ID ^ --region=LOCATION
您應該會收到類似以下的回應:
回應
Using endpoint [https://us-central1-aiplatform.googleapis.com/] --- createTime: '2023-09-12T20:45:33.220989Z' displayName: test name: projects/123456789012/locations/us-central1/persistentResources/test-persistent-resource resourcePools: - autoscalingSpec: maxReplicaCount: '4' minReplicaCount: '1' diskSpec: bootDiskSizeGb: 100 bootDiskType: pd-standard id: n1-highmem-2-nvidia-tesla-t4-1 machineSpec: acceleratorCount: 1 acceleratorType: NVIDIA_TESLA_T4 machineType: n1-highmem-2 replicaCount: '1' startTime: '2023-09-12T20:50:36.992739253Z' state: RUNNING updateTime: '2023-09-12T20:50:42.813723Z' --- createTime: '2023-09-12T20:37:21.691977Z' displayName: my-persistent-resource name: projects/123456789012/locations/us-central1/persistentResources/my-persistent-resource resourcePools: - autoscalingSpec: maxReplicaCount: '12' minReplicaCount: '4' diskSpec: bootDiskSizeGb: 200 bootDiskType: pd-standard id: n1-highmem-2-nvidia-tesla-t4-1 machineSpec: acceleratorCount: 1 acceleratorType: NVIDIA_TESLA_T4 machineType: n1-highmem-2 replicaCount: '4' - diskSpec: bootDiskSizeGb: 100 bootDiskType: pd-ssd id: n1-standard-4 machineSpec: machineType: n1-standard-4 replicaCount: '4' startTime: '2023-09-12T20:42:46.495575169Z' state: RUNNING updateTime: '2023-09-12T20:42:51.519271Z'
Python
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Python。詳情請參閱 Vertex AI Python API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
清單中每個持續性資源的狀態會以數值表示。詳情請參閱 Vertex AI SDK 中的狀態定義。
from google.cloud.aiplatform.preview import persistent_resource # Optional arguments: # filter (str): An expression for filtering the results of the request. For # field names both snake_case and camelCase are supported. # order_by (str): A comma-separated list of fields to order by, sorted in # ascending order. Use "desc" after a field name for descending. Supported # fields: `display_name`, `create_time`, `update_time` # List the persistent resource on the project. resource_list = persistent_resource.PersistentResource.list() for i in range(len(resource_list)): print(resource_list[i].name) print(resource_list[i].state)
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您要取得持久性資源清單的 Google Cloud 專案 ID。
- LOCATION:您要建立永久性資源的區域。如需支援地區的清單,請參閱「功能適用地區」。
HTTP 方法和網址:
GET https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/persistentResources
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
取得永久性資源的相關資訊
請選取下列任一分頁,瞭解如何取得有關持久性資源的資訊,包括其狀態、硬體設定和可用的副本。
控制台
如要在 Google Cloud 控制台中查看永久資源的相關資訊,請按照下列步驟操作:
在 Google Cloud 控制台,前往「Persistent resources」(永久性資源) 頁面。
按一下要查看的永久性資源名稱。
gcloud
使用下列任何指令資料之前,請先替換以下項目:
- PROJECT_ID:您要取得資訊的永久資源專案 ID。
- LOCATION:您要取得資訊的永久性資源區域。
- PERSISTENT_RESOURCE_ID:您要取得資訊的永久資源 ID。
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud ai persistent-resources describe PERSISTENT_RESOURCE_ID \ --project=PROJECT_ID \ --region=LOCATION
Windows (PowerShell)
gcloud ai persistent-resources describe PERSISTENT_RESOURCE_ID ` --project=PROJECT_ID ` --region=LOCATION
Windows (cmd.exe)
gcloud ai persistent-resources describe PERSISTENT_RESOURCE_ID ^ --project=PROJECT_ID ^ --region=LOCATION
您應該會收到類似以下的回應:
回應
Using endpoint [https://us-central1-aiplatform.googleapis.com/] createTime: '2023-07-06T18:47:42.098296Z' displayName: Test-Persistent-Resource name: projects/123456789012/locations/us-central1/persistentResources/my-persistent-resource resourcePools: - diskSpec: bootDiskSizeGb: 100 bootDiskType: pd-ssd machineSpec: machineType: n1-highmem-4 replicaCount: '4' - diskSpec: bootDiskSizeGb: 100 bootDiskType: pd-ssd machineSpec: acceleratorCount: 1 acceleratorType: NVIDIA_TESLA_P4 machineType: n1-standard-4 replicaCount: '4' usedReplicaCOunt: '2' startTime: '2023-07-06T18:51:53.209127117Z' state: RUNNING updateTime: '2023-07-06T18:52:01.545109Z'
Python
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Python。詳情請參閱 Vertex AI Python API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
from google.cloud.aiplatform.preview import persistent_resource resource_to_get = persistent_resource.PersistentResource( PERSISTENT_RESOURCE_ID ) print(resource_to_get.display_name) print(resource_to_get.state) print(resource_to_get.start_time)
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您要取得資訊的永久資源專案 ID。
- LOCATION:您要取得資訊的永久性資源區域。
- PERSISTENT_RESOURCE_ID:您要取得資訊的永久資源 ID。
HTTP 方法和網址:
GET https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/persistentResources/PERSISTENT_RESOURCE_ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/123456789012/locations/us-central1/persistentResources/test-persistent-resource", "displayName": "test", "resourcePools": [ { "id": "n1-highmem-2-nvidia-tesla-t4-1", "machineSpec": { "machineType": "n1-highmem-2", "acceleratorType": "NVIDIA_TESLA_T4", "acceleratorCount": 1 }, "replicaCount": "1", "diskSpec": { "bootDiskType": "pd-standard", "bootDiskSizeGb": 100 }, "autoscalingSpec": { "minReplicaCount": "1", "maxReplicaCount": "4" } } ], "state": "RUNNING", "createTime": "2023-09-12T20:45:33.220989Z", "startTime": "2023-09-12T20:50:36.992739253Z", "updateTime": "2023-09-12T20:50:42.813723Z" }