如何在 Vertex AI 中访问 AIP_STORAGE_URI?

How do I access AIP_STORAGE_URI in Vertex AI?

我上传了一个模型

gcloud beta ai models upload --artifact-uri

并在 docker 中访问 AIP_STORAGE_URI。 我看到 AIP_STORAGE_URI 是另一个 Google 存储位置,所以我尝试使用 storage.Client() 下载文件,但它说我没有访问权限:

google.api_core.exceptions.Forbidden: 403 GET https://storage.googleapis.com/storage/v1/b/caip-tenant-***-***-*-*-***?projection=noAcl&prettyPrint=false: custom-online-prediction@**.iam.gserviceaccount.com does not have storage.buckets.get access to the Google Cloud Storage bucket

我是 运行 使用默认服务帐户的此端点。

https://cloud.google.com/vertex-ai/docs/predictions/custom-container-requirements#artifacts

根据上述link: The service account that your container uses by default has permission to read from this URI.

我做错了什么?

错误背后的原因是,Vertex AI 使用的默认服务帐户具有“Storage Object Viewer”角色,排除了 storage.buckets.get 权限。同时,代码的 storage.Client() 部分向默认服务帐户没有权限的 Vertex AI 托管存储桶发出 storage.buckets.get 请求。

要解决此问题,我建议您按照以下步骤操作 -

  • 更改自定义代码以访问包含项目中模型工件的存储桶,而不是使用指向 Vertex AI 托管存储桶中模型位置的环境变量 AIP_STORAGE_URI .

  • 创建您自己的服务帐户并授予服务帐户所有 permissions needed by the custom code. For this specific error, a role with the storage.buckets.get permission, eg. Storage Admin ("roles/storage.admin") 必须授予服务帐户。

  • 部署模型时在“服务帐户”字段中提供新创建的服务帐户。