安排笔记本运行
本页面介绍了如何在 Colab Enterprise 中安排笔记本运行。
概览
您可以安排笔记本立即运行一次,也可以安排笔记本定期运行。
安排笔记本运行时间时,您需要选择运行时模板。 Colab Enterprise 会使用此运行时模板来创建运行笔记本的运行时。
运行时需要特定权限才能运行笔记本的代码并访问 Google Cloud 服务和 API。
如果运行时模板配置启用了最终用户凭据,则运行时会使用与您的用户凭据关联的权限。
如果未启用最终用户凭证,您必须在安排笔记本运行时间时指定服务账号。Colab Enterprise 使用此服务账号的凭据来运行笔记本。
如需了解详情,请参阅运行笔记本所需的角色。
Colab Enterprise 完成笔记本运行后,结果会存储在可共享的 Cloud Storage 存储桶中。
限制
Colab Enterprise 运行时使用 Compute Engine 配额。请参阅 Compute Engine 分配配额页面。
准备工作
- 登录您的 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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. 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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
安排笔记本运行所需的角色
如需获得在 Colab Enterprise 中安排笔记本运行所需的权限,请让您的管理员为您授予项目的以下 IAM 角色:
- Colab Enterprise User (
roles/aiplatform.colabEnterpriseUser) - Storage Admin (
roles/storage.admin)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
运行笔记本所需的角色
运行笔记本的主账号需要特定权限。委托人是您的用户账号或您指定的服务账号,如概览中所述。
如需获得在 Colab Enterprise 中运行笔记本所需的权限,请让您的管理员为您授予以下 IAM 角色:
- 笔记本上的 Code Viewer (
roles/dataform.codeViewer) - 项目的 Logs Writer (
roles/logging.logWriter) - 监控指标写入者 (
roles/monitoring.metricWriter) 角色 对项目的权限 - 针对笔记本的 Storage Legacy Bucket Writer (
roles/storage.legacyBucketWriter) - 针对输出存储桶的 Storage Legacy Object Reader (
roles/storage.legacyObjectReader)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
这些预定义角色包含在 Colab Enterprise 中运行笔记本所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
如需在 Colab Enterprise 中运行笔记本,您需要拥有以下权限:
-
dataform.locations.list在笔记本上 -
dataform.repositories.computeAccessTokenStatus在笔记本上 -
dataform.repositories.fetchHistory在笔记本上 -
dataform.repositories.fetchRemoteBranches在笔记本上 -
dataform.repositories.get在笔记本上 -
dataform.repositories.getIamPolicy在笔记本上 -
dataform.repositories.list在笔记本上 -
dataform.repositories.queryDirectoryContents在笔记本上 -
dataform.repositories.readFile在笔记本上 -
针对项目的
logging.logEntries.create权限 -
针对项目的
logging.logEntries.route权限 -
针对项目的
monitoring.metricDescriptors.create权限 -
针对项目的
monitoring.metricDescriptors.get权限 -
针对项目的
monitoring.metricDescriptors.list权限 -
针对项目的
monitoring.monitoredResourceDescriptors.get权限 -
针对项目的
monitoring.monitoredResourceDescriptors.list权限 -
针对项目的
monitoring.timeSeries.create权限 -
针对项目的
resourcemanager.projects.get权限 -
针对项目的
resourcemanager.projects.list权限 -
storage.buckets.get在笔记本上 -
storage.managedFolders.create在笔记本上 -
storage.managedFolders.delete在笔记本上 -
storage.managedFolders.get在笔记本上 -
storage.managedFolders.list在笔记本上 -
storage.multipartUploads.abort在笔记本上 -
storage.multipartUploads.create在笔记本上 -
storage.multipartUploads.list在笔记本上 -
storage.multipartUploads.listParts在笔记本上 -
storage.objects.create在笔记本上 -
storage.objects.delete在笔记本上 -
storage.objects.get在笔记本上 -
storage.objects.list在笔记本上 -
storage.objects.restore在笔记本上 -
storage.objects.setRetention在笔记本上
在共享 VPC 网络中使用笔记本运行的预定时间
如需在共享 VPC 网络中使用笔记本运行调度,您必须授予额外的权限。请参阅在共享 VPC 网络中使用 Colab Enterprise。
运行笔记本一次
如需运行笔记本一次,您可以使用 Google Cloud 控制台、Google Cloud CLI、Agent Platform Python 客户端库或 Terraform。
控制台
-
在 Google Cloud 控制台中,前往 Colab Enterprise 我的笔记本页面。
-
在区域菜单中,选择包含笔记本的区域。
-
在笔记本旁边,点击 笔记本操作菜单,然后选择安排。
-
在时间表名称字段中,输入时间表的名称。
-
点击运行时模板列表,然后选择一个运行时模板。运行时模板用于确定运行笔记本的运行时的规范。
-
在运行时间表下,选择一次性,以便在您提交笔记本运行后立即运行笔记本。
-
点击 Cloud Storage 输出位置字段旁边的浏览,打开选择文件夹对话框。
-
选择 Cloud Storage 存储桶。或者,如需创建存储桶,请点击 创建新存储桶,然后完成对话框。
-
如果您选择的运行时模板未启用最终用户凭据,则该对话框会包含服务账号字段。在服务账号字段中,输入服务账号的电子邮件地址。
-
点击提交。
笔记本运行会立即开始。
gcloud
在使用下面的命令数据之前,请先进行以下替换:
DISPLAY_NAME:笔记本运行的显示名称。NOTEBOOK_RUNTIME_TEMPLATE:用于指定运行时计算配置的笔记本运行时模板。NOTEBOOK_URI:要运行的笔记本的 Cloud Storage URI。OUTPUT_URI:您要存储结果的 Cloud Storage 位置。USER_EMAIL:指定笔记本运行对 Google Cloud 资源的访问权限的用户账号电子邮件地址。PROJECT_ID:您的项目 ID。REGION:笔记本将运行的区域。
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud colab executions create --display-name="DISPLAY_NAME" \ --notebook-runtime-template=NOTEBOOK_RUNTIME_TEMPLATE \ --gcs-notebook-uri=NOTEBOOK_URI \ --gcs-output-uri=OUTPUT_URI