管理 TPU Spot 虚拟机

Spot 虚拟机以超低费率提供未使用的容量。Spot 虚拟机可以随时抢占(关停),但与抢占式 TPU 不同的是,对运行时时长没有限制。您无法重启 TPU Spot 虚拟机,并且在抢占后必须重新创建它们。如需大致了解 Spot 虚拟机的整体情况,请参阅有关 Spot 虚拟机的 Compute Engine 文档

创建 TPU Spot 虚拟机

您可以使用排队的资源创建 TPU Spot 虚拟机,这会将您的创建请求添加到队列中,并使您在容量可用时获得容量。最佳实践是将 TPU 创建为已排入队列的资源。如需了解详情,请参阅已加入队列的资源用户指南

通过将 --spot 标志添加到已加入队列的资源 create 命令中,将 TPU Spot 虚拟机创建为已加入队列的资源:

gcloud

gcloud alpha 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.16.1-pod-pjrt \
  --spot

curl

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.16.1-pod-pjrt"
        }
      }
    },
    spot: {}
  }'

您还可以通过向 create 命令添加 --spot 标志来创建 TPU Spot 虚拟机,而无需使用已加入队列的资源:

gcloud

gcloud compute tpus tpu-vm create TPU_NAME \
  --zone=europe-west4-a \
  --accelerator-type=v3-8 \
  --version=tpu-vm-tf-2.16.1-pod-pjrt \
  --spot

curl

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.16.1-pod-pjrt",
    network_config: {enable_external_ips: true},
    scheduling_config: {spot: true}
  }'

检查 TPU 虚拟机是否为 Spot 虚拟机

如需确认您的 TPU 虚拟机是否为 Spot 虚拟机,请使用 describe 命令:

gcloud compute tpus tpu-vm describe TPU_NAME --zone=europe-west4-a

如果 TPU 虚拟机是 Spot 虚拟机,则输出将包含设置为 truespot 字段,类似于以下内容:

...
schedulingConfig:
  spot: true
...

价格和配额

TPU Spot 虚拟机的价格远低于按需 TPU 和预留 TPU。如需详细了解价格,请参阅 Cloud TPU 价格

您需要有抢占式配额才能使用 TPU Spot 虚拟机。如需了解详情,请参阅配额