閒置關閉
根據預設,Colab Enterprise 執行階段會在閒置 180 分鐘後關閉。本頁面說明閒置關機功能,以及如何在建立執行階段範本時,變更預設閒置關機設定或關閉這項功能。
總覽
為協助管理費用,Colab Enterprise 執行階段預設會在閒置一段時間後關閉。建立執行階段範本時,您可以變更時間長度或關閉這項功能。
執行階段範本建立後,即無法變更設定。因此,您無法變更執行階段或執行階段範本的閒置關機設定。如要使用閒置關機設定不同的執行階段,請先建立具有所需設定的執行階段範本,然後使用該範本產生的執行階段。
事前準備
- 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
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.enablepermission. 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.-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
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.enablepermission. 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.
必要的角色
如要取得在 Colab Enterprise 建立執行階段所需的權限,請要求管理員授予您專案的 Colab Enterprise 管理員 (roles/aiplatform.colabEnterpriseAdmin) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
建立執行階段範本,並指定閒置關機設定
如要建立具有特定閒置關機設定的執行階段範本,可以使用 Google Cloud 控制台或 Google Cloud CLI。
控制台
如要建立具有特定閒置關機設定的執行階段範本,請按照下列步驟操作:
-
前往 Google Cloud 控制台的 Colab Enterprise「Runtime templates」(執行階段範本) 頁面。
-
按一下「 New template」(新增範本)。
「Create new runtime template」(建立新的執行階段範本) 對話方塊隨即顯示。
-
在「Runtime basics」(執行階段基本資訊) 部分,輸入「Display name」(顯示名稱)。
-
在「Region」(區域) 選單中,選取執行階段範本所在的區域。
-
如要變更閒置關機設定,請按一下「Configure compute」(設定運算) 專區,然後完成下列步驟。
-
在「Idle shutdown」(閒置關機) 部分:
-
如要關閉閒置關機功能,請清除「Enable idle shutdown」(啟用閒置關機功能)。
-
如要變更閒置時間長度,請在「關機前的閒置時間 (分鐘)」中,將數字變更為所需的閒置分鐘數。在 Google Cloud 控制台中,這項設定可設為 10 到 1440 之間的任何整數值。
-
-
在「Environment」(環境) 部分,選取「Environment」(環境)。 預設值為「Latest」(最新) (目前為 Python 3.13)。
-
選用:在「Post-startup script」(執行開機指令碼後) 欄位中,輸入執行開機指令碼後的 URI。如要進一步瞭解如何使用啟動後指令碼,請參閱「使用啟動後指令碼」。
-
選用:在執行開機指令碼後網址下方,選取執行開機指令碼後的行為。預設行為是「Run once」(執行一次)。詳情請參閱「開機指令碼行為」。
-
選用:如要新增環境變數,請按一下 「Add env variable」(新增環境變數),然後輸入「Key」(鍵) 和「Value」(值) 配對。如要新增更多環境變數,請重複這個步驟。
-
按一下「繼續」。
-
完成建立對話方塊的其餘部分。
-
按一下「Create」(建立),完成建立執行階段範本。
執行階段範本會顯示在「Runtime templates」(執行階段範本) 分頁的清單中。
gcloud
使用下列任何指令資料前,請先替換以下項目:
DISPLAY_NAME:執行階段範本的顯示名稱。INACTIVITY_DURATION:執行階段關閉前的閒置時間長度。輸入0s會關閉閒置關機功能。有效值範圍為 10 分鐘 (10m) 至 24 小時 (24h)。PROJECT_ID:您的專案 ID。REGION:執行階段範本所在的區域。
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud colab runtime-templates create --display-name=DISPLAY_NAME \ --idle-shutdown-timeout=INACTIVITY_DURATION \ --project=PROJECT_ID \ --region=REGION
Windows (PowerShell)
gcloud colab runtime-templates create --display-name=DISPLAY_NAME ` --idle-shutdown-timeout=INACTIVITY_DURATION ` --project=PROJECT_ID ` --region=REGION
Windows (cmd.exe)
gcloud colab runtime-templates create --display-name=DISPLAY_NAME ^ --idle-shutdown-timeout=INACTIVITY_DURATION ^ --project=PROJECT_ID ^ --region=REGION
如要進一步瞭解如何透過指令列建立執行階段範本,請參閱 gcloud CLI 說明文件。
閒置關機功能的運作方式
符合下列條件時,執行階段就會關閉:
指定時間範圍內沒有核心活動。
執行階段未連結至筆記本。
如要中斷執行階段與筆記本的連線,請關閉筆記本。如果筆記本在連線至執行階段時保持開啟,執行階段就不會關閉。
如要瞭解執行階段產生的費用,請參閱「執行階段費用」。
後續步驟
- 進一步瞭解執行階段和執行階段範本。
- 瞭解如何依據執行階段範本建立執行階段。
- 如要尋找可協助您快速啟動專案的筆記本,請參閱筆記本庫。