במדריך הזה מוסבר איך לפרוס מודל שפה גדול (LLM) ב-Google Kubernetes Engine (GKE) באמצעות GKE Inference Gateway. המדריך כולל שלבים להגדרת אשכול, פריסת מודל, הגדרת GKE Inference Gateway וטיפול בבקשות LLM.
המדריך הזה מיועד למהנדסי למידת מכונה (ML), למנהלי פלטפורמות ולמפעילי פלטפורמות, ולמומחי נתונים ו-AI שרוצים לפרוס ולנהל אפליקציות LLM ב-GKE באמצעות GKE Inference Gateway.
לפני שתקראו את הדף הזה, כדאי שתכירו את המושגים הבאים:
- מידע על הסקת מסקנות ממודלים ב-GKE
- הרצת הסקה לפי השיטות המומלצות באמצעות מתכונים של GKE Inference Quickstart
- מצב אוטומטי ומצב ידני
- מעבדים גרפיים ב-GKE
רקע
בקטע הזה מתוארות הטכנולוגיות העיקריות שבהן משתמשים במדריך הזה. מידע נוסף על מושגים ומונחים שקשורים לפרסום מודלים, ועל האופן שבו יכולות מבוססות-AI גנרטיבי של GKE יכולות לשפר ולתמוך בביצועים של פרסום המודלים, זמין במאמר מידע על הסקת מסקנות ממודלים ב-GKE.
vLLM
vLLM הוא מסגרת בקוד פתוח שעברה אופטימיזציה גבוהה להצגת מודלים גדולים של שפה (LLM), שמשפרת את קצב העיבוד של ההצגה ביחידות GPU. התכונות העיקריות כוללות:
- הטמעה משופרת של טרנספורמר באמצעות PagedAttention
- עיבוד באצ'ים רציף שמשפר את קצב העיבוד הכולל של הצגת המודעות
- מקביליות של טנזורים ועיבוד מבוזר בכמה מעבדי GPU
מידע נוסף זמין במסמכי התיעוד של vLLM.
GKE Inference Gateway
GKE Inference Gateway משפר את היכולות של GKE להצגת מודלי LLM. הוא מבצע אופטימיזציה של עומסי עבודה של הסקה באמצעות תכונות כמו:
- איזון עומסים שמותאם להסקת מסקנות על סמך מדדי עומס.
- תמיכה בהצגה צפופה של עומסי עבודה מרובים של מתאמי LoRA.
- ניתוב מבוסס-מודל לפעולות פשוטות יותר.
מידע נוסף זמין במאמר מידע על GKE Inference Gateway.
מטרות
לפני שמתחילים
- נכנסים לחשבון 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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the required API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. 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.-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the required API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. 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.-
צריך לוודא שיש לכם בפרויקט את התפקיד או התפקידים הבאים: roles/container.admin, roles/iam.serviceAccountAdmin
בדיקת התפקידים
-
נכנסים לדף IAM במסוף Google Cloud .
כניסה לדף IAM - בוחרים את הפרויקט.
-
בעמודה Principal, מחפשים את כל השורות שמזהות אתכם או קבוצה שאתם חברים בה. כדי לברר לאילו קבוצות אתם שייכים, פנו לאדמין.
- בכל השורות שבהן אתם מופיעים, בודקים בעמודה Role אם רשימת התפקידים כוללת את התפקידים הנדרשים.
מתן התפקידים
-
נכנסים לדף IAM במסוף Google Cloud .
כניסה לדף IAM - בוחרים את הפרויקט.
- לוחצים על Grant access.
-
בשדה New principals, מזינים את מזהה המשתמש. בדרך כלל מזהה המשתמש הוא כתובת האימייל של חשבון Google.
- לוחצים על Select a role ומחפשים את התפקיד.
- כדי לתת עוד תפקידים, לוחצים על Add another role ומוסיפים אותם.
- לוחצים על Save.
-
- אם עדיין אין לכם חשבון ב-Hugging Face, אתם צריכים ליצור חשבון.
- מוודאים שיש בפרויקט מכסה מספיקה למעבדי GPU מסוג H100. מידע נוסף זמין במאמרים תכנון מכסת GPU ומכסות הקצאה.
קבלת גישה למודל
כדי לפרוס את המודל Llama3.1 ב-GKE, צריך לחתום על הסכם הרישיון וליצור אסימון גישה ל-Hugging Face.
חתימה על הסכם הרישיון
כדי להשתמש במודל Llama3.1, צריך לחתום על הסכם ההסכמה. פועלים לפי ההוראות הבאות:
- נכנסים לדף ההסכמה ומאשרים את השימוש בחשבון Hugging Face.
- מאשרים את תנאי המודל.
יצירת טוקן גישה
כדי לגשת למודל דרך Hugging Face, צריך טוקן של Hugging Face.
אם אין לכם טוקן, אתם יכולים ליצור טוקן חדש לפי השלבים הבאים:
- לוחצים על Your Profile > Settings > טוקני גישה.
- לוחצים על New Token (אסימון חדש).
- מציינים שם לבחירתכם ותפקיד של לפחות
Read. - לוחצים על יצירת טוקן.
- מעתיקים את הטוקן שנוצר ללוח.
הכנת הסביבה
במדריך הזה תשתמשו ב-Cloud Shell כדי לנהל משאבים שמתארחים ב-Google Cloud. ב-Cloud Shell מותקנות מראש התוכנות שצריך בשביל המדריך הזה, כולל kubectl וה-CLI של gcloud.
כדי להגדיר את הסביבה באמצעות Cloud Shell:
במסוף Google Cloud , מפעילים סשן של Cloud Shell בלחיצה על
Activate Cloud Shell במסוףGoogle Cloud . הפעולה הזו תפתח סשן בחלונית התחתונה של מסוף Google Cloud .
מגדירים את משתני הסביבה שמוגדרים כברירת מחדל:
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 CLUSTER_NAME=CLUSTER_NAME export HF_TOKEN=HF_TOKENמחליפים את הערכים הבאים:
-
PROJECT_ID: מזהה הפרויקט ב- Google Cloud. -
REGION: אזור שתומך בסוג המאיץ שבו רוצים להשתמש, לדוגמהus-central1ל-GPU מסוג H100. -
CLUSTER_NAME: שם האשכול. HF_TOKEN: האסימון של Hugging Face שיצרתם קודם.
-
יצירה והגדרה של משאבי Google Cloud
יצירת אשכול GKE ומאגר צמתים
הצגת מודלי LLM ב-GPU באשכול GKE Autopilot או Standard. כדי ליהנות מחוויית Kubernetes בניהול מלא, מומלץ להשתמש באשכול Autopilot. כדי לבחור את מצב הפעולה של 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 מסוג H100.-
CLUSTER_NAME: שם האשכול.
GKE יוצר אשכול Autopilot עם צומתי מעבד (CPU) ו-GPU, בהתאם לבקשה של עומסי העבודה שנפרסו.
רגילה
ב-Cloud Shell, מריצים את הפקודה הבאה כדי ליצור אשכול רגיל:
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 \ --enable-managed-prometheus \ --monitoring=SYSTEM,DCGM \ --gateway-api=standardמחליפים את הערכים הבאים:
-
PROJECT_ID: מזהה הפרויקט ב- Google Cloud. CONTROL_PLANE_LOCATION: האזור ב-Compute Engine של מישור הבקרה של האשכול. מציינים אזור שתומך בסוג המאיץ שבו רוצים להשתמש, לדוגמה,us-central1ל-GPU מסוג H100.-
CLUSTER_NAME: שם האשכול.
יצירת האשכול עשויה להימשך כמה דקות.
-
כדי ליצור מאגר צמתים עם גודל דיסק שמתאים להרצת המודל
Llama-3.1-8B-Instruct, מריצים את הפקודה הבאה:gcloud container node-pools create gpupool \ --accelerator type=nvidia-h100-80gb,count=2,gpu-driver-version=latest \ --project=PROJECT_ID \ --location=CONTROL_PLANE_LOCATION \ --node-locations=CONTROL_PLANE_LOCATION-a \ --cluster=CLUSTER_NAME \ --machine-type=a3-highgpu-2g \ --num-nodes=1 \ --disk-type="pd-balanced"GKE יוצר מאגר צמתים אחד שמכיל GPU אחד מסוג H100.
הגדרת הרשאה לאיסוף מדדים
כדי להגדיר הרשאה לאיסוף מדדים, יוצרים את הסוד inference-gateway-sa-metrics-reader-secret.
שומרים את המניפסט הבא בתור
metrics-auth.yaml:מחילים את המניפסט:
kubectl apply -f metrics-auth.yaml
יצירת סוד ב-Kubernetes לפרטי הכניסה של Hugging Face
ב-Cloud Shell, מבצעים את הפעולות הבאות:
מגדירים את
kubectlכדי שיוכל לתקשר עם האשכול:gcloud container clusters get-credentials CLUSTER_NAME \ --location=REGIONמחליפים את הערכים הבאים:
-
REGION: אזור שתומך בסוג המאיץ שבו רוצים להשתמש, לדוגמהus-central1ל-GPU מסוג L4. -
CLUSTER_NAME: שם האשכול.
-
יוצרים Kubernetes Secret שמכיל את הטוקן של Hugging Face:
kubectl create secret generic hf-secret \ --from-literal=hf_api_token=${HF_TOKEN} \ --dry-run=client -o yaml | kubectl apply -f -מחליפים את
HF_TOKENבטוקן של Hugging Face שיצרתם קודם.
התקנת CustomResourceDefinitions של InferenceObjective ו-InferencePool
בקטע הזה תתקינו את ה-CustomResourceDefinitions שנדרשים ל-GKE Inference Gateway.
CustomResourceDefinitions מרחיבים את Kubernetes API. כך אפשר להגדיר סוגי משאבים חדשים. כדי להשתמש ב-GKE Inference Gateway, מתקינים את InferencePool ואת InferenceObjective CustomResourceDefinitions באשכול GKE באמצעות הפקודה הבאה:
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api-inference-extension/releases/download/v1.0.0/manifests.yaml
פריסת שרת המודל
בדוגמה הזו נפרס מודל Llama3.1 באמצעות שרת מודל vLLM. הפריסה מסומנת בתווית app:vllm-llama3.1-8b-instruct. הפריסה הזו משתמשת גם בשני מתאמי LoRA בשם food-review ו-cad-fabricator מ-Hugging Face. אתם יכולים לעדכן את הפריסה הזו עם שרת מודל, קונטיינר מודל, יציאת שירות ושם פריסה משלכם. אפשר להגדיר מתאמי LoRA בפריסה, או לפרוס את מודל הבסיס.
כדי לפרוס במאיץ מסוג
nvidia-h100-80gb, שומרים את המניפסט הבא בתורvllm-llama3.1-8b-instruct.yaml. המניפסט הזה מגדיר פריסת Kubernetes עם המודל ושרת המודל שלכם:apiVersion: apps/v1 kind: Deployment metadata: name: vllm-llama3.1-8b-instruct spec: replicas: 3 selector: matchLabels: app: vllm-llama3.1-8b-instruct template: metadata: labels: app: vllm-llama3.1-8b-instruct spec: containers: - name: vllm image: "vllm/vllm-openai:v0.13.0" imagePullPolicy: Always command: ["python3", "-m", "vllm.entrypoints.openai.api_server"] args: - "--model" - "meta-llama/Llama-3.1-8B-Instruct" - "--tensor-parallel-size" - "1" - "--port" - "8000" - "--enable-lora" - "--max-loras" - "2" - "--max-cpu-loras" - "12" - "--compilation-config" - '{"cudagraph_specialize_lora": "False"}' # As workaround for https://github.com/vllm-project/vllm/issues/29049 env: - name: PORT value: "8000" - name: HUGGING_FACE_HUB_TOKEN valueFrom: secretKeyRef: name: hf-secret key: hf_api_token - name: VLLM_ALLOW_RUNTIME_LORA_UPDATING value: "true" ports: - containerPort: 8000 name: http protocol: TCP lifecycle: preStop: # vLLM stops accepting connections when it receives SIGTERM, so we need to sleep # to give upstream gateways a chance to take us out of rotation. The time we wait # is dependent on the time it takes for all upstreams to completely remove us from # rotation. Older or simpler load balancers might take upwards of 30s, but we expect # our deployment to run behind a modern gateway like Envoy which is designed to # probe for readiness aggressively. sleep: # Upstream gateway probers for health should be set on a low period, such as 5s, # and the shorter we can tighten that bound the faster that we release # accelerators during controlled shutdowns. However, we should expect variance, # as load balancers may have internal delays, and we don't want to drop requests # normally, so we're often aiming to set this value to a p99 propagation latency # of readiness -> load balancer taking backend out of rotation, not the average. # # This value is generally stable and must often be experimentally determined on # for a given load balancer and health check period. We set the value here to # the highest value we observe on a supported load balancer, and we recommend # tuning this value down and verifying no requests are dropped. # # If this value is updated, be sure to update terminationGracePeriodSeconds. # seconds: 30 # # IMPORTANT: preStop.sleep is beta as of Kubernetes 1.30 - for older versions # replace with this exec action. #exec: # command: # - /usr/bin/sleep # - 30 livenessProbe: httpGet: path: /health port: http scheme: HTTP # vLLM's health check is simple, so we can more aggressively probe it. Liveness # check endpoints should always be suitable for aggressive probing. periodSeconds: 1 successThreshold: 1 # vLLM has a very simple health implementation, which means that any failure is # likely significant. However, any liveness triggered restart requires the very # large core model to be reloaded, and so we should bias towards ensuring the # server is definitely unhealthy vs immediately restarting. Use 5 attempts as # evidence of a serious problem. failureThreshold: 5 timeoutSeconds: 1 readinessProbe: httpGet: path: /health port: http scheme: HTTP # vLLM's health check is simple, so we can more aggressively probe it. Readiness # check endpoints should always be suitable for aggressive probing, but may be # slightly more expensive than readiness probes. periodSeconds: 1 successThreshold: 1 # vLLM has a very simple health implementation, which means that any failure is # likely significant, failureThreshold: 1 timeoutSeconds: 1 # We set a startup probe so that we don't begin directing traffic or checking # liveness to this instance until the model is loaded. startupProbe: # Failure threshold is when we believe startup will not happen at all, and is set # to the maximum possible time we believe loading a model will take. In our # default configuration we are downloading a model from HuggingFace, which may # take a long time, then the model must load into the accelerator. We choose # 10 minutes as a reasonable maximum startup time before giving up and attempting # to restart the pod. # # IMPORTANT: If the core model takes more than 10 minutes to load, pods will crash # loop forever. Be sure to set this appropriately. failureThreshold: 600 # Set delay to start low so that if the base model changes to something smaller # or an optimization is deployed, we don't wait unnecessarily. initialDelaySeconds: 2 # As a startup probe, this stops running and so we can more aggressively probe # even a moderately complex startup - this is a very important workload. periodSeconds: 1 httpGet: # vLLM does not start the OpenAI server (and hence make /health available) # until models are loaded. This may not be true for all model servers. path: /health port: http scheme: HTTP resources: limits: nvidia.com/gpu: 1 requests: nvidia.com/gpu: 1 volumeMounts: - mountPath: /data name: data - mountPath: /dev/shm name: shm - name: adapters mountPath: "/adapters" # This is the second container in the Pod, a sidecar to the vLLM container. # It watches the ConfigMap and downloads LoRA adapters. - name: lora-adapter-syncer image: us-central1-docker.pkg.dev/k8s-staging-images/gateway-api-inference-extension/lora-syncer:main imagePullPolicy: Always env: - name: DYNAMIC_LORA_ROLLOUT_CONFIG value: "/config/configmap.yaml" volumeMounts: # DO NOT USE subPath, dynamic configmap updates don't work on subPaths - name: config-volume mountPath: /config restartPolicy: Always # vLLM allows VLLM_PORT to be specified as an environment variable, but a user might # create a 'vllm' service in their namespace. That auto-injects VLLM_PORT in docker # compatible form as `tcp://<IP>:<PORT>` instead of the numeric value vLLM accepts # causing CrashLoopBackoff. Set service environment injection off by default. enableServiceLinks: false # Generally, the termination grace period needs to last longer than the slowest request # we expect to serve plus any extra time spent waiting for load balancers to take the # model server out of rotation. # # An easy starting point is the p99 or max request latency measured for your workload, # although LLM request latencies vary significantly if clients send longer inputs or # trigger longer outputs. Since steady state p99 will be higher than the latency # to drain a server, you may wish to slightly this value either experimentally or # via the calculation below. # # For most models you can derive an upper bound for the maximum drain latency as # follows: # # 1. Identify the maximum context length the model was trained on, or the maximum # allowed length of output tokens configured on vLLM (llama2-7b was trained to # 4k context length, while llama3-8b was trained to 128k). # 2. Output tokens are the more compute intensive to calculate and the accelerator # will have a maximum concurrency (batch size) - the time per output token at # maximum batch with no prompt tokens being processed is the slowest an output # token can be generated (for this model it would be about 10ms TPOT at a max # batch size around 50, or 100 tokens/sec) # 3. Calculate the worst case request duration if a request starts immediately # before the server stops accepting new connections - generally when it receives # SIGTERM (for this model that is about 4096 / 100 ~ 40s) # 4. If there are any requests generating prompt tokens that will delay when those # output tokens start, and prompt token generation is roughly 6x faster than # compute-bound output token generation, so add 40% to the time from above (40s + # 16s = 56s) # # Thus we think it will take us at worst about 56s to complete the longest possible # request the model is likely to receive at maximum concurrency (highest latency) # once requests stop being sent. # # NOTE: This number will be lower than steady state p99 latency since we stop receiving # new requests which require continuous prompt token computation. # NOTE: The max timeout for backend connections from gateway to model servers should # be configured based on steady state p99 latency, not drain p99 latency # # 5. Add the time the pod takes in its preStop hook to allow the load balancers to # stop sending us new requests (56s + 30s = 86s). # # Because the termination grace period controls when the Kubelet forcibly terminates a # stuck or hung process (a possibility due to a GPU crash), there is operational safety # in keeping the value roughly proportional to the time to finish serving. There is also # value in adding a bit of extra time to deal with unexpectedly long workloads. # # 6. Add a 50% safety buffer to this time (86s * 1.5 ≈ 130s). # # One additional source of drain latency is that some workloads may run close to # saturation and have queued requests on each server. Since traffic in excess of the # max sustainable QPS will result in timeouts as the queues grow, we assume that failure # to drain in time due to excess queues at the time of shutdown is an expected failure # mode of server overload. If your workload occasionally experiences high queue depths # due to periodic traffic, consider increasing the safety margin above to account for # time to drain queued requests. terminationGracePeriodSeconds: 130 nodeSelector: cloud.google.com/gke-accelerator: "nvidia-h100-80gb" volumes: - name: data emptyDir: {} - name: shm emptyDir: medium: Memory - name: adapters emptyDir: {} - name: config-volume configMap: name: vllm-llama3.1-8b-adapters --- apiVersion: v1 kind: ConfigMap metadata: name: vllm-llama3.1-8b-adapters data: configmap.yaml: | vLLMLoRAConfig: name: vllm-llama3.1-8b-instruct port: 8000 defaultBaseModel: meta-llama/Llama-3.1-8B-Instruct ensureExist: models: - id: food-review source: Kawon/llama3.1-food-finetune_v14_r8 - id: cad-fabricator source: redcathode/fabricator --- kind: HealthCheckPolicy apiVersion: networking.gke.io/v1 metadata: name: health-check-policy namespace: default spec: targetRef: group: "inference.networking.k8s.io" kind: InferencePool name: vllm-llama3.1-8b-instruct default: config: type: HTTP httpHealthCheck: requestPath: /health port: 8000מחילים את המניפסט על האשכול:
kubectl apply -f vllm-llama3.1-8b-instruct.yaml
יצירת משאב InferencePool
המשאב המותאם אישית InferencePool ב-Kubernetes מגדיר קבוצה של Pods עם מודל LLM בסיסי משותף והגדרת מחשוב משותפת.
המשאב המותאם אישית InferencePool כולל את שדות המפתח הבאים:
-
selector: מציין אילו Pods שייכים למאגר הזה. התוויות בבורר הזה חייבות להיות זהות לתוויות שמוחלות על Pods של שרת המודל. -
targetPort: מגדיר את היציאות שבהן משתמש שרת המודל בתוך ה-Pods.
המשאב InferencePool מאפשר ל-GKE Inference Gateway לנתב תנועה לפודים של שרת המודל.
כדי ליצור משאב InferencePool באמצעות Helm:
helm install vllm-llama3.1-8b-instruct \
--set inferencePool.modelServers.matchLabels.app=vllm-llama3.1-8b-instruct \
--set provider.name=gke \
--set healthCheckPolicy.create=false \
--version v1.0.0 \
oci://registry.k8s.io/gateway-api-inference-extension/charts/inferencepool
משנים את השדה הבא בהתאם לפריסה:
-
inferencePool.modelServers.matchLabels.app: המפתח של התווית שמשמשת לבחירת ה-Pods של שרת המודל.
הפקודה הזו יוצרת אובייקט InferencePool שמייצג באופן לוגי את פריסת שרת המודל, ומפנה לשירותים של נקודות הקצה של המודל בתוך ה-Pods שנבחרו על ידי Selector.
יצירת משאב InferenceObjective עם רמת קריטיות להצגה
המשאב המותאם אישית InferenceObjective מגדיר את הפרמטרים להצגת המודל, כולל העדיפות שלו. כדי להגדיר אילו מודלים יוצגו במשאב InferencePool, צריך ליצור משאבי InferenceObjective. המשאבים האלה יכולים להפנות למודלים בסיסיים או למתאמי LoRA שנתמכים על ידי שרתי המודלים במשאב InferencePool.
השדה metadata.name מציין את שם המודל, השדה priority מגדיר את רמת הקריטיות של הצגת המודעות, והשדה poolRef מקשר למשאב InferencePool שבו המודל מוצג.
כדי לשייך בקשות למשאב InferenceObjective, הלקוחות מציינים את כותרת ה-HTTP x-gateway-inference-objective שמוגדרת לערך metadata.name של המשאב (לדוגמה, x-gateway-inference-objective: food-review). לאחר מכן, השער מחיל על הבקשות האלה את העדיפות שהוגדרה למשאב InferenceObjective.
כדי ליצור משאב InferenceObjective:
שומרים את המניפסט לדוגמה הבא בתור
inferenceobjective.yaml:apiVersion: inference.networking.x-k8s.io/v1alpha2 kind: InferenceObjective metadata: name: MODEL_NAME spec: priority: VALUE poolRef: name: INFERENCE_POOL_NAME kind: "InferencePool"מחליפים את מה שכתוב בשדות הבאים:
-
MODEL_NAME: השם של מודל הבסיס או מתאם ה-LoRA. לדוגמה,food-review. -
VALUE: העדיפות של יעד ההסקה. זהו מספר שלם, וככל שהערך גבוה יותר, כך הבקשה קריטית יותר. לדוגמה,10. -
INFERENCE_POOL_NAME: השם של המשאב InferencePool שיצרתם בשלב הקודם. לדוגמה,vllm-llama3.1-8b-instruct.
-
מחילים את המניפסט לדוגמה על האשכול:
kubectl apply -f inferenceobjective.yaml
בדוגמה הבאה נוצרים שני משאבי InferenceObjective. הראשונה מגדירה את מודל ה-LoRA של food-review במשאב vllm-llama3.1-8b-instruct InferencePool עם עדיפות של 10. השני מגדיר את המשאב llama3-base-model InferenceObjective כך שיוצג בעדיפות גבוהה יותר של 20.
apiVersion: inference.networking.k8s.io/v1alpha1
kind: InferenceObjective
metadata:
name: food-review
spec:
priority: 10
poolRef:
name: vllm-llama3.1-8b-instruct
kind: "InferencePool"
---
apiVersion: inference.networking.k8s.io/v1alpha1
kind: InferenceObjective
metadata:
name: llama3-base-model
spec:
priority: 20
poolRef:
name: vllm-llama3.1-8b-instruct
kind: "InferencePool"
יצירת השער
המשאב Gateway משמש כנקודת הכניסה של תנועה חיצונית לאשכול Kubernetes. היא מגדירה את המאזינים שמקבלים חיבורים נכנסים.
GKE Inference Gateway תומך ב-Gateway Class מסוג gke-l7-rilb ו-gke-l7-regional-external-managed. מידע נוסף זמין במאמרי העזרה של GKE בנושא Gateway Classes.
כדי ליצור שער:
שומרים את המניפסט לדוגמה הבא בתור
gateway.yaml:apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: GATEWAY_NAME spec: gatewayClassName: gke-l7-regional-external-managed listeners: - protocol: HTTP # Or HTTPS for production port: 80 # Or 443 for HTTPS name: httpמחליפים את
GATEWAY_NAMEבשם ייחודי למשאב Gateway. לדוגמה,inference-gateway.מחילים את המניפסט על האשכול:
kubectl apply -f gateway.yaml
יצירת המשאב HTTPRoute
בקטע הזה יוצרים משאב HTTPRoute כדי להגדיר איך השער מנתב בקשות HTTP נכנסות למשאב InferencePool.
המשאב HTTPRoute מגדיר איך GKE Gateway מנתב בקשות HTTP נכנסות לשירותים לקצה העורפי, שהם המשאב InferencePool. הוא מציין כללי התאמה (לדוגמה, כותרות או נתיבים) ואת הקצה העורפי שאליו צריך להעביר את התנועה.
כדי ליצור HTTPRoute:
שומרים את המניפסט לדוגמה הבא בתור
httproute.yaml:apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: HTTPROUTE_NAME spec: parentRefs: - name: GATEWAY_NAME rules: - matches: - path: type: PathPrefix value: PATH_PREFIX backendRefs: - name: INFERENCE_POOL_NAME group: inference.networking.k8s.io kind: InferencePoolמחליפים את מה שכתוב בשדות הבאים:
-
HTTPROUTE_NAME: שם ייחודי למשאב HTTPRoute. לדוגמה,my-route. -
GATEWAY_NAME: השם של משאב השער שיצרתם. לדוגמה,inference-gateway. -
PATH_PREFIX: התחילית של הנתיב שמשמשת להתאמה לבקשות נכנסות. לדוגמה,/כדי להתאים לכולם. -
INFERENCE_POOL_NAME: השם של המשאב InferencePool שאליו רוצים לנתב את התנועה. לדוגמה,vllm-llama3.1-8b-instruct.
-
מחילים את המניפסט על האשכול:
kubectl apply -f httproute.yaml
שליחת בקשת הסקה
אחרי שמגדירים את GKE Inference Gateway, אפשר לשלוח בקשות להסקת מסקנות למודל שנפרס.
כדי לשלוח בקשות להסקת מסקנות:
- מאחזרים את נקודת הקצה (endpoint) של השער.
- יוצרים בקשת JSON בפורמט תקין.
- משתמשים ב-
curlכדי לשלוח את הבקשה לנקודת הקצה (endpoint) של/v1/completions.
כך אפשר ליצור טקסט דינמי מבוסס-AI על סמך הנחיית הקלט והפרמטרים שצוינו.
כדי לקבל את נקודת הקצה של השער, מריצים את הפקודה הבאה:
IP=$(kubectl get gateway/GATEWAY_NAME -o jsonpath='{.status.addresses[0].value}') PORT=80מחליפים את
GATEWAY_NAMEבשם של משאב השער.כדי לשלוח בקשה לנקודת הקצה (endpoint) של
/v1/completionsבאמצעותcurl, מריצים את הפקודה הבאה:curl -i -X POST http://${IP}:${PORT}/v1/completions \ -H "Content-Type: application/json" \ -H "x-gateway-inference-objective: INFERENCE_OBJECTIVE_NAME" \ -d '{ "model": "MODEL_NAME", "prompt": "PROMPT_TEXT", "max_tokens": MAX_TOKENS, "temperature": "TEMPERATURE" }'מחליפים את מה שכתוב בשדות הבאים:
-
INFERENCE_OBJECTIVE_NAME: השם של המשאב InferenceObjective שרוצים לשייך לבקשה, לדוגמהfood-review. -
MODEL_NAME: שם המודל או מתאם ה-LoRA שרוצים להשתמש בו. -
PROMPT_TEXT: הנחיית הקלט למודל. -
MAX_TOKENS: המספר המקסימלי של טוקנים שייווצרו בתשובה. -
TEMPERATURE: קובע את מידת האקראיות של הפלט. כדי לקבל פלט דטרמיניסטי, משתמשים בערך0. כדי לקבל פלט יצירתי יותר, משתמשים במספר גבוה יותר.
-
בדוגמה הבאה מוסבר איך לשלוח בקשה לדוגמה שמשויכת למשאב food-review InferenceObjective אל GKE Inference Gateway:
curl -i -X POST http://${IP}:${PORT}/v1/completions \
-H "Content-Type: application/json" \
-H "x-gateway-inference-objective: food-review" \
-d '{
"model": "food-review",
"prompt": "What is the best pizza in the world?",
"max_tokens": 2048,
"temperature": 0
}'
חשוב לזכור:
כותרת של יעד הסקה: כדי לשייך בקשה למשאב InferenceObjective ספציפי, צריך לכלול את כותרת ה-HTTP
x-gateway-inference-objectiveשמוגדרת לערךmetadata.nameשל המשאב. אם לא משתמשים בכותרת הזו, הבקשה מעובדת לפי עדיפות ברירת המחדל של המאגר.גוף הבקשה: גוף הבקשה יכול לכלול פרמטרים נוספים כמו
stopו-top_p. רשימה מלאה של האפשרויות מופיעה במפרט של OpenAI API.טיפול בשגיאות: מטמיעים טיפול תקין בשגיאות בקוד הלקוח כדי לטפל בשגיאות פוטנציאליות בתגובה. לדוגמה, בודקים את קוד הסטטוס של HTTP בתגובה של
curl. קוד סטטוס שהוא לא 200 בדרך כלל מציין שגיאה.אימות והרשאה: בפריסות בסביבת ייצור, צריך לאבטח את נקודת הקצה ל-API באמצעות מנגנוני אימות והרשאה. מוסיפים לבקשות את הכותרות המתאימות (לדוגמה,
Authorization).
הגדרת ניראות (observability) ל-Inference Gateway
GKE Inference Gateway מספק תצפית על התקינות, הביצועים וההתנהגות של עומסי העבודה להסקה. כך אפשר לזהות ולפתור בעיות, לייעל את ניצול המשאבים ולוודא שהאפליקציות פועלות בצורה אמינה. אתם יכולים לראות את מדדי התצפיתיות האלה ב-Cloud Monitoring באמצעות Metrics Explorer.
כדי להגדיר את הניראות של GKE Inference Gateway, קראו את המאמר הגדרת ניראות.
מחיקת המשאבים שנפרסו
כדי להימנע מצבירת חיובים בחשבון Google Cloud על המשאבים שיצרתם באמצעות המדריך הזה, מריצים את הפקודה הבאה:
gcloud container clusters delete CLUSTER_NAME \
--location=CONTROL_PLANE_LOCATION
מחליפים את הערכים הבאים:
CONTROL_PLANE_LOCATION: האזור ב-Compute Engine של מישור הבקרה של האשכול.-
CLUSTER_NAME: שם האשכול.