【问题标题】:Authenticate Custom Training Job in Vertex AI with Service Account使用服务帐户验证 Vertex AI 中的自定义训练作业
【发布时间】:2022-10-15 01:06:49
【问题描述】:

我正在尝试运行自定义训练作业,以直接从 Jupyterlab 在 Vertex AI 中部署我的模型。这个 Jupyterlab 是从一个 Vertex AI Managed Notebook 实例化的,我已经在其中指定了服务帐户。

我的目标是将我指定的训练脚本直接从笔记本的单元格部署到方法CustomTrainingJob。这相当于将包含我的脚本的图像推送到容器注册表并从 Vertex AI 的 UI 手动部署训练作业(通过这种方式,通过指定服务帐户,我能够正确地部署训练作业)。但是,我需要从同一个笔记本上执行所有内容。

为了指定 aiplatform 的CustomTrainingJob 的凭据,我执行以下单元格,其中所有变量都已正确设置:

import google.auth
from google.cloud import aiplatform
from google.auth import impersonated_credentials

source_credentials = google.auth.default()
target_credentials = impersonated_credentials.Credentials(
source_credentials=source_credentials,
target_principal='SERVICE_ACCOUNT.iam.gserviceaccount.com',
target_scopes = ['https://www.googleapis.com/auth/cloud-platform'])

aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_NAME)

job = aiplatform.CustomTrainingJob(
    display_name=JOB_NAME,
    script_path=SCRIPT_PATH,
    container_uri=MODEL_TRAINING_IMAGE,
    credentials=target_credentials
)

在执行job.run() 命令后,似乎没有正确设置凭据。特别是,返回以下错误:

/opt/conda/lib/python3.7/site-packages/google/auth/impersonated_credentials.py in _update_token(self, request)
    254 
    255         # Refresh our source credentials if it is not valid.
--> 256         if not self._source_credentials.valid:
    257             self._source_credentials.refresh(request)
    258 

AttributeError: 'tuple' object has no attribute 'valid'

我还尝试了不同的方法来配置我的服务帐户的凭据,但它们似乎都不起作用。在这种情况下,看起来包含源凭据的元组缺少“有效”属性,即使方法 google.auth.default() 仅返回两个值。

【问题讨论】:

    标签: google-cloud-platform service-accounts google-cloud-vertex-ai


    【解决方案1】:

    要使用服务帐户运行自定义训练作业,您可以尝试使用 service_account argument for job.run(),而不是尝试设置凭据。只要笔记本作为对所选服务帐户具有充当权限的用户执行,这应该允许您以该服务帐户的身份运行自定义训练作业。

    【讨论】:

      猜你喜欢
      • 2021-08-27
      • 2022-10-06
      • 2021-08-08
      • 2020-07-18
      • 2021-12-24
      • 2021-11-17
      • 2021-10-02
      • 2017-08-22
      • 2019-07-06
      相关资源
      最近更新 更多