使用預留項目

本文說明如何使用 Compute Engine 預留項目,確保 Colab Enterprise 執行階段有足夠的虛擬機器 (VM) 資源可供執行。

預留項目是 Compute Engine 的功能。預留項目有助於確保您擁有可用的資源,隨時都能建立具有相同硬體 (記憶體和 vCPU) 和選用資源 (GPU 和本機 SSD 磁碟) 的 VM。

建立預留項目時,Compute Engine 會驗證指定可用區是否有要求的容量。如果是,Compute Engine 會保留資源、建立預留項目,並執行下列操作:

  • 預留的資源可立即使用,直到您刪除預留項目為止。

  • 在刪除預留項目之前,預留資源的計費方式與執行中的 VM 相同,都是依據隨選費率計算,並包含任何適用的折扣。使用預留項目時,VM 不會產生重複的資源費用,因為預留項目已針對預留資源的費用計費。詳情請參閱「Compute Engine 可用區資源的預留項目」。

總覽

如要在 Colab Enterprise 使用預留項目,請執行下列工作:

  1. 建立預留項目。

  2. 將預留項目新增至新的執行階段範本。

  3. 在衍生自執行階段範本的執行階段上執行程式碼,使用預留項目。

限制與需求

Colab Enterprise 執行階段使用預留項目時,Compute Engine 預留項目的所有限制皆適用。請參閱「預留項目的運作方式」。

此外,搭配 Colab Enterprise 使用預留項目時,須遵守下列限制和規定:

  • 預訂必須符合下列其中一項條件:

    • 與 Colab Enterprise 筆記本和執行階段位於相同專案。
    • 與 Colab Enterprise 筆記本和執行階段共用同一個專案。
  • 預留項目的 VM 屬性必須與 Colab Enterprise 執行階段完全相符,才能使用預留項目。舉例來說,如果預留項目指定 e2-standard-8 機型,則 Colab Enterprise 執行階段也必須使用 e2-standard-8 機型,才能使用該預留項目。請參閱「需求條件」。

事前準備

  1. 請參閱預留項目的規定和限制。
  2. 查看共用預留項目的配額規定和限制。
  3. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Agent Platform, Dataform, and Compute Engine APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

必要的角色

如要取得透過 Colab Enterprise 使用預留項目所需的權限,請要求管理員授予您下列專案 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

建立預留項目

建立 Compute Engine 預留項目。可以是單一專案預留項目或共用預留項目。詳情請參閱下列文件:

預留項目可包含 GPU 加速器。

將預留項目新增至新的執行階段範本

如要建立使用預留項目的執行階段範本,請按照下列步驟操作:
  1. 前往 Google Cloud 控制台的 Colab Enterprise「Runtime templates」(執行階段範本) 頁面。

    前往「Runtime templates」(執行階段範本) 頁面

  2. 按一下「 New template」(新增範本)。

    「Create new runtime template」(建立新的執行階段範本) 對話方塊隨即顯示。

  3. 在「Runtime basics」(執行階段基本資訊) 部分,輸入「Display name」(顯示名稱)。

  4. 在「Region」(區域) 選單中,選取執行階段範本所在的區域。

  5. 在「Configure compute」(設定運算) 區段的「Machine type」(機器類型) 選單中,選取機器類型。執行階段範本的機器類型必須與預留項目的機器類型相符。

  6. 在「Reservations」(預留項目) 選單中,選取要使用的特定預留項目,或選取「Use automatically selected reservations」(使用自動選取的預留項目)。

    如要進一步瞭解如何使用自動選取或指定目標的預留項目,請參閱「預留項目的運作方式」中的「使用類型」一節。

  7. 完成對話方塊中的其餘部分,然後按一下「Create」。

    執行階段範本會顯示在「Runtime templates」(執行階段範本) 分頁的清單中。

使用預留項目

如要使用預留項目,請按照下列步驟操作:

  1. 使用新的執行階段範本建立執行階段。

  2. 開啟或建立筆記本。

  3. 在筆記本中連線至執行階段,然後執行程式碼。

停止使用預留項目

如要停止使用預留項目,可以刪除預留項目。

如要繼續將預留項目用於其他資源,但不希望 Colab Enterprise 筆記本使用該預留項目,請刪除與預留項目相關聯的執行階段和執行階段範本。

帳單

使用 Compute Engine 預留項目時,您需要支付下列費用:

疑難排解

本節說明如何解決在 Colab Enterprise 使用預留項目時遇到的問題。

無法建立執行階段

嘗試建立執行階段時,發生類似下列的錯誤。

Failed to create notebook runtime with error: Invalid value for field
'resource.reservationAffinity': '{"consumeReservationType":
"SPECIFIC_ALLOCATION", "key": "compute.googleapis.com/reservation-name...'.
No available resources in specified reservations.

如果預留項目的 VM 屬性與 Colab Enterprise 執行階段不符,就會發生這項錯誤。舉例來說,如果預留項目指定 e2-standard-8 機型,則 Colab Enterprise 執行階段也必須使用 e2-standard-8 機型,才能使用該預留項目。詳情請參閱「需求條件」。

如要解決這個問題,請建立執行階段範本,並採用與預留項目 VM 屬性相符的設定。

後續步驟