הגדרת הגדרות של מאגרים לאימון ללא שרת ב-Gemini Enterprise Agent Platform

כשמבצעים אימון ללא שרת ב-Gemini Enterprise Agent Platform, צריך לציין איזה קוד של למידת מכונה (ML) רוצים ש-Gemini Enterprise Agent Platform יריץ. כדי לעשות את זה, מגדירים את ההגדרות של קונטיינר האימון עבור קונטיינר בהתאמה אישית או אפליקציית אימון של Python שפועלת בקונטיינר מוכן מראש.

כדי להחליט אם רוצים להשתמש במאגר תגים בהתאמה אישית או במאגר תגים מוכן מראש, כדאי לקרוא את המאמר דרישות קוד ההדרכה.

במסמך הזה מתוארים השדות של Agent Platform API שצריך לציין בכל אחד מהמקרים הקודמים.

איפה מציינים את הגדרות המאגר

מציינים את פרטי ההגדרה בתוך תג WorkerPoolSpec. בהתאם לאופן שבו מבצעים אימון ללא שרת, צריך להזין את הערך WorkerPoolSpec באחד משדות ה-API הבאים:

אם אתם מבצעים אימון מבוזר, אתם יכולים להשתמש בהגדרות שונות לכל מאגר עובדים.

קביעת הגדרות של מאגרי תגים

בהתאם לסוג מאגר התגים שבו אתם משתמשים (מאגר תגים מוכן מראש או מאגר תגים בהתאמה אישית), צריך לציין שדות שונים בתוך WorkerPoolSpec. בוחרים את הכרטיסייה של התרחיש הרלוונטי:

מאגר מוכן מראש

  1. בוחרים מאגר תגים מוכן מראש שתומך במסגרת ה-ML שבה אתם מתכננים להשתמש לאימון. מציינים אחת מכתובות ה-URI של תמונת הקונטיינר בשדה pythonPackageSpec.executorImageUri.

  2. מציינים את מזהי ה-URI של Cloud Storage של אפליקציית האימון של Python בשדה pythonPackageSpec.packageUris.

  3. מציינים את מודול נקודת הכניסה של אפליקציית האימון בשדה pythonPackageSpec.pythonModule.

  4. אפשר גם לציין רשימה של ארגומנטים בשורת הפקודה שיועברו למודול נקודת הכניסה של אפליקציית האימון בשדה pythonPackageSpec.args.

בדוגמאות הבאות מודגש איפה מציינים את הגדרות הקונטיינר האלה כשיוצרים CustomJob:

המסוף

במסוף Google Cloud , אי אפשר ליצור CustomJob ישירות. עם זאת, אפשר ליצור TrainingPipeline שיוצר CustomJob. כשיוצרים TrainingPipeline במסוף Google Cloud , אפשר לציין הגדרות מוכנות מראש של מאגר תגים בשדות מסוימים בשלב Training container (מאגר תגים לאימון):

  • pythonPackageSpec.executorImageUri: משתמשים בתפריטים הנפתחים Model framework ו-Model framework version.

  • pythonPackageSpec.packageUris: משתמשים בשדה מיקום החבילה.

  • pythonPackageSpec.pythonModule: משתמשים בשדה Python module.

  • pythonPackageSpec.args: משתמשים בשדה Arguments (ארגומנטים).

gcloud

gcloud ai custom-jobs create \
  --region=LOCATION \
  --display-name=JOB_NAME \
  --python-package-uris=PYTHON_PACKAGE_URIS \
  --worker-pool-spec=machine-type=MACHINE_TYPE,replica-count=REPLICA_COUNT,executor-image-uri=PYTHON_PACKAGE_EXECUTOR_IMAGE_URI,python-module=PYTHON_MODULE

למידע נוסף, אפשר לקרוא את המדריך ליצירת CustomJob.

מאגר תגים בהתאמה אישית

  1. מציינים את ה-URI של Artifact Registry או Docker Hub של המאגר המותאם אישית בשדה containerSpec.imageUri.

  2. אם רוצים לשנות את ההוראות של ENTRYPOINT או CMD במאגר התגים, אפשר לציין את השדות containerSpec.command או containerSpec.args. השדות האלה משפיעים על הפעלת מאגר התגים בהתאם לכללים הבאים:

    • אם לא מציינים אף אחד מהשדות: מאגר התגים יפעל בהתאם להוראה ENTRYPOINT ולהוראה CMD (אם היא קיימת). במאמרי העזרה של Docker מוסבר איך CMD ו-ENTRYPOINT פועלים יחד.

    • אם מציינים רק containerSpec.command: מאגר התגים יפעל עם הערך של containerSpec.command במקום ההוראה ENTRYPOINT. אם יש תג CMD במאגר התגים, המערכת מתעלמת ממנו.

    • אם מציינים רק containerSpec.args: מאגר התגים פועל בהתאם להוראה ENTRYPOINT, והערך של containerSpec.args מחליף את ההוראה CMD.

    • אם מציינים את שני השדות: מאגר התגים פועל עם containerSpec.command במקום ההוראה ENTRYPOINT ועם containerSpec.args במקום ההוראה CMD.

בדוגמה הבאה אפשר לראות איפה מציינים חלק מההגדרות של מאגר התגים כשיוצרים CustomJob:

המסוף

במסוף Google Cloud , אי אפשר ליצור CustomJob ישירות. עם זאת, אפשר ליצור TrainingPipeline שיוצר CustomJob. כשיוצרים TrainingPipeline במסוף Google Cloud , אפשר לציין הגדרות מותאמות אישית של מאגר התגים בשדות מסוימים בשלב Training container (מאגר תגים לאימון):

  • containerSpec.imageUri: משתמשים בשדה Container image (קובץ אימג' של קונטיינר).

  • containerSpec.command: אי אפשר להגדיר את השדה הזה ב-API בGoogle Cloud מסוף.

  • containerSpec.args: משתמשים בשדה Arguments (ארגומנטים).

gcloud

gcloud ai custom-jobs create \
  --region=LOCATION \
  --display-name=JOB_NAME \
  --worker-pool-spec=machine-type=MACHINE_TYPE,replica-count=REPLICA_COUNT,container-image-uri=CUSTOM_CONTAINER_IMAGE_URI

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Javaההוראות להגדרה במאמר מדריך למתחילים של Agent Platform באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Agent Platform Java API.

כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


import com.google.cloud.aiplatform.v1.AcceleratorType;
import com.google.cloud.aiplatform.v1.ContainerSpec;
import com.google.cloud.aiplatform.v1.CustomJob;
import com.google.cloud.aiplatform.v1.CustomJobSpec;
import com.google.cloud.aiplatform.v1.JobServiceClient;
import com.google.cloud.aiplatform.v1.JobServiceSettings;
import com.google.cloud.aiplatform.v1.LocationName;
import com.google.cloud.aiplatform.v1.MachineSpec;
import com.google.cloud.aiplatform.v1.WorkerPoolSpec;
import java.io.IOException;

// Create a custom job to run machine learning training code in Vertex AI
public class CreateCustomJobSample {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "PROJECT";
    String displayName = "DISPLAY_NAME";

    // Vertex AI runs your training application in a Docker container image. A Docker container
    // image is a self-contained software package that includes code and all dependencies. Learn
    // more about preparing your training application at
    // https://cloud.google.com/vertex-ai/docs/training/overview#prepare_your_training_application
    String containerImageUri = "CONTAINER_IMAGE_URI";
    createCustomJobSample(project, displayName, containerImageUri);
  }

  static void createCustomJobSample(String project, String displayName, String containerImageUri)
      throws IOException {
    JobServiceSettings settings =
        JobServiceSettings.newBuilder()
            .setEndpoint("us-central1-aiplatform.googleapis.com:443")
            .build();
    String location = "us-central1";

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests.
    try (JobServiceClient client = JobServiceClient.create(settings)) {
      MachineSpec machineSpec =
          MachineSpec.newBuilder()
              .setMachineType("n1-standard-4")
              .setAcceleratorType(AcceleratorType.NVIDIA_TESLA_T4)
              .setAcceleratorCount(1)
              .build();

      ContainerSpec containerSpec =
          ContainerSpec.newBuilder().setImageUri(containerImageUri).build();

      WorkerPoolSpec workerPoolSpec =
          WorkerPoolSpec.newBuilder()
              .setMachineSpec(machineSpec)
              .setReplicaCount(1)
              .setContainerSpec(containerSpec)
              .build();

      CustomJobSpec customJobSpecJobSpec =
          CustomJobSpec.newBuilder().addWorkerPoolSpecs(workerPoolSpec).build();

      CustomJob customJob =
          CustomJob.newBuilder()
              .setDisplayName(displayName)
              .setJobSpec(customJobSpecJobSpec)
              .build();
      LocationName parent = LocationName.of(project, location);
      CustomJob response = client.createCustomJob(parent, customJob);
      System.out.format("response: %s\n", response);
      System.out.format("Name: %s\n", response.getName());
    }
  }
}

Node.js

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Node.jsההוראות להגדרה במאמר מדריך למתחילים של Agent Platform באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Agent Platform Node.js API.

כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */

// const customJobDisplayName = 'YOUR_CUSTOM_JOB_DISPLAY_NAME';
// const containerImageUri = 'YOUR_CONTAINER_IMAGE_URI';
// const project = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';

// Imports the Google Cloud Job Service Client library
const {JobServiceClient} = require('@google-cloud/aiplatform');

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};

// Instantiates a client
const jobServiceClient = new JobServiceClient(clientOptions);

async function createCustomJob() {
  // Configure the parent resource
  const parent = `projects/${project}/locations/${location}`;
  const customJob = {
    displayName: customJobDisplayName,
    jobSpec: {
      workerPoolSpecs: [
        {
          machineSpec: {
            machineType: 'n1-standard-4',
            acceleratorType: 'NVIDIA_TESLA_T4',
            acceleratorCount: 1,
          },
          replicaCount: 1,
          containerSpec: {
            imageUri: containerImageUri,
            command: [],
            args: [],
          },
        },
      ],
    },
  };
  const request = {parent, customJob};

  // Create custom job request
  const [response] = await jobServiceClient.createCustomJob(request);

  console.log('Create custom job response:\n', JSON.stringify(response));
}
createCustomJob();

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של Python API.

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",
                        "accelerator_type": aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_K80,
                        "accelerator_count": 1,
                    },
                    "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)

למידע נוסף, אפשר לקרוא את המדריך ליצירת CustomJob.

המאמרים הבאים