googleapis / python-aiplatform

A Python SDK for Vertex AI, a fully managed, end-to-end platform for data science and machine learning.
Apache License 2.0
641 stars 347 forks source link

`vertexai.init` always uses the default project instead of the project that is passed to it #2563

Open seperman opened 1 year ago

seperman commented 1 year ago

Environment details

Steps to reproduce

  1. vertexai.init(project=not_default_project_id)
  2. Watch vertexai use the default project id instead when language_models.CodeGenerationModel.from_pretrained(...) is called.

Below, you can see it is raising exception because the default project does not have Vertex AI enabled.

Stack trace

 File "~/.pyenv/versions/vertex/lib/python3.11/site-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.PermissionDenied: 403 Vertex AI API has not been used in project DEFAULT_PROJECT before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/aiplatform.googleapis.com/overview?project=DEFAULT_PROJECT then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. [links {
  description: "Google developers console API activation"
  url: "https://console.developers.google.com/apis/api/aiplatform.googleapis.com/overview?project=DEFAULT_PROJECT"
}
, reason: "SERVICE_DISABLED"
domain: "googleapis.com"
metadata {
  key: "service"
  value: "aiplatform.googleapis.com"
}
metadata {
  key: "consumer"
  value: "projects/DEFAULT_PROJECT"
}
]
seperman commented 1 year ago

I changed my default project to gcloud config set project ANOTHER_PROJECT and it still hitting DEFAULT_PROJECT. Where is it pulling DEFAULT_PROJECT from?

sasha-gitg commented 1 year ago

It's the default quota project ID set by Application Default Credentials(ADC)[1]. Recommended usage for setting the quota project ID is captured in https://github.com/googleapis/python-aiplatform/issues/2557#issuecomment-1709284744.

  1. https://cloud.google.com/docs/authentication/troubleshoot-adc
seperman commented 1 year ago

Thanks for responding @sasha-gitg So is this a bug or a feature? From the interface perspective, it presents itself as a bug.

whittid4 commented 1 month ago

I am facing this issue too. We want to use a sandbox project to constrain all of the Vertex experimentations to, but calling from a different project service account (Databricks).

The vertexai.init(project=not_default_project_id) works for other models (e.g Gemini), but as mentioned above, the call to TextEmbeddingModel.from_pretrained(model_name) is not respecting the project.

vmallya-123 commented 2 weeks ago

Hi is this issue resolved?