管理 TPU Spot 虚拟机

Spot 虚拟机以极高的折扣费率提供未使用的容量。 Spot 虚拟机可以随时被抢占(关停),但不同于抢占式虚拟机 TPU,对运行时时长无限制。禁止的行为 重启 TPU Spot 虚拟机,您必须在抢占后重新创建它们。对于 请参阅 Compute Engine 有关 Spot 虚拟机的文档

创建 TPU Spot 虚拟机

您可以使用排队的资源创建 TPU Spot 虚拟机, 创建请求发送到队列,并允许您在容量变为 可用。最佳做法是将 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.17.0-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.17.0-pod-pjrt"
        }
      }
    },
    spot: {}
  }'

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

gcloud

gcloud compute tpus tpu-vm create TPU_NAME \
  --zone=europe-west4-a \
  --accelerator-type=v3-8 \
  --version=tpu-vm-tf-2.17.0-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.17.0-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 虚拟机,则输出将包括 spot 字段设置为 true,类似于以下内容:

...
schedulingConfig:
  spot: true
...

价格和配额

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

您需要有抢占式配额才能使用 TPU Spot 虚拟机。如需更多信息 请参阅配额