הצגת מודלים פתוחים של Gemma באמצעות מעבדים גרפיים ב-GKE עם vLLM

כדי להכניס לשימוש בסביבת הייצור מודלי שפה גדולים (LLM) של Gemma 4 ב-Google Kubernetes Engine‏ (GKE) באמצעות ה-framework של vLLM עם GPUs, צריך להקצות אשכול GKE עם מאיצים נתמכים, כמו NVIDIA B200,‏ H100,‏ RTX Pro 6000 או L4 GPUs.

כדי לקבל את משקלי המודל של Gemma 4, אפשר להגדיר את קובץ ה-container של vLLM שנבנה מראש כך שיוריד אותם ממאגר Hugging Face. לחלופין, הקונטיינר יכול לטעון משקלים של מודלים מאחסון קבוע קיים – למשל, על ידי שמירת קטגוריות של מודלים ב-Cloud Storage במטמון במופע מנוהל של Lustre ב-Google Cloud.

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

המדריך הזה מיועד למהנדסי למידת מכונה (ML), לאדמינים ולאופרטורים של פלטפורמות ולמומחי נתונים ו-AI שרוצים להשתמש ביכולות של Kubernetes לניהול קונטיינרים כדי להפעיל עומסי עבודה של AI/ML בחומרת GPU מסוג H200,‏ H100,‏ A100 ו-L4. כדי לקבל מידע נוסף על תפקידים נפוצים ועל משימות לדוגמה שאנחנו מתייחסים אליהן ב Google Cloud תוכן, אפשר לעיין במאמר תפקידי משתמשים נפוצים ומשימות ב-GKE.

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

לפני שקוראים את הדף הזה, חשוב לוודא שמכירים את הנושאים הבאים:

רקע

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

יחידות GPU

מעבדי GPU מאפשרים להאיץ עומסי עבודה ספציפיים שפועלים בצמתים, כמו למידת מכונה ועיבוד נתונים. ‫GKE מספק מגוון אפשרויות של סוגי מכונות להגדרת צמתים, כולל סוגי מכונות עם מעבדי GPU של NVIDIA H200,‏ H100,‏ L4 ו-A100.

vLLM

‫vLLM הוא פריימוורק קוד פתוח לאירוח מודלים גדולים של שפה (LLM) שעבר אופטימיזציה גבוהה, ויכול לשפר את קצב העברת הנתונים של אירוח מודלים ביחידות GPU. הוא כולל תכונות כמו:

  • הטמעה אופטימלית של טרנספורמציה באמצעות PagedAttention
  • הוספת תכונה של אצווה מתמשכת כדי לשפר את התפוקה הכוללת של הצגת המודעות
  • מקביליות טנסורים והצגה מבוזרת במספר יחידות GPU

מידע נוסף מופיע במאמרי העזרה בנושא vLLM.

מטרות

המדריך הזה מספק בסיס להבנה ולבדיקה של פריסת מודלים גדולים של שפה (LLM) למסקנות בסביבת Kubernetes מנוהלת.

  1. מכינים את הסביבה עם אשכול GKE במצב Autopilot או Standard.
  2. פורסים קונטיינר vLLM לאשכול.
  3. שימוש ב-vLLM כדי להכניס לשימוש בסביבת הייצור את מודל Gemma 4 באמצעות curl וממשק צ'אט באינטרנט.

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

  • נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  • 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

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

  • Enable the required API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  • 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

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

  • Enable the required API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  • צריך לוודא שיש לכם בפרויקט את התפקיד או התפקידים הבאים: roles/container.admin, roles/iam.serviceAccountAdmin

    בדיקת התפקידים

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

      כניסה לדף IAM
    2. בוחרים את הפרויקט.
    3. בעמודה Principal (חשבון המשתמש), מוצאים את כל השורות שבהן מופיע השם שלכם או של קבוצה שאתם נכללים בה. כדי לברר באילו קבוצות אתם נכללים, פנו לאדמין.

    4. בודקים את העמודה Role בכל השורות שבהן מצוין או מופיע השם שלכם, כדי לראות אם רשימת התפקידים כוללת את התפקידים הנדרשים.

    מתן התפקידים

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

      כניסה לדף IAM
    2. בוחרים את הפרויקט.
    3. לוחצים על Grant access.
    4. בשדה New principals, מזינים את מזהה המשתמש. ‫ בדרך כלל מזהה המשתמש הוא כתובת האימייל של חשבון Google.

    5. לוחצים על Select a role ומחפשים את התפקיד.
    6. כדי לתת עוד תפקידים, לוחצים על Add another role ומוסיפים אותם.
    7. לוחצים על Save.

הכנת הסביבה

במדריך הזה משתמשים ב-Cloud Shell כדי לנהל משאבים שמתארחים ב-Google Cloud. ב-Cloud Shell מותקנת מראש התוכנה שדרושה לכם כדי לבצע את ההדרכה הזו, כולל kubectl ו-ה-CLI של gcloud.

כדי להגדיר את הסביבה באמצעות Cloud Shell:

  1. ב Google Cloud מסוף, מפעילים סשן של Cloud Shell על ידי לחיצה על Activate Cloud Shell בGoogle Cloud מסוף.סמל ההפעלה של Cloud Shell תופעל סשן בחלונית התחתונה של Google Cloud המסוף.

  2. מגדירים את משתני הסביבה שמוגדרים כברירת מחדל:

    gcloud config set project PROJECT_ID
    gcloud config set billing/quota_project PROJECT_ID
    export PROJECT_ID=$(gcloud config get project)
    export REGION=REGION
    export ZONE=ZONE
    export CLUSTER_NAME=CLUSTER_NAME
    

    מחליפים את הערכים הבאים:

יצירה והגדרה של Google Cloud משאבים

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

יצירת אשכול GKE ומאגר צמתים

אפשר להפעיל את Gemma במעבדים גרפיים באשכול GKE Autopilot או באשכול רגיל. מומלץ להשתמש באשכול Autopilot כדי ליהנות מחוויית Kubernetes מנוהלת באופן מלא. כדי לבחור את מצב הפעולה של GKE שהכי מתאים לעומסי העבודה שלכם, אפשר לעיין במאמר בחירת מצב פעולה של GKE.

טייס אוטומטי

ב-Cloud Shell, מריצים את הפקודה הבאה:

gcloud container clusters create-auto CLUSTER_NAME \
    --project=PROJECT_ID \
    --location=CONTROL_PLANE_LOCATION \
    --release-channel=rapid

מחליפים את הערכים הבאים:

  • PROJECT_ID: מזהה הפרויקט ב- Google Cloud.
  • CONTROL_PLANE_LOCATION: האזור של Compute Engine במישור הבקרה של האשכול. מציינים אזור שתומך בסוג המאיץ שרוצים להשתמש בו, לדוגמה, us-central1 ל-GPU מסוג L4.
  • CLUSTER_NAME: השם של האשכול.

‫GKE יוצר אשכול Autopilot עם צמתים של מעבד ו-GPU לפי הבקשה של עומסי העבודה שנפרסו.

רגילה

  1. ב-Cloud Shell, מריצים את הפקודה הבאה כדי ליצור אשכול Standard:

    gcloud container clusters create CLUSTER_NAME \
        --project=PROJECT_ID \
        --location=CONTROL_PLANE_LOCATION \
        --workload-pool=PROJECT_ID.svc.id.goog \
        --release-channel=rapid \
        --num-nodes=1
    

    מחליפים את הערכים הבאים:

    • PROJECT_ID: מזהה הפרויקט ב- Google Cloud.
    • CONTROL_PLANE_LOCATION: האזור של Compute Engine במישור הבקרה של האשכול. מציינים אזור שתומך בסוג המאיץ שרוצים להשתמש בו, לדוגמה, us-central1 ל-GPU מסוג L4.
    • CLUSTER_NAME: השם של האשכול.

    יצירת האשכול עשויה להימשך כמה דקות.

  2. כדי ליצור מאגר צמתים לאשכול עם גודל הדיסק המתאים, מריצים את הפקודה הבאה:

      gcloud container node-pools create gpupool \
          --accelerator type=nvidia-rtx-pro-6000,count=1,gpu-driver-version=latest \
          --project=PROJECT_ID \
          --location=REGION \
          --node-locations=ZONE \
          --cluster=CLUSTER_NAME \
          --machine-type=g4-standard-48 \
          --num-nodes=1
    

    ‫GKE יוצר מאגר צמתים יחיד שמכיל RTX PRO. ‫6,000 GPU לכל צומת.

פריסת מודלים של Gemma 4 ב-vLLM באמצעות משקלים של Hugging Face

כדי לפרוס מודלים של Gemma 4 באמצעות משקלים של Hugging Face, צריך להחיל מניפסט של פריסת Kubernetes לגודל המודל שנבחר. פריסה היא אובייקט Kubernetes API שמאפשר להפעיל כמה רפליקות של Pods שמפוזרות בין הצמתים באשכול.

התהליך

הפעלת המניפסט הזה מושכת את קובץ האימג' של קונטיינר vLLM, מבקשת יחידת GPU של NVIDIA, ומורידה באופן אוטומטי את המשקלים מ-Hugging Face כדי להפעיל את מנוע ההיקש של vLLM.

Gemma 4 E2B-it

כדי לפרוס את מודל Gemma 4 E2B שעבר כוונון להוראות (קלט טקסט בלבד), פועלים לפי ההוראות האלה.

  1. יוצרים את קובץ המניפסט vllm-4-e2b-it.yaml הבא:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vllm-gemma-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: gemma-server
      template:
        metadata:
          labels:
            app: gemma-server
            ai.gke.io/model: gemma-4-e2b-it
            ai.gke.io/inference-server: vllm
            examples.ai.gke.io/source: user-guide
        spec:
          containers:
          - name: inference-server
            image: us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:gemma4
            resources:
              requests:
                cpu: "2"
                memory: "10Gi"
                ephemeral-storage: "10Gi"
                nvidia.com/gpu: "1"
              limits:
                cpu: "2"
                memory: "10Gi"
                ephemeral-storage: "10Gi"
                nvidia.com/gpu: "1"
            command: ["python3", "-m", "vllm.entrypoints.api_server"]
            args:
              - --model=$(MODEL_ID)
              - --host=0.0.0.0
              - --port=8000
              - --tensor-parallel-size=1
              - --enable-log-requests
              - --enable-chunked-prefill
              - --enable-prefix-caching
              - --enable-auto-tool-choice
              - --generation-config=auto
              - --tool-call-parser=gemma4
              - --dtype=bfloat16
              - --max-num-seqs=16
              - --max-model-len=32768
              - --gpu-memory-utilization=0.95
              - --reasoning-parser=gemma4
              - --trust-remote-code
            env:
            - name: LD_LIBRARY_PATH
              value: ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64
            - name: MODEL_ID
              value: google/gemma-4-E2B-it
            volumeMounts:
            - mountPath: /dev/shm
              name: dshm
          volumes:
          - name: dshm
            emptyDir:
                medium: Memory
          nodeSelector:
            cloud.google.com/gke-accelerator: nvidia-rtx-pro-6000
            cloud.google.com/gke-gpu-driver-version: latest
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: llm-service
    spec:
      selector:
        app: gemma-server
      type: ClusterIP
      ports:
        - protocol: TCP
          port: 8000
          targetPort: 8000
    
  2. החלת המניפסט:

    kubectl apply -f vllm-4-e2b-it.yaml
    

‫Gemma 4 E4B-it

כדי לפרוס את מודל Gemma 4 E4B שעבר כוונון להוראות, פועלים לפי ההוראות הבאות.

  1. יוצרים את קובץ המניפסט vllm-4-e4b-it.yaml הבא:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vllm-gemma-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: gemma-server
      template:
        metadata:
          labels:
            app: gemma-server
            ai.gke.io/model: gemma-4-e4b-it
            ai.gke.io/inference-server: vllm
            examples.ai.gke.io/source: user-guide
        spec:
          containers:
          - name: inference-server
            image: us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:gemma4
            resources:
              requests:
                cpu: "4"
                memory: "20Gi"
                ephemeral-storage: "20Gi"
                nvidia.com/gpu: "1"
              limits:
                cpu: "4"
                memory: "20Gi"
                ephemeral-storage: "20Gi"
                nvidia.com/gpu: "1"
            command: ["python3", "-m", "vllm.entrypoints.api_server"]
            args:
              - --model=$(MODEL_ID)
              - --host=0.0.0.0
              - --port=8000
              - --tensor-parallel-size=1
              - --enable-log-requests
              - --enable-chunked-prefill
              - --enable-prefix-caching
              - --enable-auto-tool-choice
              - --generation-config=auto
              - --tool-call-parser=gemma4
              - --dtype=bfloat16
              - --max-num-seqs=16
              - --max-model-len=32768
              - --gpu-memory-utilization=0.95
              - --reasoning-parser=gemma4
              - --trust-remote-code
            env:
            - name: LD_LIBRARY_PATH
              value: ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64
            - name: MODEL_ID
              value: google/gemma-4-E4b-it
            volumeMounts:
            - mountPath: /dev/shm
              name: dshm
          volumes:
          - name: dshm
            emptyDir:
                medium: Memory
          nodeSelector:
            cloud.google.com/gke-accelerator: nvidia-rtx-pro-6000
            cloud.google.com/gke-gpu-driver-version: latest
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: llm-service
    spec:
      selector:
        app: gemma-server
      type: ClusterIP
      ports:
        - protocol: TCP
          port: 8000
          targetPort: 8000
    
  2. החלת המניפסט:

    kubectl apply -f vllm-4-E4b-it.yaml
    

    בדוגמה שלנו, אנחנו מגבילים את חלון ההקשר ל-32 K באמצעות האפשרות --max-model-len=32768 של vLLM. אם רוצים להגדיל את גודל חלון ההקשר (עד 128K), צריך לשנות את קובץ המניפסט ואת ההגדרה של מאגר הצמתים כדי להגדיל את קיבולת ה-GPU.

Gemma 4 26B-A4B-it

כדי לפרוס את מודל Gemma 4 26B-A4B שעבר כוונון להוראות, פועלים לפי ההוראות הבאות.

  1. יוצרים את קובץ המניפסט vllm-4-26b-a4b-it.yaml הבא:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vllm-gemma-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: gemma-server
      template:
        metadata:
          labels:
            app: gemma-server
            ai.gke.io/model: gemma-4-26b-a4b-it
            ai.gke.io/inference-server: vllm
            examples.ai.gke.io/source: user-guide
        spec:
          containers:
          - name: inference-server
            image: us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:gemma4
            resources:
              requests:
                cpu: "20"
                memory: "80Gi"
                ephemeral-storage: "80Gi"
                nvidia.com/gpu: "1"
              limits:
                cpu: "20"
                memory: "80Gi"
                ephemeral-storage: "80Gi"
                nvidia.com/gpu: "1"
            command: ["python3", "-m", "vllm.entrypoints.api_server"]
            args:
              - --model=$(MODEL_ID)
              - --host=0.0.0.0
              - --port=8000
              - --tensor-parallel-size=1
              - --enable-log-requests
              - --enable-chunked-prefill
              - --enable-prefix-caching
              - --enable-auto-tool-choice
              - --generation-config=auto
              - --tool-call-parser=gemma4
              - --dtype=bfloat16
              - --max-num-seqs=16
              - --max-model-len=16384
              - --gpu-memory-utilization=0.95
              - --reasoning-parser=gemma4
              - --trust-remote-code
            env:
            - name: LD_LIBRARY_PATH
              value: ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64
            - name: MODEL_ID
              value: google/gemma-4-26B-A4B-it
            volumeMounts:
            - mountPath: /dev/shm
              name: dshm
          volumes:
          - name: dshm
            emptyDir:
                medium: Memory
          nodeSelector:
            cloud.google.com/gke-accelerator: nvidia-rtx-pro-6000
            cloud.google.com/gke-gpu-driver-version: latest
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: llm-service
    spec:
      selector:
        app: gemma-server
      type: ClusterIP
      ports:
        - protocol: TCP
          port: 8000
          targetPort: 8000
    
  2. החלת המניפסט:

    kubectl apply -f vllm-4-26b-a4b-it.yaml
    

    בדוגמה שלנו, אנחנו מגבילים את גודל חלון ההקשר ל-16K באמצעות האפשרות --max-model-len=16384 של vLLM. אם אתם רוצים להגדיל את גודל חלון ההקשר (עד 128K), אתם צריכים לשנות את ההגדרה של קובץ המניפסט ושל מאגר הצמתים כדי להגדיל את קיבולת ה-GPU.

Gemma 4 31B-it

כדי לפרוס את מודל Gemma 4 31B שעבר כוונון להוראות, פועלים לפי ההוראות הבאות.

  1. יוצרים את קובץ המניפסט vllm-4-31b-it.yaml הבא:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vllm-gemma-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: gemma-server
      template:
        metadata:
          labels:
            app: gemma-server
            ai.gke.io/model: gemma-4-31b-it
            ai.gke.io/inference-server: vllm
            examples.ai.gke.io/source: user-guide
        spec:
          containers:
          - name: inference-server
            image: us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:gemma4
            resources:
              requests:
                cpu: "22"
                memory: "100Gi"
                ephemeral-storage: "80Gi"
                nvidia.com/gpu: "1"
              limits:
                cpu: "22"
                memory: "100Gi"
                ephemeral-storage: "80Gi"
                nvidia.com/gpu: "1"
            command: ["python3", "-m", "vllm.entrypoints.api_server"]
            args:
              - --model=$(MODEL_ID)
              - --host=0.0.0.0
              - --port=8000
              - --tensor-parallel-size=1
              - --enable-log-requests
              - --enable-chunked-prefill
              - --enable-prefix-caching
              - --enable-auto-tool-choice
              - --generation-config=auto
              - --tool-call-parser=gemma4
              - --dtype=bfloat16
              - --max-num-seqs=16
              - --max-model-len=16384
              - --gpu-memory-utilization=0.95
              - --reasoning-parser=gemma4
              - --trust-remote-code
            env:
            - name: LD_LIBRARY_PATH
              value: ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64
            - name: MODEL_ID
              value: google/gemma-4-31B-it
            volumeMounts:
            - mountPath: /dev/shm
              name: dshm
          volumes:
          - name: dshm
            emptyDir:
                medium: Memory
          nodeSelector:
            cloud.google.com/gke-accelerator: nvidia-rtx-pro-6000
            cloud.google.com/gke-gpu-driver-version: latest
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: llm-service
    spec:
      selector:
        app: gemma-server
      type: ClusterIP
      ports:
        - protocol: TCP
          port: 8000
          targetPort: 8000
    
  2. החלת המניפסט:

    kubectl apply -f vllm-4-31b-it.yaml
    

    בדוגמה שלנו, אנחנו מגבילים את גודל חלון ההקשר ל-16K באמצעות האפשרות --max-model-len=16384 של vLLM. אם רוצים להגדיל את גודל חלון ההקשר (עד 128K), צריך לשנות את קובץ המניפסט ואת ההגדרה של מאגר הצמתים כדי להגדיל את קיבולת ה-GPU.

אימות

  1. ממתינים עד שהפריסה תהיה זמינה:

    kubectl wait --for=condition=Available --timeout=1800s deployment/vllm-gemma-deployment
    
  2. צפייה ביומנים מהפריסה הפעילה:

    kubectl logs -f -l app=gemma-server
    

    משאב הפריסה מוריד את נתוני המודל של Gemma. התהליך הזה יכול לקחת כמה דקות. הפלט אמור להיראות כך:

      ...
      ...
      (APIServer pid=1) INFO:     Started server process [1]
      (APIServer pid=1) INFO:     Waiting for application startup.
      (APIServer pid=1) INFO:     Application startup complete.
    

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

פריסת Gemma שעברה כוונון עדין מ-Managed Lustre

כדי להכניס לשימוש בסביבת הייצור מודל Gemma שעבר כוונון עדין (כמו Gemma 3 27B) וכבר מאוחסן במכונת Google Cloud Managed Lustre, צריך לטעון את PersistentVolumeClaim (PVC) המתאים לקונטיינר vLLM.

דרישות מוקדמות

מוודאים שיש לכם PVC קיים באשכול GKE שמקושר למופע Lustre. בדוגמה הזו, ה-PVC נקרא gemma-lustre-pvc.

במאמר גישה למופע קיים של Managed Lustre מוסבר איך ליצור PVC ו-PersistentVolume (PV) למופע קיים.

התהליך

  1. שומרים את מניפסט ה-YAML הבא בשם vllm-lustre-gemma.yaml. בדוגמה הזו, הפריסה מטמיעה את ה-PVC של Lustre ב-/data ומורה ל-vLLM לטעון את משקלי המודל מהנתיב המקומי הזה.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vllm-gemma-lustre
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: gemma-server
      template:
        metadata:
          labels:
            app: gemma-server
        spec:
          containers:
          - name: vllm
            image: vllm/vllm-openai:latest
            command: ["python3", "-m", "vllm.entrypoints.openai.api_server"]
            args:
            - --model=/data/gemma-3-27b
            - --tensor-parallel-size=1
            resources:
              limits:
                nvidia.com/gpu: "1"
            volumeMounts:
            - name: model-weights
              mountPath: /data
          volumes:
          - name: model-weights
            persistentVolumeClaim:
              claimName: gemma-lustre-pvc
          nodeSelector:
            cloud.google.com/gke-accelerator: nvidia-l4
            cloud.google.com/gke-gpu-driver-version: latest
    
  2. מחילים את המניפסט על אשכול GKE:

    kubectl apply -f vllm-lustre-gemma.yaml
    

אימות

כדי לוודא שהמודל נטען בהצלחה מהנפח של Lustre, בודקים את היומנים של ה-Pod ברצף ההפעלה של vLLM:

kubectl logs -l app=gemma-server

פרסום המודל

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

הגדרת העברה ליציאה אחרת

מריצים את הפקודה הבאה כדי להגדיר העברת נתונים (פורט פורוורדינג) למודל:

kubectl port-forward service/llm-service 8000:8000

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

Forwarding from 127.0.0.1:8000 -> 8000

אינטראקציה עם המודל באמצעות curl

בקטע הזה מוסבר איך לבצע בדיקת עשן בסיסית כדי לאמת את מודלי Gemma 4 שעברו כוונון להוראות. במודלים אחרים, מחליפים את gemma-4-e4b-it בשם המודל הרלוונטי.

בדוגמה הזו תוכלו לראות איך בודקים את המודל Gemma 4 E4B שעבר כוונון להוראות עם קלט של טקסט בלבד.

בסשן חדש של מסוף, משתמשים ב-curl כדי לשוחח עם המודל:

curl http://127.0.0.1:8000/v1/chat/completions \
-X POST \
-H "Content-Type: application/json" \
-d '{
    "model": "google/gemma-4-26B-A4B-it",
    "messages": [
        {
          "role": "user",
          "content": "Why is the sky blue?"
        }
    ],
    "chat_template_kwargs": {
         "enable_thinking": true
    },
    "skip_special_tokens": false
}'

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

{
  "id": "chatcmpl-be75ccfcbdf753d1",
  "object": "chat.completion",
  "created": 1775006187,
  "model": "google/gemma-4-26B-A4B-it",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The short answer is a phenomenon called **Rayleigh scattering**.\n\nTo understand how it works, you have to look at three things: sunlight, the Earth's atmosphere, and how light travels.\n\n### 1. Sunlight is a Rainbow\nAlthough sunlight looks white to us, it is actually made up of all the colors of the rainbow (red, orange, yellow, green, blue, indigo, and violet). Light travels as **waves**, and each color has a different wavelength:\n*   **Red light** travels in long, lazy, wide waves.\n*   **Blue and violet light** travel in short, choppy, tight waves.\n\n### 2. The Atmosphere is an Obstacle Course\nEarth's atmosphere is filled with gases (mostly nitrogen and oxygen). As sunlight travels through the atmosphere, it strikes the molecules of these gases. \n\nBecause the gas molecules are very small, they affect the colors differently based on their wavelength:\n*   The **long waves** (reds and yellows) pass through the atmosphere mostly straight, without hitting much. They are like large ocean waves that roll right over small pebbles.\n*   The **short waves** (blues and violets) strike the gas molecules and get scattered in every direction. They are like small ripples that hit a pebble and splash everywhere.\n\nBecause this blue light is being scattered in every direction by the air, when you look up, your eyes are catching that scattered blue light coming from every part of the sky.\n\n### 3. Why isn't the sky violet?\nIf violet light has an even shorter wavelength than blue light, you might wonder why the sky doesn't look purple. There are two main reasons:\n1.  **The Sun's output:** The Sun emits much more blue light than violet light.\n2.  **Human Biology:** Human eyes are much more sensitive to blue than to violet. Our eyes interpret the scatter of mixed blue and violet light simply as pale blue.\n\n---\n\n### Bonus: Why are sunsets red?\nWhen the sun is setting, it is much lower on the horizon. This means the sunlight has to travel through a much **thicker** layer of the atmosphere to reach your eyes. \n\nBy the time the light gets to you, the blue light has been scattered away completely로. Only the long-wavelength colors—the reds, oranges, and pinks—are able to make it through that thick layer of air without being scattered away, creating the beautiful colors of a sunset.",
        "refusal": null,
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": [],
        "reasoning": "\"Why is the sky blue?\"\nScience/Physics (Atmospheric scattering).\nExplain the phenomenon clearly, accurately, and engagingly.\n\n    *   Sunlight (white light) is made of a spectrum of colors (ROYGBIV).\n    *   Earth's atmosphere is filled with gases (nitrogen, oxygen) and particles.\n    *   Rayleigh Scattering: Shorter wavelengths (blue/violet) scatter more easily than longer wavelengths (red/yellow) when hitting small gas molecules.\n    *   The human eye's sensitivity: Why isn't it violet?\n\n    A good scientific explanation should follow a logical flow:\n    *   *Direct Answer:* The core mechanism (Rayleigh Scattering).\n    *   *The Components:* Sunlight and the Atmosphere.\n    *   *The Mechanism:* How light interacts with gas molecules.\n    *   *The Wavelength Factor:* Comparing colors.\n    *   *The \"Wait, why not violet?\" question:* Addressing human perception.\n    *   *Bonus/Related concept:* Why sunsets are red.\n\n        *   Use the term **Rayleigh Scattering**.\n        *   Summarize: Its how sunlight interacts with the Earth's atmosphere.\n\n        *   Sunlight looks white, but it's actually a mix of all colors (the rainbow).\n        *   Each color travels as a different wavelength. Red = long/lazy waves; Blue/Violet = short/choppy waves.\n\n        *   The atmosphere is mostly Nitrogen and Oxygen.\n        *   When sunlight hits these tiny gas molecules, the light gets scattered in all directions.\n\n        *   Blue light travels in shorter, smaller waves.\n        *   Because these waves are small, they strike the gas molecules more frequently and get scattered more easily than the longer red/yellow waves.\n        *   Result: When you look up, your eyes are catching this \"scattered\" blue light coming from every direction.\n\n        *   *Technically*, violet light has an even shorter wavelength than blue, so it scatters *even more*. Why isn't the sky violet?\n        *   Two reasons: 1. The Sun emits more blue light than violet light. 2. Human eyes are much more sensitive to blue than violet.\n\n        *   Briefly mention sunsets to provide a complete picture.\n        *   At sunset, light travels through *more* atmosphere. The blue is scattered away completely, leaving only the long red/orange waves to reach your eyes.\n\n    *   *Tone Check:* Is it too academic? Use analogies (like waves in water or skipping stones) if needed, but keep it concise.\n    *   *Clarity:* Ensure the distinction between wavelength and scattering is clear."
      },
      "logprobs": null,
      "finish_reason": "stop",
      "stop_reason": 106,
      "token_ids": null
    }
  ],
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "prompt_tokens": 21,
    "total_tokens": 1122,
    "completion_tokens": 1101,
    "prompt_tokens_details": null
  },
  "prompt_logprobs": null,
  "prompt_token_ids": null,
  "kv_transfer_params": null
}

(אופציונלי) אינטראקציה עם המודל דרך ממשק צ'אט של Gradio

בקטע הזה תבנו אפליקציית צ'אט באינטרנט שתאפשר לכם ליצור אינטראקציה עם מודל שהותאם להוראות. כדי לפשט את הדברים, בקטע הזה מתואר רק הגישה לבדיקה באמצעות מודל 4B-it.

Gradio היא ספריית Python עם wrapper של ChatInterface שיוצר ממשקי משתמש לצ'אטבוטים.

פריסת ממשק הצ'אט

  1. ב-Cloud Shell, שומרים את קובץ המניפסט הבא בשם gradio.yaml. מחליפים את google/gemma-4-E4B-it בשם של מודל Gemma 4 שבו השתמשתם בפריסה.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: gradio
      labels:
        app: gradio
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: gradio
      template:
        metadata:
          labels:
            app: gradio
        spec:
          containers:
          - name: gradio
            image: us-docker.pkg.dev/google-samples/containers/gke/gradio-app:v1.0.7
            resources:
              requests:
                cpu: "250m"
                memory: "512Mi"
              limits:
                cpu: "500m"
                memory: "512Mi"
            env:
            - name: CONTEXT_PATH
              value: "/v1/chat/completions"
            - name: HOST
              value: "http://llm-service:8000"
            - name: LLM_ENGINE
              value: "openai-chat"
            - name: MODEL_ID
              value: "google/gemma-4-E4B-it"
            - name: DISABLE_SYSTEM_MESSAGE
              value: "true"
            ports:
            - containerPort: 7860
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: gradio
    spec:
      selector:
        app: gradio
      ports:
      - protocol: TCP
        port: 8080
        targetPort: 7860
      type: ClusterIP
    
  2. החלת המניפסט:

    kubectl apply -f gradio.yaml
    
  3. מחכים שהפריסה תהיה זמינה:

    kubectl wait --for=condition=Available --timeout=900s deployment/gradio
    
  4. שימוש בממשק הצ'אט

    1. ב-Cloud Shell, מריצים את הפקודה הבאה:

      kubectl port-forward service/gradio 8080:8080
      

      הפעולה הזו יוצרת העברת פורטים מ-Cloud Shell לשירות Gradio.

    2. לוחצים על הלחצן סמל של תצוגה מקדימה באינטרנט Web Preview (תצוגה מקדימה באינטרנט) שנמצא בפינה השמאלית העליונה של סרגל המשימות ב-Cloud Shell. לוחצים על תצוגה מקדימה ביציאה 8080. תיפתח כרטיסייה חדשה בדפדפן.

    3. אינטראקציה עם Gemma באמצעות ממשק הצ'אט של Gradio. מוסיפים הנחיה ולוחצים על שליחה.

    פתרון בעיות

    מעקב אחר ביצועי המודל

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

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

      מעבר אל 'מודלים שנפרסו'

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

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

      • בלוח הבקרה Infrastructure usage מוצגים מדדי השימוש.
      • בלוח הבקרה DCGM מוצגים מדדי DCGM.
      • אם אתם משתמשים ב-vLLM, לוח הבקרה Model performance זמין ומציג מדדים של ביצועי מודל vLLM.

    אפשר גם לראות מדדים בשילוב של לוח הבקרה vLLM ב-Cloud Monitoring. המדדים האלה מצטברים לכל הפריסות של vLLM ללא מסננים מוגדרים מראש

    כדי להשתמש בלוח הבקרה ב-Cloud Monitoring, צריך להפעיל את השירות המנוהל של Google Cloud ל-Prometheus, שאוסף את המדדים מ-vLLM באשכול GKE. ‫vLLM חושף מדדים בפורמט Prometheus כברירת מחדל, כך שלא צריך להתקין כלי נוסף לייצוא נתונים. מידע על שימוש בשירות המנוהל של Google Cloud ל-Prometheus כדי לאסוף מדדים מהמודל זמין במאמר בנושא vLLM בתיעוד של Cloud Monitoring.

הסרת המשאבים

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

מחיקת המשאבים שנפרסו

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

gcloud container clusters delete CLUSTER_NAME \
    --location=CONTROL_PLANE_LOCATION

מחליפים את הערכים הבאים:

  • CONTROL_PLANE_LOCATION: האזור של Compute Engine במישור הבקרה של האשכול.
  • CLUSTER_NAME: השם של האשכול.

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