0

Trying to follow the example here to launch a custom job in vertex ai.

This is the code I am using

from google.cloud import aiplatform


def create_custom_job_sample(
    project: str,
    display_name: str,
    container_image_uri: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.JobServiceClient(client_options=client_options)
    custom_job = {
        "display_name": display_name,
        "job_spec": {
            "worker_pool_specs": [
                {
                    "machine_spec": {
                        "machine_type": "n1-standard-4"
                    },
                    "replica_count": 1,
                    "container_spec": {
                        "image_uri": container_image_uri,
                        "command": [],
                        "args": [],
                    },
                }
            ]
        },
    }
    parent = f"projects/{project}/locations/{location}"
    response = client.create_custom_job(parent=parent, custom_job=custom_job)
    print("response:", response)

create_custom_job_sample(
    "MY_PROJECT",
    "job-123",
    "europe-west1-docker.pkg.dev/<MYPROJECT>/<MY_IMAGE_URI>",
    "europe-west1",
    "eu-west1-aiplatform.googleapis.com"
)

However I get an error that start with

E0728 15:00:53.742356000 4417760704 hpack_parser.cc:1234]              Error parsing metadata: error=invalid value key=content-type value=text/html; charset=UTF-8

and ends with google.api_core.exceptions.Unknown: None Stream removed

Don't understand what the problem is. The job starts correctly from the terminal with

gcloud ai custom-jobs create \
  --region=europe-west1 \
  --display-name=test-job-1 \
  --worker-pool-spec=machine-type=n1-standard-4,replica-count=1,executor-image-uri=<MY_IMAGE_URI>,local-package-path=.,script=myfolder/myscript.py

Could someone help me?

Galuoises
  • 2,630
  • 24
  • 30
  • Check that the permissions or when you [create an instance](https://cloud.google.com/vertex-ai/docs/general/troubleshooting-workbench#:~:text=mode%20enabled.-,The%20following%20example%20shows%20how%20to%20specify%20a%20service%20account%20when%20you%20create%20an%20instance%3A,-gcloud%20notebooks%20instances) see that you are specifying the account with the correct IAM roles. – Jose Gutierrez Paliza Aug 01 '22 at 21:24
  • I can launch a job via gcloud and via call to the google rest api, so I think this is unlikely related with permissions. The problem seems to be related with the python library – Galuoises Aug 02 '22 at 09:07
  • When you launch the job without using the Console it normally uses a Service Account, so that's why I asked to check the permissions/roles. – Jose Gutierrez Paliza Aug 05 '22 at 17:05

0 Answers0