管理 TPU Spot 虚拟机
Spot 虚拟机可以极高的折扣价格提供未使用的容量。Spot 虚拟机可随时被抢占(关闭),但与抢占式 TPU 不同,其运行时长没有限制。您无法重启 TPU Spot 虚拟机,并且必须在抢占后重新创建这些虚拟机。如需详细了解 Spot 虚拟机的一般信息,请参阅 Compute Engine 文档中的 Spot 虚拟机部分。
创建 TPU Spot 虚拟机
您可以使用已排队的资源创建 TPU Spot 虚拟机,这会将您的创建请求添加到队列中,并在容量可用时让您接收容量。最佳实践是将 TPU 创建为已排队的资源。如需了解详情,请参阅队列化资源用户指南。
以下示例展示了如何使用队列化资源创建 TPU Spot 虚拟机:
gcloud
将 --spot
标志添加到 gcloud compute tpus queued-resources
命令:
gcloud compute tpus queued-resources create QUEUED_RESOURCE_ID \ --node-id=NODE_ID \ --zone=europe-west4-a \ --accelerator-type=v3-8 \ --runtime-version=tpu-vm-tf-2.18.0-pod-pjrt \ --spot
curl
将 spot: {}
添加到请求正文:
curl -X POST https://tpu.googleapis.com/v2alpha1/projects/PROJECT_ID/locations/europe-west4-a/queuedResources?queued_resource_id=QUEUED_RESOURCE_ID \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ tpu: { node_spec: { parent: "projects/PROJECT_ID/locations/europe-west4-a", node_id: "NODE_ID", node: { accelerator_type: "v3-8", runtime_version: "tpu-vm-tf-2.18.0-pod-pjrt" } } }, spot: {} }'
控制台
在 Google Cloud 控制台中,前往 TPU 页面:
点击创建 TPU。
在名称字段中,为 TPU 输入名称。
在“可用区”框中,选择要创建 TPU 的可用区。
在 TPU 类型框中,选择加速器类型。加速器类型用于指定您要创建的 Cloud TPU 的版本和大小。如需详细了解每个 TPU 版本支持的加速器类型,请参阅 TPU 版本。
在 TPU 软件版本框中,选择软件版本。创建 Cloud TPU 虚拟机时,TPU 软件版本指定了要安装的 TPU 运行时的版本。如需了解详情,请参阅 TPU 虚拟机映像。
点击启用队列功能切换开关。
在已加入队列的资源名称字段中,为已加入队列的资源请求输入名称。
展开管理部分。
选中将此项设置为 TPU Spot 虚拟机复选框。
点击创建。
您还可以创建不使用已排队资源的 TPU Spot 虚拟机:
gcloud
将 --spot
标志添加到 gcloud compute tpus tpu-vm
命令:
gcloud compute tpus tpu-vm create TPU_NAME \ --zone=europe-west4-a \ --accelerator-type=v3-8 \ --version=tpu-vm-tf-2.18.0-pod-pjrt \ --spot
curl
将 scheduling_config: {spot: true}
添加到请求正文:
curl -X POST https://tpu.googleapis.com/v2/projects/PROJECT_ID/locations/europe-west4-a/nodes?node_id=TPU_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ accelerator_type: "v3-8", runtime_version: "tpu-vm-tf-2.18.0-pod-pjrt", network_config: {enable_external_ips: true}, scheduling_config: {spot: true} }'
控制台
检查 TPU 虚拟机是否为 Spot 虚拟机
gcloud
如需确认您的 TPU 虚拟机是否为 Spot 虚拟机,请使用 describe 命令:
gcloud compute tpus tpu-vm describe TPU_NAME --zone=europe-west4-a
如果 TPU 虚拟机是 Spot 虚拟机,则输出将包含设置为 true
的 spot
字段,如下所示:
...
schedulingConfig:
spot: true
...
控制台
在 Google Cloud 控制台中,前往 TPU 页面:
点击 Cloud TPU 的名称。
如果 TPU 虚拟机是 Spot 虚拟机,则层级将为 Spot 虚拟机。
价格和配额
TPU Spot 虚拟机的价格远低于按需 TPU 和预留 TPU 的价格。如需详细了解价格,请参阅 Cloud TPU 价格。
您需要抢占式配额才能使用 TPU Spot 虚拟机。如需了解详情,请参阅配额。