ניהול גרסאות של מודלים באמצעות מרשם המודלים

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

ייבוא של גרסת מודל חדשה

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

המסוף

  1. במסוף Google Cloud , עוברים לדף מרשם המודלים.
    מעבר למרשם המודלים
  2. בחלק העליון של הדף, לוחצים על ייבוא.
  3. בוחרים באפשרות ייבוא כגרסה חדשה.
  4. בתפריט הנפתח, בוחרים את המודל שזו גרסה חדשה שלו. מוסיפים תיאור אופציונלי של הגרסה.
  5. אפשר גם להגדיר את המודל הזה כגרסת ברירת המחדל. גרסת ברירת המחדל נבחרת מראש בכל פעם שהמודל משמש לחיזוי (אבל עדיין אפשר לבחור גרסאות אחרות).
  6. בוחרים את האזור.
  7. לוחצים על המשך.
  8. בהגדרות המודל, מגדירים את מאגר התגים שרוצים להשתמש בו. אתם יכולים לבחור לייבא ארטיפקטים של מודלים למאגר חדש שנוצר מראש, או לייבא אותם למאגר מותאם אישית קיים. מידע נוסף על מאגרי תגים זמין במאמר ייבוא מודלים ל-Agent Platform.
  9. לוחצים על המשך.
  10. אופציונלי: מוסיפים תמיכה בהסבר של המודל.
  11. לוחצים על ייבוא.

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • PROJECT_ID: מזהה הפרויקט.
  • LOCATION: המיקום.
  • MODEL_DISPLAY_NAME: שם המודל.
  • ARTIFACT_URI: הנתיב לספרייה שמכילה את ארטיפקט המודל ואת כל קובצי התמיכה שלו.
  • IMAGE_URI: קובץ אימג' של Docker שישמש כקונטיינר בהתאמה אישית להצגת תחזיות.
  • PARENT_MODEL: שם המשאב של המודל שאליו רוצים להעלות את הגרסה.

ה-method של ה-HTTP וכתובת ה-URL:

POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/models:upload

תוכן בקשת JSON:

{

  "model": {
    "displayName": "MODEL_DISPLAY_NAME",
    "artifactUri": "ARTIFACT_URI",
    "containerSpec": {
       "imageUri": "IMAGE_URI"
    }
   },
 "parentModel": "PARENT_MODEL"
}

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

אמורים לקבל קוד סטטוס של הצלחה (2xx) ותגובה ריקה.

Python

Python


from typing import List

from google.cloud import aiplatform


def upload_new_model_version_using_custom_training_pipeline(
    display_name: str,
    script_path: str,
    container_uri,
    model_serving_container_image_uri: str,
    dataset_id: str,
    replica_count: int,
    machine_type: str,
    accelerator_type: str,
    accelerator_count: int,
    parent_model: str,
    args: List[str],
    model_version_aliases: List[str],
    model_version_description: str,
    is_default_version: bool,
    project: str,
    location: str,
):
    """
    Uploads a new model version using a custom training pipeline.
    Args:
        display_name: The display name of the model version.
        script_path: The path to the Python script that trains the model.
        container_uri: The URI of the container to use for training.
        model_serving_container_image_uri: The URI of the serving container image to use.
        dataset_id: The ID of the dataset to use for training.
        replica_count: The number of replicas to use for training.
        machine_type: The machine type to use for training.
        accelerator_type: The accelerator type to use for training.
        accelerator_count: The number of accelerators to use for training.
        parent_model: The parent resource name of an existing model.
        args: A list of arguments to pass to the training script.
        model_version_aliases: The aliases of the model version to create.
        model_version_description: The description of the model version.
        is_default_version: Whether the model version is the default version.
        project: The project ID.
        location: The region name.
    Returns:
        The new version of the model.
    """
    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Create the training job.
    # This job will upload a new, non-default version of the my-training-job model
    job = aiplatform.CustomTrainingJob(
        display_name=display_name,
        script_path=script_path,
        container_uri=container_uri,
        model_serving_container_image_uri=model_serving_container_image_uri,
    )

    # Create dataset
    # This examples uses a TabularDataset, but you can use any dataset type.
    dataset = aiplatform.TabularDataset(dataset_id) if dataset_id else None

    # Run the training job.
    model = job.run(
        dataset=dataset,
        args=args,
        replica_count=replica_count,
        machine_type=machine_type,
        accelerator_type=accelerator_type,
        accelerator_count=accelerator_count,
        parent_model=parent_model,
        model_version_aliases=model_version_aliases,
        model_version_description=model_version_description,
        is_default_version=is_default_version,
    )

    return model

אימון גרסה חדשה של המודל

ממאגר המודלים אפשר לאמן גרסה חדשה של מודל.

המסוף

ממאגר המודלים אפשר ליצור גרסה של מודל קיים. מידע נוסף על הוספה או יצירה של גרסת מודל בצינור האימון זמין במאמר CustomJob והעלאת מודל

  1. במסוף Google Cloud , עוברים לדף מרשם המודלים.
    מעבר למרשם המודלים
  2. בחלק העליון של הדף, לוחצים על יצירה. מזינים את פרטי שיטת האימון ובוחרים את שיטת אימון המודל.
  3. לוחצים על Continue.
  4. בקטע Model details (פרטי המודל), בוחרים באפשרות Train new version (אימון גרסה חדשה). בתפריט הנפתח בוחרים את המודל שאליו רוצים להוסיף גרסה חדשה. מוסיפים תיאור של הגרסה. לוחצים על Continue.
  5. בקטע Compute and pricing (חישוב וחיוב), מזינים את התקציב ובוחרים באפשרות Start training (התחלת האימון) כשמוכנים. כשהאימון של המודל מסתיים, הגרסה החדשה שלו מופיעה במאגר המודלים.

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • TRAINING_PIPELINE_NAME: שם תצוגה ל-trainingPipeline
  • TRAINING_TASK_INPUT: הפרמטרים של משימת האימון.
  • PARENT_MODEL: שם המשאב של המודל שאליו רוצים להעלות את הגרסה.

ה-method של ה-HTTP וכתובת ה-URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/trainingPipelines

תוכן בקשת JSON:

{
  "displayName": "TRAINING_PIPELINE_NAME",
  "trainingTaskDefinition": "gs://google-cloud-aiplatform/schema/trainingjob/definition/custom_task_1.0.0.yaml",
  "trainingTaskInputs":"TRAINING_TASK_INPUT"
  },
  "modelToUpload": {
    "displayName": "MODEL_DISPLAY_NAME",
    "containerSpec": {
       "imageUri": "IMAGE_URI"
    },
  },
  "parentModel": "PARENT_MODEL",

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

אמורים לקבל קוד סטטוס של הצלחה (2xx) ותגובה ריקה.

Python

Python


from google.cloud import aiplatform


def create_default_model_sample(model_id: str, project: str, location: str):
    """
    Initialize a Model resource to represent an existing model version with alias 'default'.
    Args:
        model_id: The ID of the model to initialize. Parent resource name of the model is also accepted.
        project: The project ID.
        location: The region name.
    Returns:
        Model resource.
    """
    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Initialize the Model resource with the ID 'model_id'. The parent_name of the Model resource can be also
    # 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
    default_model = aiplatform.Model(model_name=model_id)

    return default_model

איך רואים רשימה של כל הגרסאות של מודל

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

המסוף

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

  1. במסוף Google Cloud , עוברים לדף מרשם המודלים.
    מעבר למרשם המודלים
  2. בעמודה Name (שם), בוחרים את השם של מודל שיש לו כמה גרסאות. ייפתח הדף 'גרסאות'.
  3. מוצגת רשימה של כל הגרסאות ומזהי הגרסאות שמשויכים אליהן.

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • PROJECT_ID: מזהה הפרויקט שמשויך למודל הזה
  • LOCATION: האזור שבו משתמשים ב-Agent Platform.
  • MODEL_ID: המזהה שמשויך למודל ספציפי.

ה-method של ה-HTTP וכתובת ה-URL:

GET https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/models/MODEL_ID

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

אמורים לקבל קוד סטטוס של הצלחה (2xx) ותגובה ריקה.

Python

Python


from google.cloud import aiplatform


def list_model_versions_sample(model_id: str, project: str, location: str):
    """
    List all model versions of a model.
    Args:
        model_id: The ID of the model to list. Parent resource name of the model is also accepted.
        project: The project ID.
        location: The region name.
    Returns:
        versions: List of model versions.
    """
    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also
    # 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
    model_registry = aiplatform.models.ModelRegistry(model=model_id)

    # List all model versions of the model.
    versions = model_registry.list_versions()

    return versions

איך מציגים פרטים על גרסת המודל

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

המסוף

כדי להציג את דף הפרטים של המודל: כדי לראות את פרטי הגרסה, לוחצים על שם הגרסה.

  1. במסוף Google Cloud , עוברים לדף מרשם המודלים.
    מעבר למרשם המודלים
  2. ממאגר המודלים של Gemini Enterprise Agent Platform, לוחצים על שם של מודל כדי לפתוח את דף הפרטים שלו.
  3. תוצג רשימה של כל הגרסאות ומזהי הגרסאות שמשויכים אליהן. גרסאות המודל מוצגות בשורות נפרדות. פרטי גרסת המודל כוללים את מזהה הגרסה, הכינוי של המודל, הסטטוס, התיאור והתוויות.
  4. כדי לראות את הפרטים של אחת מגרסאות המודל, בוחרים מזהה גרסה. נפתח דף הפרטים של המודל
  5. בדף הפרטים אפשר להעריך, לפרוס ולבדוק, להשתמש בחיזוי אצווה ולעיין בפרטי הגרסה. בנוסף, בדף הזה אפשר להשתמש ב הערכת מודלים ב-Agent Platform כדי להשוות בין גרסאות המודל.

Python

Python


from google.cloud import aiplatform


def get_model_version_info_sample(
    model_id: str, version_id: str, project: str, location: str
):
    """
    Get model version info.
    Args:
        model_id: The ID of the model.
        version_id: The version ID of the model version.
        project: The project ID.
        location: The region name.
    Returns:
        VersionInfo resource.
    """

    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also
    # 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
    model_registry = aiplatform.models.ModelRegistry(model=model_id)

    # Get model version info with the version 'version_id'.
    model_version_info = model_registry.get_version_info(version=version_id)

    return model_version_info