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

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

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

מטרות

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

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

חסרונות

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

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

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

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

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

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

  • הגדרת פרויקט ב- Google Cloud והפעלת Agent Platform API
  • במכונה המקומית:
    • התקנה, הפעלה ואימות באמצעות 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, if it is not already enabled.

    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, if it is not already enabled.

    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 לשפה שלכם ואת ספריית מאגרי האחסון לפרוטוקולים. דוגמאות הקוד משתמשות בפונקציות מספריית מאגר האחסון לפרוטוקולים כדי להמיר את מילון הקלט לפורמט JSON שנדרש על ידי ה-API.

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

Python

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

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

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

    pip3 install --upgrade "protobuf>=5.28"

Node.js

מתקינים או מעדכנים את ה-SDK של aiplatform ל-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 מייצג instruction-tuned (כוונון לפי הוראות).

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

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

    כניסה ל-Model Garden

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

    מעבר אל Gemma 2

  3. לוחצים על Deploy כדי לפתוח את החלונית Deploy model.

  4. מציינים את הפרטים הבאים בחלונית Deploy model:

    1. בקטע Deployment environment, לוחצים על Agent Platform.

    2. בקטע Deploy model:

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

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

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

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

    3. בקטע Deployment settings:

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

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

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

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

    כניסה לדף Endpoints

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

אחרי שפורסים את Gemma 2 2B, משתמשים ב-PredictionServiceClient כדי לקבל חיזויים אונליין להנחיה: "Why is the sky blue?‎" (למה השמיים כחולים?)

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

בדוגמאות הקוד של 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. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.

"""
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.

מחיקת משאבים ספציפיים

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

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

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

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

המסוף

  1. במסוף Google Cloud , לוחצים על Online prediction ואז על Endpoints.

    כניסה לדף 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 במזהה נקודת הקצה (endpoint)
  • ‫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. במסוף Google Cloud , בקטע Agent Platform, נכנסים לדף Model Registry.

    כניסה לדף Model Registry

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

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

  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 באזור שבו פרסתם את המודל.

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