פריסה והיקש של Gemma באמצעות Model Garden ונקודות קצה של Gemini Enterprise Agent Platform עם תמיכה ב-TPU

במדריך הזה נשתמש ב-Model Garden כדי לפרוס את המודל הפתוח Gemma 2 2B לנקודת קצה של Gemini Enterprise Agent Platform עם תמיכה ב-TPU. כדי להשתמש במודל כדי להציג תחזיות אונליין, צריך לפרוס את המודל לנקודת קצה. פריסת מודל משייכת למודל משאבים פיזיים כדי שהוא יוכל לספק תחזיות אונליין עם זמן אחזור נמוך.

אחרי שפורסים את מודל Gemma 2 2B, מסיקים מסקנות מהמודל שאומן באמצעות PredictionServiceClient כדי לקבל חיזויים אונליין. תחזיות אונליין הן בקשות סנכרוניות שנשלחות למודל שפריסתו מתבצעת לנקודת קצה (endpoint).

מטרות

במדריך הזה מוסבר איך לבצע את הפעולות הבאות:

  • איך פורסים את המודל הפתוח Gemma 2 2B לנקודת קצה שמגובה על ידי TPU באמצעות Model Garden
  • משתמשים ב-PredictionServiceClient כדי לקבל תחזיות אונליין

עלויות

במסמך הזה משתמשים ברכיבים הבאים של Google Cloud, והשימוש בהם כרוך בתשלום:

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

משתמשים חדשים של Google Cloud ? יכול להיות שאתם זכאים לתקופת ניסיון בחינם.

כשמסיימים את המשימות שמתוארות במסמך הזה אפשר למחוק את המשאבים שיצרתם כדי להימנע מחיובים נוספים. מידע נוסף זמין בקטע הסרת המשאבים.

לפני שמתחילים

כדי לבצע את הפעולות במדריך הזה, צריך:

  • הגדרת פרויקט והפעלת Agent Platform API Google Cloud
  • במכונה המקומית:
    • התקנה, הפעלה ואימות באמצעות Google Cloud CLI
    • התקנה של ה-SDK בשפה שלכם

הגדרת Google Cloud פרויקט

מגדירים את הפרויקט ב- Google Cloud ומפעילים את Agent Platform API.

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Agent Platform API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Agent Platform API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

הגדרת Google Cloud CLI

במחשב המקומי, מגדירים את Google Cloud CLI.

  1. מתקינים ומפעילים את Google Cloud CLI.

  2. אם התקנתם בעבר את ה-CLI של gcloud, מריצים את הפקודה הזו כדי לוודא שהרכיבים של gcloud מעודכנים.

    gcloud components update
  3. כדי לבצע אימות באמצעות ה-CLI של gcloud, מריצים את הפקודה הזו כדי ליצור קובץ מקומי של Application Default Credentials ‏ (ADC). תהליך האינטרנט שמופעל על ידי הפקודה משמש להזנת פרטי הכניסה שלכם.

    gcloud auth application-default login

    למידע נוסף, ראו הגדרת אימות ב-CLI של gcloud והגדרת ADC.

הגדרת ה-SDK לשפת התכנות

כדי להגדיר את הסביבה שבה משתמשים במדריך הזה, צריך להתקין את Gemini Enterprise Agent Platform SDK בשפה שלכם ואת ספריית Protocol Buffers. בדוגמאות הקוד נעשה שימוש בפונקציות מהספרייה של מאגרי אחסון לפרוטוקולים כדי להמיר את מילון הקלט לפורמט JSON שה-API מצפה לו.

במחשב המקומי, לוחצים על אחת מהכרטיסיות הבאות כדי להתקין את ה-SDK עבור שפת התכנות שלכם.

Python

במחשב המקומי, לוחצים על אחת מהכרטיסיות הבאות כדי להתקין את ה-SDK בשפת התכנות הרצויה.

  • כדי להתקין ולעדכן את Agent Platform SDK for Python, מריצים את הפקודה הבאה.

    pip3 install --upgrade "google-cloud-aiplatform>=1.64"
  • מריצים את הפקודה הבאה כדי להתקין את ספריית Protocol Buffers ל-Python.

    pip3 install --upgrade "protobuf>=5.28"

Node.js

כדי להתקין או לעדכן את aiplatform SDK for Node.js, מריצים את הפקודה הבאה.

npm install @google-cloud/aiplatform

Java

כדי להוסיף את google-cloud-aiplatform כתלות, מוסיפים את הקוד המתאים לסביבה שלכם.

‫Maven עם BOM

מוסיפים את קוד ה-HTML הבא לקובץ pom.xml:

<dependencyManagement>
<dependencies>
  <dependency>
    <artifactId>libraries-bom</artifactId>
    <groupId>com.google.cloud</groupId>
    <scope>import</scope>
    <type>pom</type>
    <version>26.34.0</version>
  </dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-aiplatform</artifactId>
</dependency>
<dependency>
  <groupId>com.google.protobuf</groupId>
  <artifactId>protobuf-java-util</artifactId>
</dependency>
<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
</dependency>
</dependencies>

‫Maven בלי BOM

מוסיפים את השורות הבאות לקובץ pom.xml:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-aiplatform</artifactId>
  <version>1.1.0</version>
</dependency>
<dependency>
  <groupId>com.google.protobuf</groupId>
  <artifactId>protobuf-java-util</artifactId>
  <version>5.28</version>
</dependency>
<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.11.0</version>
</dependency>

‫Gradle ללא BOM

מוסיפים את הנתונים הבאים אל build.gradle:

implementation 'com.google.cloud:google-cloud-aiplatform:1.1.0'

המשך

כדי להתקין את חבילות Go האלה, מריצים את הפקודות הבאות.

go get cloud.google.com/go/aiplatform
go get google.golang.org/protobuf
go get github.com/googleapis/gax-go/v2

פריסת Gemma באמצעות Model Garden

אתם פורסים את מודל Gemma 2 2B במכונה וירטואלית מסוג ct5lp-hightpu-1t Compute Engine, שמותאמת לאימון בקנה מידה קטן עד בינוני. במכונה הזו יש מאיץ TPU v5e. מידע נוסף על אימון מודלים באמצעות TPU זמין במאמר אימון ב-Cloud TPU v5e.

במדריך הזה נסביר איך לפרוס את מודל Gemma 2 2B בקוד פתוח שעבר כוונון לפי הוראות, באמצעות כרטיס המודל ב-Model Garden. גרסת המודל הספציפית היא gemma2-2b-it-it מייצג כוונון לפי הוראות.

למודל Gemma 2 2B יש גודל פרמטרים קטן יותר, מה שאומר שדרישות המשאבים נמוכות יותר והגמישות בפריסה גבוהה יותר.

  1. נכנסים לדף Model Garden במסוף Google Cloud .

    כניסה ל-Model Garden

  2. לוחצים על כרטיס המודל Gemma 2.

    מעבר אל Gemma 2

  3. לוחצים על Deploy (פריסה) כדי לפתוח את החלונית Deploy model (פריסת מודל).

  4. בחלונית Deploy model (פריסת המודל), מציינים את הפרטים הבאים.

    1. בקטע סביבת פריסה, לוחצים על Agent Platform.

    2. בקטע Deploy model (פריסת מודל):

      1. בשדה מזהה המשאב, בוחרים באפשרות gemma-2b-it.

      2. בקטעים Model name ו-Endpoint name, מאשרים את ערכי ברירת המחדל. לדוגמה:

        • שם הדגם: gemma2-2b-it-1234567891234
        • שם נקודת הקצה: gemma2-2b-it-mg-one-click-deploy

        רושמים את שם נקודת הקצה. תצטרכו אותו כדי למצוא את מזהה נקודת הקצה שמשמש בדוגמאות הקוד.

    3. בקטע הגדרות הפריסה:

      1. מאשרים את אפשרות ברירת המחדל להגדרות בסיסיות.

      2. בשדה Region (אזור), מאשרים את ערך ברירת המחדל או בוחרים אזור מהרשימה. רושמים את האזור. תצטרכו אותו לדוגמאות הקוד.

      3. בקטע Machine spec, בוחרים את המכונה הווירטואלית עם TPU: ct5lp-hightpu-1t (1 TPU_V5_LITEPOD; ct5lp-hightpu-1t).

  5. לוחצים על פריסה. בסיום הפריסה, תקבלו אימייל עם פרטים על נקודת הקצה החדשה. אפשר גם לראות את פרטי נקודת הקצה בלחיצה על Online prediction > Endpoints (חיזוי אונליין > נקודות קצה) ובחירה באזור.

    לדף Endpoints

הסקת מסקנות של Gemma 2 2B באמצעות PredictionServiceClient

אחרי שמפעילים את Gemma 2 2B, משתמשים ב-PredictionServiceClient כדי לקבל תחזיות אונליין להנחיה: "למה השמיים כחולים?"

פרמטרים של קוד

בדוגמאות הקוד של PredictionServiceClient צריך לעדכן את הפרטים הבאים.

  • PROJECT_ID: כדי למצוא את מזהה הפרויקט, פועלים לפי השלבים הבאים.

    1. נכנסים לדף Welcome במסוף Google Cloud .

      מעבר לדף Welcome

    2. בוחרים את הפרויקט מתוך כלי לבחירת פרויקטים בחלק העליון של הדף.

      שם הפרויקט, מספר הפרויקט ומזהה הפרויקט מופיעים אחרי הכותרת Welcome.

  • ENDPOINT_REGION: האזור שבו פרסתם את נקודת הקצה.

  • ENDPOINT_ID: כדי למצוא את מזהה נקודת הקצה, אפשר לראות אותו במסוף או להריץ את הפקודה gcloud ai endpoints list. תצטרכו את שם נקודת הקצה והאזור מהחלונית Deploy model.

    המסוף

    כדי לראות את הפרטים של נקודת הקצה, לוחצים על Online prediction (חיזוי אונליין) > Endpoints (נקודות קצה) ובוחרים את האזור. שימו לב למספר שמופיע בעמודה ID.

    לדף Endpoints

    gcloud

    כדי לראות את פרטי נקודת הקצה, מריצים את הפקודה gcloud ai endpoints list.

    gcloud ai endpoints list \
      --region=ENDPOINT_REGION \
      --filter=display_name=ENDPOINT_NAME
    

    הפלט אמור להיראות כך:

    Using endpoint [https://us-central1-aiplatform.googleapis.com/]
    ENDPOINT_ID: 1234567891234567891
    DISPLAY_NAME: gemma2-2b-it-mg-one-click-deploy
    

קוד לדוגמה

בקוד לדוגמה בשפה שלכם, מעדכנים את PROJECT_ID, ENDPOINT_REGION ו-ENDPOINT_ID. לאחר מכן מריצים את הקוד.

Python

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

"""
Sample to run inference on a Gemma2 model deployed to a Vertex AI endpoint with TPU accellerators.
"""

from google.cloud import aiplatform
from google.protobuf import json_format
from google.protobuf.struct_pb2 import Value

# TODO(developer): Update & uncomment lines below
# PROJECT_ID = "your-project-id"
# ENDPOINT_REGION = "your-vertex-endpoint-region"
# ENDPOINT_ID = "your-vertex-endpoint-id"

# Default configuration
config = {"max_tokens": 1024, "temperature": 0.9, "top_p": 1.0, "top_k": 1}

# Prompt used in the prediction
prompt = "Why is the sky blue?"

# Encapsulate the prompt in a correct format for TPUs
# Example format: [{'prompt': 'Why is the sky blue?', 'temperature': 0.9}]
input = {"prompt": prompt}
input.update(config)

# Convert input message to a list of GAPIC instances for model input
instances = [json_format.ParseDict(input, Value())]

# Create a client
api_endpoint = f"{ENDPOINT_REGION}-aiplatform.googleapis.com"
client = aiplatform.gapic.PredictionServiceClient(
    client_options={"api_endpoint": api_endpoint}
)

# Call the Gemma2 endpoint
gemma2_end_point = (
    f"projects/{PROJECT_ID}/locations/{ENDPOINT_REGION}/endpoints/{ENDPOINT_ID}"
)
response = client.predict(
    endpoint=gemma2_end_point,
    instances=instances,
)
text_responses = response.predictions
print(text_responses[0])

Node.js

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

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

// Imports the Google Cloud Prediction Service Client library
const {
  // TODO(developer): Uncomment PredictionServiceClient before running the sample.
  // PredictionServiceClient,
  helpers,
} = require('@google-cloud/aiplatform');
/**
 * TODO(developer): Update these variables before running the sample.
 */
const projectId = 'your-project-id';
const endpointRegion = 'your-vertex-endpoint-region';
const endpointId = 'your-vertex-endpoint-id';

// Prompt used in the prediction
const prompt = 'Why is the sky blue?';

// Encapsulate the prompt in a correct format for TPUs
// Example format: [{prompt: 'Why is the sky blue?', temperature: 0.9}]
const input = {
  prompt,
  // Parameters for default configuration
  maxOutputTokens: 1024,
  temperature: 0.9,
  topP: 1.0,
  topK: 1,
};

// Convert input message to a list of GAPIC instances for model input
const instances = [helpers.toValue(input)];

// TODO(developer): Uncomment apiEndpoint and predictionServiceClient before running the sample.
// const apiEndpoint = `${endpointRegion}-aiplatform.googleapis.com`;

// Create a client
// predictionServiceClient = new PredictionServiceClient({apiEndpoint});

// Call the Gemma2 endpoint
const gemma2Endpoint = `projects/${projectId}/locations/${endpointRegion}/endpoints/${endpointId}`;

const [response] = await predictionServiceClient.predict({
  endpoint: gemma2Endpoint,
  instances,
});

const predictions = response.predictions;
const text = predictions[0].stringValue;

console.log('Predictions:', text);

Java

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

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


import com.google.cloud.aiplatform.v1.EndpointName;
import com.google.cloud.aiplatform.v1.PredictResponse;
import com.google.cloud.aiplatform.v1.PredictionServiceClient;
import com.google.cloud.aiplatform.v1.PredictionServiceSettings;
import com.google.gson.Gson;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Value;
import com.google.protobuf.util.JsonFormat;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Gemma2PredictTpu {
  private final PredictionServiceClient predictionServiceClient;

  // Constructor to inject the PredictionServiceClient
  public Gemma2PredictTpu(PredictionServiceClient predictionServiceClient) {
    this.predictionServiceClient = predictionServiceClient;
  }

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String endpointRegion = "us-west1";
    String endpointId = "YOUR_ENDPOINT_ID";

    PredictionServiceSettings predictionServiceSettings =
        PredictionServiceSettings.newBuilder()
            .setEndpoint(String.format("%s-aiplatform.googleapis.com:443", endpointRegion))
            .build();
    PredictionServiceClient predictionServiceClient =
        PredictionServiceClient.create(predictionServiceSettings);
    Gemma2PredictTpu creator = new Gemma2PredictTpu(predictionServiceClient);

    creator.gemma2PredictTpu(projectId, endpointRegion, endpointId);
  }

  // Demonstrates how to run inference on a Gemma2 model
  // deployed to a Vertex AI endpoint with TPU accelerators.
  public String gemma2PredictTpu(String projectId, String region,
           String endpointId) throws IOException {
    Map<String, Object> paramsMap = new HashMap<>();
    paramsMap.put("temperature", 0.9);
    paramsMap.put("maxOutputTokens", 1024);
    paramsMap.put("topP", 1.0);
    paramsMap.put("topK", 1);
    Value parameters = mapToValue(paramsMap);
    // Prompt used in the prediction
    String instance = "{ \"prompt\": \"Why is the sky blue?\"}";
    Value.Builder instanceValue = Value.newBuilder();
    JsonFormat.parser().merge(instance, instanceValue);
    // Encapsulate the prompt in a correct format for TPUs
    // Example format: [{'prompt': 'Why is the sky blue?', 'temperature': 0.9}]
    List<Value> instances = new ArrayList<>();
    instances.add(instanceValue.build());

    EndpointName endpointName = EndpointName.of(projectId, region, endpointId);

    PredictResponse predictResponse = this.predictionServiceClient
        .predict(endpointName, instances, parameters);
    String textResponse = predictResponse.getPredictions(0).getStringValue();
    System.out.println(textResponse);
    return textResponse;
  }

  private static Value mapToValue(Map<String, Object> map) throws InvalidProtocolBufferException {
    Gson gson = new Gson();
    String json = gson.toJson(map);
    Value.Builder builder = Value.newBuilder();
    JsonFormat.parser().merge(json, builder);
    return builder.build();
  }
}

Go

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

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

import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/aiplatform/apiv1/aiplatformpb"

	"google.golang.org/protobuf/types/known/structpb"
)

// predictTPU demonstrates how to run interference on a Gemma2 model deployed to a Vertex AI endpoint with TPU accelerators.
func predictTPU(w io.Writer, client PredictionsClient, projectID, location, endpointID string) error {
	ctx := context.Background()

	// Note: client can be initialized in the following way:
	// apiEndpoint := fmt.Sprintf("%s-aiplatform.googleapis.com:443", location)
	// client, err := aiplatform.NewPredictionClient(ctx, option.WithEndpoint(apiEndpoint))
	// if err != nil {
	// 	return fmt.Errorf("unable to create prediction client: %v", err)
	// }
	// defer client.Close()

	gemma2Endpoint := fmt.Sprintf("projects/%s/locations/%s/endpoints/%s", projectID, location, endpointID)
	prompt := "Why is the sky blue?"
	parameters := map[string]interface{}{
		"temperature":     0.9,
		"maxOutputTokens": 1024,
		"topP":            1.0,
		"topK":            1,
	}

	// Encapsulate the prompt in a correct format for TPUs.
	// Example format: [{'prompt': 'Why is the sky blue?', 'temperature': 0.9}]
	promptValue, err := structpb.NewValue(map[string]interface{}{
		"prompt":     prompt,
		"parameters": parameters,
	})
	if err != nil {
		fmt.Fprintf(w, "unable to convert prompt to Value: %v", err)
		return err
	}

	req := &aiplatformpb.PredictRequest{
		Endpoint:  gemma2Endpoint,
		Instances: []*structpb.Value{promptValue},
	}

	resp, err := client.Predict(ctx, req)
	if err != nil {
		return err
	}

	prediction := resp.GetPredictions()
	value := prediction[0].GetStringValue()
	fmt.Fprintf(w, "%v", value)

	return nil
}

הסרת המשאבים

כדי להימנע מחיובים בחשבון Google Cloud בגלל השימוש במשאבים שנעשה במסגרת המדריך הזה, אפשר למחוק את הפרויקט שמכיל את המשאבים, או להשאיר את הפרויקט ולמחוק את המשאבים בנפרד.

מחיקת הפרויקט

  1. במסוף Google Cloud , נכנסים לדף Manage resources.

    כניסה לדף Manage resources

  2. ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על Delete.
  3. כדי למחוק את הפרויקט, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down.

מחיקת משאבים בודדים

אם אתם רוצים לשמור את הפרויקט, אתם צריכים למחוק את המשאבים שבהם השתמשתם במדריך הזה:

  • ביטול הפריסה של המודל ומחיקת נקודת הקצה
  • מחיקת המודל ממרשם המודלים

ביטול הפריסה של המודל ומחיקת נקודת הקצה

כדי לבטל את הפריסה של מודל ולמחוק את נקודת הקצה, אפשר להשתמש באחת מהשיטות הבאות.

המסוף

  1. במסוף Google Cloud , לוחצים על חיזוי מיידי ואז על נקודות קצה.

    כניסה לדף Endpoints

  2. בתפריט הנפתח Region, בוחרים את האזור שבו פרסתם את נקודת הקצה.

  3. לוחצים על שם נקודת הקצה כדי לפתוח את דף הפרטים. לדוגמה: gemma2-2b-it-mg-one-click-deploy.

  4. בשורה של מודל Gemma 2 (Version 1), לוחצים על Actions ואז על Undeploy model from endpoint.

  5. בתיבת הדו-שיח Undeploy model from endpoint (ביטול הפריסה של המודל מנקודת הקצה), לוחצים על Undeploy (ביטול הפריסה).

  6. לוחצים על הלחצן הקודם כדי לחזור לדף Endpoints.

    כניסה לדף Endpoints

  7. בסוף השורה gemma2-2b-it-mg-one-click-deploy, לוחצים על Actions (פעולות) ואז בוחרים באפשרות Delete endpoint (מחיקת נקודת קצה).

  8. בהודעת האישור, לוחצים על אישור.

gcloud

כדי לבטל את הפריסה של המודל ולמחוק את נקודת הקצה באמצעות Google Cloud CLI, פועלים לפי השלבים הבאים.

בפקודות האלה, מחליפים את:

  • PROJECT_ID בשם הפרויקט
  • LOCATION_ID עם האזור שבו פרסתם את המודל ואת נקודת הקצה
  • ENDPOINT_ID עם מזהה נקודת הקצה
  • DEPLOYED_MODEL_NAME עם השם המוצג של המודל
  • DEPLOYED_MODEL_ID עם מזהה המודל
  1. מריצים את הפקודה gcloud ai endpoints list כדי לקבל את מזהה נקודת הקצה. הפקודה הזו מציגה רשימה של מזהי נקודות הקצה של כל נקודות הקצה בפרויקט. חשוב לשים לב למזהה של נקודת הקצה שבה נעשה שימוש במדריך הזה.

    gcloud ai endpoints list \
        --project=PROJECT_ID \
        --region=LOCATION_ID
    

    הפלט אמור להיראות כך: בפלט, המזהה נקרא ENDPOINT_ID.

    Using endpoint [https://us-central1-aiplatform.googleapis.com/]
    ENDPOINT_ID: 1234567891234567891
    DISPLAY_NAME: gemma2-2b-it-mg-one-click-deploy
    
  2. מריצים את הפקודה gcloud ai models describe כדי לקבל את מזהה המודל. רושמים בצד את המזהה של המודל שפרסתם במדריך הזה.

    gcloud ai models describe DEPLOYED_MODEL_NAME \
        --project=PROJECT_ID \
        --region=LOCATION_ID
    

    הפלט המקוצר נראה כך: בפלט, המזהה נקרא deployedModelId.

    Using endpoint [https://us-central1-aiplatform.googleapis.com/]
    artifactUri: [URI removed]
    baseModelSource:
      modelGardenSource:
        publicModelName: publishers/google/models/gemma2
    ...
    deployedModels:
    - deployedModelId: '1234567891234567891'
      endpoint: projects/12345678912/locations/us-central1/endpoints/12345678912345
    displayName: gemma2-2b-it-12345678912345
    etag: [ETag removed]
    modelSourceInfo:
      sourceType: MODEL_GARDEN
    name: projects/123456789123/locations/us-central1/models/gemma2-2b-it-12345678912345
    ...
    
  3. מבטלים את הפריסה של המודל מנקודת הקצה. תצטרכו את מזהה נקודת הקצה ואת מזהה המודל מהפקודות הקודמות.

    gcloud ai endpoints undeploy-model ENDPOINT_ID \
        --project=PROJECT_ID \
        --region=LOCATION_ID \
        --deployed-model-id=DEPLOYED_MODEL_ID
    

    הפקודה הזו לא יוצרת פלט.

  4. מריצים את הפקודה gcloud ai endpoints delete כדי למחוק את נקודת הקצה.

    gcloud ai endpoints delete ENDPOINT_ID \
        --project=PROJECT_ID \
        --region=LOCATION_ID
    

    כשמופיעה בקשה, מקלידים y כדי לאשר. הפקודה הזו לא יוצרת פלט.

מחיקת המודל

המסוף

  1. עוברים לדף מרשם המודלים בקטע Agent Platform במסוף Google Cloud .

    כניסה לדף Model Registry

  2. בתפריט הנפתח Region, בוחרים את האזור שבו פרסתם את המודל.

  3. בסוף השורה gemma2-2b-it-1234567891234, לוחצים על פעולות.

  4. בוחרים באפשרות מחיקת המודל.

    כשמוחקים את המודל, כל הגרסאות וההערכות שמשויכות אליו נמחקות מהפרויקט Google Cloud .

  5. בהודעת האישור, לוחצים על מחיקה.

gcloud

כדי למחוק את המודל באמצעות Google Cloud CLI, צריך להזין את שם התצוגה והאזור של המודל בפקודה gcloud ai models delete.

gcloud ai models delete DEPLOYED_MODEL_NAME \
    --project=PROJECT_ID \
    --region=LOCATION_ID

מחליפים את DEPLOYED_MODEL_NAME בשם לתצוגה של המודל. מחליפים את PROJECT_ID בשם הפרויקט. מחליפים את LOCATION_ID באזור שבו פרסתם את המודל.

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