【发布时间】: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