שימוש ב-Private Service Connect כדי לגשת למסקנות אצווה של Gemini Enterprise Agent Platform ממיקום מקומי

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

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

המדריך הזה מיועד למנהלי רשתות בארגונים, למדעני נתונים ולחוקרים שמכירים את Gemini Enterprise Agent Platform, את הענן הפרטי הווירטואלי (VPC), את מסוף Cloud de Confiance ואת Cloud Shell. מומלץ להכיר את Vertex AI Workbench, אבל לא חובה.

דיאגרמת ארכיטקטורה של שימוש ב-Private Service Connect כדי לגשת להסקות באצווה.

מטרות

  • יוצרים שתי רשתות של ענן וירטואלי פרטי (VPC), כמו שמוצג בתרשים הקודם:
    • אחד (vertex-networking-vpc) משמש לגישה לממשקי Google API להסקת מסקנות באצווה.
    • השני (onprem-vpc) מייצג רשת מקומית.
  • פורסים שערי HA VPN, מנהרות Cloud VPN ונתבי Cloud Router כדי לחבר בין vertex-networking-vpc ל-onprem-vpc.
  • יוצרים מודל היסק באצווה ב-Gemini Enterprise Agent Platform ומעלים אותו לקטגוריה של Cloud Storage.
  • צריך ליצור נקודת קצה (endpoint) של Private Service Connect ‏(PSC) כדי להעביר בקשות פרטיות ל-API בארכיטקטורת REST של Gemini Enterprise Agent Platform להסקת מסקנות באצווה.
  • מגדירים את מצב הפרסום בהתאמה אישית של Cloud Router ב-vertex-networking-vpc כדי להודיע על מסלולים לנקודת הקצה של Private Service Connect אל onprem-vpc.
  • יוצרים מכונה וירטואלית של Compute Engine ב-onprem-vpc כדי לייצג אפליקציית לקוח (on-prem-client) ששולחת בקשות להסקה באצווה באופן פרטי דרך HA VPN.

עלויות

במסמך הזה משתמשים ברכיבים הבאים של Cloud de Confiance by S3NS, והשימוש בהם כרוך בתשלום:

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

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

  1. נכנסים לדף לבחירת הפרויקט במסוף Cloud de Confiance .

    כניסה לדף לבחירת הפרויקט

  2. בוחרים או יוצרים פרויקט ב- Cloud de Confiance .

    התפקידים שנדרשים כדי לבחור או ליצור פרויקט

    • בחירת פרויקט: כדי לבחור פרויקט לא נדרש תפקיד IAM ספציפי – אתם יכולים לבחור כל פרויקט שקיבלתם בו תפקיד.
    • יצירת פרויקט: כדי ליצור פרויקט, צריך את התפקיד "יצירת פרויקטים" (roles/resourcemanager.projectCreator), שכולל את ההרשאה resourcemanager.projects.create. איך מקצים תפקידים?
  3. מוודאים שהחיוב מופעל בפרויקט ב- Cloud de Confiance .

  4. פותחים את Cloud Shell כדי להריץ את הפקודות שמפורטות במדריך הזה. ‫Cloud Shell היא סביבת מעטפת אינטראקטיבית של Cloud de Confiance , שמאפשרת לנהל את הפרויקטים והמשאבים מדפדפן האינטרנט.
  5. ב-Cloud Shell, מגדירים את הפרויקט הנוכחי למזהה הפרויקט ב- Cloud de Confiance by S3NS ושומרים את אותו מזהה פרויקט במשתנה המעטפת projectid:
      projectid="PROJECT_ID"
      gcloud config set project ${projectid}
    מחליפים את PROJECT_ID במזהה הפרויקט. במקרה הצורך, אפשר לאתר את מזהה הפרויקט במסוף Cloud de Confiance . מידע נוסף זמין במאמר איתור מזהה הפרויקט.
  6. אם אתם לא הבעלים של הפרויקט, בקשו מהבעלים להקצות לכם את התפקיד אדמין IAM של פרויקט (roles/resourcemanager.projectIamAdmin). אתם צריכים את התפקיד הזה כדי להקצות תפקידי IAM בשלב הבא.
  7. נותנים תפקידים לחשבון המשתמש. מריצים את הפקודה הבאה לכל אחד מהתפקידים הבאים ב-IAM: roles/compute.instanceAdmin.v1, roles/compute.networkAdmin, roles/compute.securityAdmin, roles/dns.admin, roles/iap.tunnelResourceAccessor, roles/notebooks.admin, roles/iam.serviceAccountAdmin, roles/iam.serviceAccountUser, roles/servicedirectory.editor, roles/serviceusage.serviceUsageAdmin, roles/storage.admin, roles/aiplatform.admin, roles/aiplatform.user, roles/resourcemanager.projectIamAdmin

    gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

    מחליפים את מה שכתוב בשדות הבאים:

  8. מפעילים את ממשקי ה-API הבאים, אם הם עדיין לא מופעלים: DNS,‏ Artifact Registry,‏ IAM,‏ Compute Engine,‏ Notebooks ו-Agent Platform.

    התפקידים שנדרשים כדי להפעיל ממשקי API

    כדי להפעיל ממשקי API, צריך את ההרשאה serviceusage.services.enable. אם יצרתם את הפרויקט, סביר להניח שכבר יש לכם את ההרשאה הזו דרך התפקיד "בעלים" (roles/owner). אחרת, תוכלו לקבל את ההרשאה הזו דרך התפקיד "אדמין בממשק 'שימוש בשירות'" (roles/serviceusage.serviceUsageAdmin). כך מקצים תפקידים.

    gcloud services enable dns.googleapis.com artifactregistry.googleapis.com iam.googleapis.com compute.googleapis.com notebooks.googleapis.com aiplatform.googleapis.com

יצירת רשתות ה-VPC

בקטע הזה, יוצרים שתי רשתות VPC: אחת כדי לגשת ל-Google APIs להסקת מסקנות באצווה, והשנייה כדי לדמות רשת מקומית. בכל אחת משתי רשתות ה-VPC, יוצרים Cloud Router ושער Cloud NAT. שער Cloud NAT מספק קישוריות יוצאת למכונות וירטואליות (VM) של Compute Engine ללא כתובות IP חיצוניות.

  1. יוצרים את רשת ה-VPC של vertex-networking-vpc:

    gcloud compute networks create vertex-networking-vpc \
      --subnet-mode custom
    
  2. ברשת vertex-networking-vpc, יוצרים תת-רשת בשם workbench-subnet עם טווח IPv4 ראשי של 10.0.1.0/28:

    gcloud compute networks subnets create workbench-subnet \
      --range=10.0.1.0/28 \
      --network=vertex-networking-vpc \
      --region=us-central1 \
      --enable-private-ip-google-access
    
  3. יוצרים את רשת ה-VPC כדי לדמות את הרשת המקומית (onprem-vpc):

    gcloud compute networks create onprem-vpc \
      --subnet-mode custom
    
  4. ברשת onprem-vpc, יוצרים תת-רשת בשם onprem-vpc-subnet1 עם טווח IPv4 ראשי של 172.16.10.0/29:

    gcloud compute networks subnets create onprem-vpc-subnet1 \
      --network onprem-vpc \
      --range 172.16.10.0/29 \
      --region us-central1
    

מוודאים שרשתות ה-VPC מוגדרות בצורה נכונה

  1. במסוף Cloud de Confiance , נכנסים לכרטיסייה Networks in current project בדף רשתות VPC.

    כניסה לדף VPC networks

  2. ברשימת רשתות ה-VPC, מוודאים ששתי הרשתות נוצרו: vertex-networking-vpc ו-onprem-vpc.

  3. לוחצים על הכרטיסייה Subnets in current project.

  4. ברשימת רשתות המשנה של ה-VPC, מוודאים שנוצרו רשתות המשנה workbench-subnet ו-onprem-vpc-subnet1.

הגדרת קישוריות היברידית

בקטע הזה תיצרו שני שערי HA VPN שמחוברים זה לזה. אחד נמצא ברשת ה-VPC של vertex-networking-vpc. השני נמצא ברשת ה-VPC של onprem-vpc. כל שער מכיל Cloud Router וזוג מנהרות VPN.

יצירת שערי HA VPN

  1. ב-Cloud Shell, יוצרים את שער ה-HA VPN לרשת ה-VPC של vertex-networking-vpc:

    gcloud compute vpn-gateways create vertex-networking-vpn-gw1 \
       --network vertex-networking-vpc \
       --region us-central1
    
  2. יוצרים את שער ה-HA VPN לרשת ה-VPC של onprem-vpc:

    gcloud compute vpn-gateways create onprem-vpn-gw1 \
       --network onprem-vpc \
       --region us-central1
    
  3. במסוף Cloud de Confiance , נכנסים לכרטיסייה Cloud VPN Gateways בדף VPN.

    מעבר אל VPN

  4. מוודאים שנוצרו שני השערים (vertex-networking-vpn-gw1 ו-onprem-vpn-gw1) ושלכל שער יש שתי כתובות IP של ממשקים.

יצירת Cloud Routers ושערי Cloud NAT

בכל אחת משתי רשתות ה-VPC, יוצרים שני נתבי Cloud Router: אחד כללי ואחד אזורי. בכל אחד מהנתבים האזוריים של Cloud Router, יוצרים שער Cloud NAT. שערי Cloud NAT מספקים קישוריות יוצאת למכונות וירטואליות (VM) של Compute Engine שאין להן כתובות IP חיצוניות.

  1. ב-Cloud Shell, יוצרים Cloud Router לרשת ה-VPC של vertex-networking-vpc:

    gcloud compute routers create vertex-networking-vpc-router1 \
       --region us-central1\
       --network vertex-networking-vpc \
       --asn 65001
    
  2. יוצרים Cloud Router לרשת ה-VPC של onprem-vpc:

    gcloud compute routers create onprem-vpc-router1 \
       --region us-central1\
       --network onprem-vpc\
       --asn 65002
    
  3. יוצרים Cloud Router אזורי לרשת ה-VPC של vertex-networking-vpc:

    gcloud compute routers create cloud-router-us-central1-vertex-nat \
      --network vertex-networking-vpc \
      --region us-central1
    
  4. מגדירים שער Cloud NAT ב-Cloud Router האזורי:

    gcloud compute routers nats create cloud-nat-us-central1 \
      --router=cloud-router-us-central1-vertex-nat \
      --auto-allocate-nat-external-ips \
      --nat-all-subnet-ip-ranges \
      --region us-central1
    
  5. יוצרים Cloud Router אזורי לרשת ה-VPC של onprem-vpc:

    gcloud compute routers create cloud-router-us-central1-onprem-nat \
      --network onprem-vpc \
      --region us-central1
    
  6. מגדירים שער Cloud NAT ב-Cloud Router האזורי:

    gcloud compute routers nats create cloud-nat-us-central1-on-prem \
      --router=cloud-router-us-central1-onprem-nat \
      --auto-allocate-nat-external-ips \
      --nat-all-subnet-ip-ranges \
      --region us-central1
    
  7. נכנסים לדף Cloud Routers במסוף Cloud de Confiance .

    כניסה לדף Cloud Routers

  8. ברשימה Cloud Routers, מוודאים שהנתבים הבאים נוצרו:

    • cloud-router-us-central1-onprem-nat
    • cloud-router-us-central1-vertex-nat
    • onprem-vpc-router1
    • vertex-networking-vpc-router1

    יכול להיות שתצטרכו לרענן את הכרטיסייה בדפדפן של מסוף Cloud de Confiance by S3NS כדי לראות את הערכים החדשים.

  9. ברשימת הנתבים של Cloud Router, לוחצים על cloud-router-us-central1-vertex-nat.

  10. בדף Router details, מוודאים שנוצר שער Cloud NAT של cloud-nat-us-central1.

  11. לוחצים על החץ חזרה כדי לחזור לדף Cloud Routers.

  12. ברשימת הנתבים, לוחצים על cloud-router-us-central1-onprem-nat.

  13. בדף Router details, מוודאים שנוצר שער Cloud NAT בשם cloud-nat-us-central1-on-prem.

יצירת מנהרות VPN

  1. ב-Cloud Shell, ברשת vertex-networking-vpc, יוצרים מנהרת VPN בשם vertex-networking-vpc-tunnel0:

    gcloud compute vpn-tunnels create vertex-networking-vpc-tunnel0 \
      --peer-gcp-gateway onprem-vpn-gw1 \
      --region us-central1 \
      --ike-version 2 \
      --shared-secret [ZzTLxKL8fmRykwNDfCvEFIjmlYLhMucH] \
      --router vertex-networking-vpc-router1 \
      --vpn-gateway vertex-networking-vpn-gw1 \
      --interface 0
    
  2. ברשת vertex-networking-vpc, יוצרים מנהרת VPN בשם vertex-networking-vpc-tunnel1:

    gcloud compute vpn-tunnels create vertex-networking-vpc-tunnel1 \
      --peer-gcp-gateway onprem-vpn-gw1 \
      --region us-central1 \
      --ike-version 2 \
      --shared-secret [bcyPaboPl8fSkXRmvONGJzWTrc6tRqY5] \
      --router vertex-networking-vpc-router1 \
      --vpn-gateway vertex-networking-vpn-gw1 \
      --interface 1
    
  3. ברשת onprem-vpc, יוצרים מנהרת VPN בשם onprem-vpc-tunnel0:

    gcloud compute vpn-tunnels create onprem-vpc-tunnel0 \
      --peer-gcp-gateway vertex-networking-vpn-gw1 \
      --region us-central1\
      --ike-version 2 \
      --shared-secret [ZzTLxKL8fmRykwNDfCvEFIjmlYLhMucH] \
      --router onprem-vpc-router1 \
      --vpn-gateway onprem-vpn-gw1 \
      --interface 0
    
  4. ברשת onprem-vpc, יוצרים מנהרת VPN בשם onprem-vpc-tunnel1:

    gcloud compute vpn-tunnels create onprem-vpc-tunnel1 \
      --peer-gcp-gateway vertex-networking-vpn-gw1 \
      --region us-central1\
      --ike-version 2 \
      --shared-secret [bcyPaboPl8fSkXRmvONGJzWTrc6tRqY5] \
      --router onprem-vpc-router1 \
      --vpn-gateway onprem-vpn-gw1 \
      --interface 1
    
  5. נכנסים לדף VPN במסוף Cloud de Confiance .

    מעבר אל VPN

  6. ברשימת מנהרות ה-VPN, מוודאים שנוצרו ארבע מנהרות VPN.

יצירת סשנים של BGP

‫Cloud Router משתמש ב-Border Gateway Protocol ‏(BGP) כדי להחליף נתיבים בין רשת ה-VPC (במקרה הזה, vertex-networking-vpc) לבין הרשת המקומית (שמיוצגת על ידי onprem-vpc). ב-Cloud Router, מגדירים ממשק ו-BGP peer לנתב המקומי. הממשק והגדרת ה-BGP peer יוצרים יחד סשן BGP. בקטע הזה יוצרים שני סשנים של BGP ל-vertex-networking-vpc ושניים ל-onprem-vpc.

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

הגדרת סשנים של BGP ל-vertex-networking-vpc

  1. ב-Cloud Shell, ברשת vertex-networking-vpc, יוצרים ממשק BGP בשביל vertex-networking-vpc-tunnel0:

    gcloud compute routers add-interface vertex-networking-vpc-router1 \
      --interface-name if-tunnel0-to-onprem \
      --ip-address 169.254.0.1 \
      --mask-length 30 \
      --vpn-tunnel vertex-networking-vpc-tunnel0 \
      --region us-central1
    
  2. ברשת vertex-networking-vpc, יוצרים קישור בין רשתות שכנות באמצעות BGP למנהרה bgp-onprem-tunnel0:

    gcloud compute routers add-bgp-peer vertex-networking-vpc-router1 \
      --peer-name bgp-onprem-tunnel0 \
      --interface if-tunnel0-to-onprem \
      --peer-ip-address 169.254.0.2 \
      --peer-asn 65002 \
      --region us-central1
    
  3. ברשת vertex-networking-vpc, יוצרים ממשק BGP ל-vertex-networking-vpc-tunnel1:

    gcloud compute routers add-interface vertex-networking-vpc-router1 \
      --interface-name if-tunnel1-to-onprem \
      --ip-address 169.254.1.1 \
      --mask-length 30 \
      --vpn-tunnel vertex-networking-vpc-tunnel1 \
      --region us-central1
    
  4. ברשת vertex-networking-vpc, יוצרים קישור בין רשתות שכנות באמצעות BGP למנהרה bgp-onprem-tunnel1:

    gcloud compute routers add-bgp-peer vertex-networking-vpc-router1 \
      --peer-name bgp-onprem-tunnel1 \
      --interface if-tunnel1-to-onprem \
      --peer-ip-address 169.254.1.2 \
      --peer-asn 65002 \
      --region us-central1
    

הגדרת סשנים של BGP ל-onprem-vpc

  1. ברשת onprem-vpc, יוצרים ממשק BGP ל-onprem-vpc-tunnel0:

    gcloud compute routers add-interface onprem-vpc-router1 \
      --interface-name if-tunnel0-to-vertex-networking-vpc \
      --ip-address 169.254.0.2 \
      --mask-length 30 \
      --vpn-tunnel onprem-vpc-tunnel0 \
      --region us-central1
    
  2. ברשת onprem-vpc, יוצרים קישור בין רשתות שכנות באמצעות BGP למנהרה bgp-vertex-networking-vpc-tunnel0:

    gcloud compute routers add-bgp-peer onprem-vpc-router1 \
      --peer-name bgp-vertex-networking-vpc-tunnel0 \
      --interface if-tunnel0-to-vertex-networking-vpc \
      --peer-ip-address 169.254.0.1 \
      --peer-asn 65001 \
      --region us-central1
    
  3. ברשת onprem-vpc, יוצרים ממשק BGP ל-onprem-vpc-tunnel1:

    gcloud compute routers add-interface   onprem-vpc-router1  \
      --interface-name if-tunnel1-to-vertex-networking-vpc \
      --ip-address 169.254.1.2 \
      --mask-length 30 \
      --vpn-tunnel onprem-vpc-tunnel1 \
      --region us-central1
    
  4. ברשת onprem-vpc, יוצרים קישור בין רשתות שכנות באמצעות BGP למנהרה bgp-vertex-networking-vpc-tunnel1:

    gcloud compute routers add-bgp-peer onprem-vpc-router1 \
      --peer-name bgp-vertex-networking-vpc-tunnel1 \
      --interface if-tunnel1-to-vertex-networking-vpc \
      --peer-ip-address 169.254.1.1 \
      --peer-asn 65001 \
      --region us-central1
    

אימות היצירה של סשן BGP

  1. נכנסים לדף VPN במסוף Cloud de Confiance .

    מעבר אל VPN

  2. ברשימת מנהרות ה-VPN, מוודאים שהערך בעמודה BGP session status של כל אחת מהמנהרות השתנה מ-Configure BGP session ל-BGP established. יכול להיות שתצטרכו לרענן את הכרטיסייה של מסוף Cloud de Confiance by S3NS בדפדפן כדי לראות את הערכים החדשים.

אימות של vertex-networking-vpc הנתיבים שנלמדו

  1. במסוף Cloud de Confiance , נכנסים לדף רשתות VPC.

    כניסה לדף VPC networks

  2. ברשימת רשתות ה-VPC, לוחצים על vertex-networking-vpc.

  3. לוחצים על הכרטיסייה מסלולים.

  4. בוחרים באפשרות us-central1 (Iowa)‎ ברשימה Region ולוחצים על View.

  5. בעמודה Destination IP range, מוודאים שטווח ה-IP של רשת המשנה onprem-vpc-subnet1 (172.16.10.0/29) מופיע פעמיים.

אימות של onprem-vpc הנתיבים שנלמדו

  1. לוחצים על החץ חזרה כדי לחזור לדף רשתות VPC.

  2. ברשימת רשתות ה-VPC, לוחצים על onprem-vpc.

  3. לוחצים על הכרטיסייה מסלולים.

  4. בוחרים באפשרות us-central1 (Iowa)‎ ברשימה Region ולוחצים על View.

  5. בעמודה Destination IP range, מוודאים שטווח כתובות ה-IP של תת-הרשת workbench-subnet (10.0.1.0/28) מופיע פעמיים.

יצירת נקודת קצה לצרכן ב-Private Service Connect

  1. ב-Cloud Shell, שומרים כתובת IP של נקודת קצה (endpoint) של צרכן, שתשמש לגישה ל-Google APIs:

    gcloud compute addresses create psc-googleapi-ip \
      --global \
      --purpose=PRIVATE_SERVICE_CONNECT \
      --addresses=192.168.0.1 \
      --network=vertex-networking-vpc
    
  2. יוצרים כלל העברה כדי לקשר את נקודת הקצה לממשקי ה-API ולשירותים של Google.

    gcloud compute forwarding-rules create pscvertex \
     --global \
     --network=vertex-networking-vpc\
     --address=psc-googleapi-ip \
     --target-google-apis-bundle=all-apis
    

יצירת נתיבים מותאמים אישית שפורסמו עבור vertex-networking-vpc

בקטע הזה, מגדירים את מצב הפרסום בהתאמה אישית של Cloud Router ל-Advertise custom IP ranges עבור vertex-networking-vpc-router1 (ה-Cloud Router של vertex-networking-vpc) כדי לפרסם את כתובת ה-IP של נקודת הקצה של ה-PSC ברשת onprem-vpc.

  1. נכנסים לדף Cloud Routers במסוף Cloud de Confiance .

    כניסה לדף Cloud Routers

  2. ברשימה של Cloud Router, לוחצים על vertex-networking-vpc-router1.

  3. בדף Router details לוחצים על Edit.

  4. בקטע Advertised routes, בוחרים באפשרות Create custom routes בשדה Routes.

  5. כדי להמשיך לפרסם את רשתות המשנה שזמינות ל-Cloud Router, מסמנים את התיבה Advertise all subnets visible to the Cloud Router. הפעלת האפשרות הזו מחקה את ההתנהגות של Cloud Router במצב פרסום ברירת מחדל.

  6. לוחצים על הוספת נתיב בהתאמה אישית.

  7. בשדה Source, בוחרים באפשרות Custom IP range.

  8. בשדה טווח כתובות IP, מזינים את כתובת ה-IP הבאה:

    192.168.0.1
    
  9. בשדה Description, מזינים את הטקסט הבא:

    Custom route to advertise Private Service Connect endpoint IP address
    
  10. לוחצים על סיום ואז על שמירה.

מוודאים ש-onprem-vpc למד את המסלולים שפורסמו

  1. נכנסים לדף Routes במסוף Cloud de Confiance .

    לדף Routes

  2. בכרטיסייה Effective routes, מבצעים את הפעולות הבאות:

    1. בשדה Network, בוחרים באפשרות onprem-vpc.
    2. בשדה Region, בוחרים באפשרות us-central1 (Iowa).
    3. לוחצים על הצגה.
    4. ברשימת הנתיבים, מוודאים שיש רשומות שהשמות שלהן מתחילים ב-onprem-vpc-router1-bgp-vertex-networking-vpc-tunnel0 וב-onprem-vpc-router1-bgp-vfertex-networking-vpc-tunnel1, ושלשתיהן יש טווח כתובות IP של יעד של 192.168.0.1.

      אם הרשומות האלה לא מופיעות מיד, המתינו כמה דקות ורעננו את הכרטיסייה של מסוף Cloud de Confiance by S3NS בדפדפן.

יצירת מכונה וירטואלית ב-onprem-vpc שמשתמשת בחשבון שירות שמנוהל על ידי משתמש

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

יצירת חשבון שירות שמנוהל על ידי משתמשים

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

    projectid=PROJECT_ID
    gcloud config set project ${projectid}
    
  2. יוצרים חשבון שירות בשם onprem-user-managed-sa:

    gcloud iam service-accounts create onprem-user-managed-sa \
      --display-name="onprem-user-managed-sa-onprem-client"
    
  3. מקצים לחשבון השירות את התפקיד משתמש בפלטפורמת Agent‏ (roles/aiplatform.user):

    gcloud projects add-iam-policy-binding $projectid \
      --member="serviceAccount:onprem-user-managed-sa@$projectid.s3ns.iam.gserviceaccount.com" \
      --role="roles/aiplatform.user"
    
  4. מקצים לחשבון השירות את התפקיד צפייה באובייקט אחסון (storage.objectViewer):

    gcloud projects add-iam-policy-binding $projectid \
      --member="serviceAccount:onprem-user-managed-sa@$projectid.s3ns.iam.gserviceaccount.com" \
      --role="roles/storage.objectViewer"
    

יצירת מכונה וירטואלית של on-prem-client

למכונה הווירטואלית שאתם יוצרים אין כתובת IP חיצונית, והיא לא מאפשרת גישה ישירה דרך האינטרנט. כדי לאפשר גישה אדמיניסטרטיבית למכונה הווירטואלית, משתמשים בהעברת TCP של שרת proxy לאימות זהויות (IAP).

  1. ב-Cloud Shell, יוצרים את המכונה הווירטואלית של on-prem-client:

    gcloud compute instances create on-prem-client \
      --zone=us-central1-a \
      --image-family=debian-11 \
      --image-project=debian-cloud \
      --subnet=onprem-vpc-subnet1 \
      --scopes=https://www.googleapis.com/auth/cloud-platform \
      --no-address \
      --shielded-secure-boot \
      --service-account=onprem-user-managed-sa@$projectid.s3ns.iam.gserviceaccount.com \
      --metadata startup-script="#! /bin/bash
        sudo apt-get update
        sudo apt-get install tcpdump dnsutils -y"
    
    
  2. יוצרים כלל של חומת אש שמאפשר ל-IAP להתחבר למכונה הווירטואלית:

    gcloud compute firewall-rules create ssh-iap-on-prem-vpc \
      --network onprem-vpc \
      --allow tcp:22 \
      --source-ranges=35.235.240.0/20
    

אימות הגישה הציבורית ל-Agent Platform API

בקטע הזה משתמשים בכלי dig כדי לבצע חיפוש DNS ממכונת ה-VM של on-prem-client ל-Agent Platform API‏ (us-central1-aiplatform.googleapis.com). הפלט של dig מראה שבגישה שמוגדרת כברירת מחדל, נעשה שימוש רק בכתובות VIP ציבוריות כדי לגשת ל-Agent Platform API.

בקטע הבא תגדירו גישה פרטית ל-API של Gemini Enterprise Agent Platform.

  1. ב-Cloud Shell, מתחברים למכונה הווירטואלית on-prem-client באמצעות IAP:

    gcloud compute ssh on-prem-client \
      --zone=us-central1-a \
      --tunnel-through-iap
    
  2. במכונה הווירטואלית של on-prem-client, מריצים את הפקודה dig:

    dig us-central1-aiplatform.googleapis.com
    

    אמור להופיע פלט של dig שדומה לזה, שבו כתובות ה-IP בקטע התשובה הן כתובות IP ציבוריות:

    ; <<>> DiG 9.16.44-Debian <<>> us-central1.aiplatfom.googleapis.com
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42506
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 16, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 512
    ;; QUESTION SECTION:
    ;us-central1.aiplatfom.googleapis.com. IN A
    
    ;; ANSWER SECTION:
    us-central1.aiplatfom.googleapis.com. 300 IN A  173.194.192.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  142.250.152.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  172.217.219.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  209.85.146.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  209.85.147.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  142.250.125.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  142.250.136.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  142.250.148.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  209.85.200.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  209.85.234.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  142.251.171.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  108.177.112.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  142.250.128.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  142.251.6.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  172.217.212.95
    us-central1.aiplatfom.googleapis.com. 300 IN A  74.125.124.95
    
    ;; Query time: 8 msec
    ;; SERVER: 169.254.169.254#53(169.254.169.254)
    ;; WHEN: Wed Sep 27 04:10:16 UTC 2023
    ;; MSG SIZE  rcvd: 321
    

הגדרה ואימות של גישה פרטית ל-Agent Platform API

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

עדכון הקובץ /etc/hosts כך שיפנה לנקודת הקצה של ה-PSC

בשלב הזה מוסיפים שורה לקובץ /etc/hosts, כדי שהבקשות שנשלחות לנקודת הקצה של השירות הציבורי (us-central1-aiplatform.googleapis.com) יופנו לנקודת הקצה של ה-PSC‏ (192.168.0.1).

  1. במכונה הווירטואלית on-prem-client, משתמשים בכלי לעריכת טקסט כמו vim או nano כדי לפתוח את הקובץ /etc/hosts:

    sudo vim /etc/hosts
    
  2. מוסיפים את השורה הבאה לקובץ:

    192.168.0.1 us-central1-aiplatform.googleapis.com
    

    השורה הזו מקצה את כתובת ה-IP של נקודת הקצה של ה-PSC (192.168.0.1) לשם דומיין שמוגדר במלואו עבור Google API של Gemini Enterprise Agent Platform (us-central1-aiplatform.googleapis.com).

    הקובץ הערוך אמור להיראות כך:

    127.0.0.1       localhost
    ::1             localhost ip6-localhost ip6-loopback
    ff02::1         ip6-allnodes
    ff02::2         ip6-allrouters
    
    192.168.0.1 us-central1-aiplatform.googleapis.com  # Added by you
    172.16.10.6 on-prem-client.us-central1-a.c.vertex-genai-400103.internal on-prem-client  # Added by Google
    169.254.169.254 metadata.google.internal  # Added by Google
    
  3. שומרים את הקובץ באופן הבא:

    • אם משתמשים ב-vim, לוחצים על המקש Esc ואז מקלידים :wq כדי לשמור את הקובץ ולצאת.
    • אם אתם משתמשים ב-nano, מקלידים Control+O ולוחצים על Enter כדי לשמור את הקובץ, ואז מקלידים Control+X כדי לצאת.
  4. שולחים פינג לנקודת הקצה של Gemini Enterprise Agent Platform באופן הבא:

    ping us-central1-aiplatform.googleapis.com
    

    הפלט הבא אמור להתקבל באמצעות הפקודה ping: ‫192.168.0.1 היא כתובת ה-IP של נקודת הקצה של ה-PSC:

    PING us-central1-aiplatform.googleapis.com (192.168.0.1) 56(84) bytes of data.
    
  5. מקלידים Control+C כדי לצאת מ-ping.

  6. מקלידים exit כדי לצאת מהמכונה הווירטואלית on-prem-client.

יוצרים חשבון שירות שמנוהל על ידי משתמש בשביל Vertex AI Workbench ב-vertex-networking-vpc

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

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

    projectid=PROJECT_ID
    gcloud config set project ${projectid}
    
  2. יוצרים חשבון שירות בשם workbench-sa:

    gcloud iam service-accounts create workbench-sa \
      --display-name="workbench-sa"
    
  3. מקצים לחשבון השירות את התפקיד משתמש בפלטפורמת הסוכנים (roles/aiplatform.user) ב-IAM:

    gcloud projects add-iam-policy-binding $projectid \
      --member="serviceAccount:workbench-sa@$projectid.s3ns.iam.gserviceaccount.com" \
      --role="roles/aiplatform.user"
    
  4. מקצים לחשבון השירות את התפקיד BigQuery User (roles/bigquery.user) ב-IAM:

    gcloud projects add-iam-policy-binding $projectid \
      --member="serviceAccount:workbench-sa@$projectid.s3ns.iam.gserviceaccount.com" \
      --role="roles/bigquery.user"
    
  5. מקצים לחשבון השירות את התפקיד אדמין של Storage‏ (roles/storage.admin) ב-IAM:

    gcloud projects add-iam-policy-binding $projectid \
      --member="serviceAccount:workbench-sa@$projectid.s3ns.iam.gserviceaccount.com" \
      --role="roles/storage.admin"
    
  6. מקצים לחשבון השירות את התפקיד צפייה ביומנים (roles/logging.viewer) ב-IAM:

    gcloud projects add-iam-policy-binding $projectid \
      --member="serviceAccount:workbench-sa@$projectid.s3ns.iam.gserviceaccount.com" \
      --role="roles/logging.viewer"
    

יצירת מכונה של Agent Platform Workbench

  1. ב-Cloud Shell, יוצרים מכונה של Agent Platform Workbench ומציינים את חשבון השירות workbench-sa:

    gcloud workbench instances create workbench-tutorial \
      --vm-image-project=deeplearning-platform-release \
      --vm-image-family=common-cpu-notebooks \
      --machine-type=n1-standard-4 \
      --location=us-central1-a \
      --subnet-region=us-central1 \
      --shielded-secure-boot=True \
      --subnet=workbench-subnet \
      --disable-public-ip \
      --service-account-email=workbench-sa@$projectid.s3ns.iam.gserviceaccount.com
    
  2. במסוף Cloud de Confiance , נכנסים לכרטיסייה Instances בדף Gemini Enterprise Agent Platform Workbench.

    כניסה ל-Agent Platform Workbench

  3. ליד השם של המכונה של Agent Platform Workbench (workbench-tutorial), לוחצים על Open JupyterLab.

    מכונת Agent Platform Workbench פותחת את JupyterLab.

  4. לוחצים על File > New > Notebook.

  5. בתפריט Select Kernel, בוחרים באפשרות Python 3 (Local)‎ ולוחצים על Select.

  6. כשפותחים את ה-notebook החדש, מופיע תא קוד שמוגדר כברירת מחדל, שבו אפשר להזין קוד. הוא נראה כמו [ ]: ואחריו שדה טקסט. שדה הטקסט הוא המקום שבו מדביקים את הקוד.

    כדי להתקין את Agent Platform SDK ל-Python, מדביקים את הקוד הבא בתא ולוחצים על  Run the selected cells and advance:

    !pip3 install --upgrade google-cloud-bigquery scikit-learn==1.2
    
  7. בשלב הזה ובכל אחד מהשלבים הבאים, מוסיפים תא קוד חדש (אם צריך) בלחיצה על Insert a cell below, מדביקים את הקוד בתא ולוחצים על  Run the selected cells and advance.

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

    # Restart kernel after installs so that your environment can access the new packages
    import IPython
    
    app = IPython.Application.instance()
    app.kernel.do_shutdown(True)
    
  8. מגדירים את משתני הסביבה הבאים ב-notebook של JupyterLab, ומחליפים את PROJECT_ID במזהה הפרויקט.

    # set project ID and location
    PROJECT_ID = "PROJECT_ID"
    REGION = "us-central1"
    
  9. יוצרים קטגוריה של Cloud Storage להכנת משימת האימון:

    BUCKET_NAME = f"{PROJECT_ID}-ml-staging"
    BUCKET_URI = f"gs://{BUCKET_NAME}"
    !gcloud storage buckets create {BUCKET_URI} --location={REGION} --project={PROJECT_ID}
    

הכנת נתוני האימון

בקטע הזה מכינים את הנתונים שישמשו לאימון מודל היסק (inference).

  1. ב-notebook של JupyterLab, יוצרים לקוח BigQuery:

    from google.cloud import bigquery
    bq_client = bigquery.Client(project=PROJECT_ID)
    
  2. אחזור נתונים ממערך הנתונים הציבורי ml_datasets של BigQuery:

    DATA_SOURCE = "bigquery-public-data.ml_datasets.census_adult_income"
    # Define the SQL query to fetch the dataset
    query = f"""
    SELECT * FROM `{DATA_SOURCE}` LIMIT 20000
    """
    # Download the dataset to a dataframe
    df = bq_client.query(query).to_dataframe()
    df.head()
    
  3. משתמשים בספרייה sklearn כדי לפצל את הנתונים לאימון ולבדיקה:

    from sklearn.model_selection import train_test_split
    # Split the dataset
    X_train, X_test = train_test_split(df, test_size=0.3, random_state=43)
    # Print the shapes of train and test sets
    print(X_train.shape, X_test.shape)
    
  4. מייצאים את מסגרות הנתונים של האימון והבדיקה לקובצי CSV בקטגוריית ה-staging:

    X_train.to_csv(f"{BUCKET_URI}/train.csv",index=False, quoting=1, quotechar='"')
    X_test[[i for i in X_test.columns if i != "income_bracket"]].iloc[:20].to_csv(f"{BUCKET_URI}/test.csv",index=False,quoting=1, quotechar='"')
    

הכנת אפליקציית האימון

בקטע הזה תיצרו ותפתחו את אפליקציית האימון ב-Python ותשמרו אותה בקטגוריית ה-Staging.

  1. ב-notebook של JupyterLab, יוצרים תיקייה חדשה לקובצי אפליקציית האימון:

    !mkdir -p training_package/trainer
    

    עכשיו אמורה להופיע תיקייה בשם training_package בתפריט הניווט של JupyterLab.

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

    %%writefile training_package/trainer/task.py
    from sklearn.ensemble import RandomForestClassifier
    from sklearn.feature_selection import SelectKBest
    from sklearn.pipeline import FeatureUnion, Pipeline
    from sklearn.preprocessing import LabelBinarizer
    import pandas as pd
    import argparse
    import joblib
    import os
    
    TARGET = "income_bracket"
    # Define the feature columns that you use from the dataset
    COLUMNS = (
      "age",
      "workclass",
      "functional_weight",
      "education",
      "education_num",
      "marital_status",
      "occupation",
      "relationship",
      "race",
      "sex",
      "capital_gain",
      "capital_loss",
      "hours_per_week",
      "native_country",
    )
    
    # Categorical columns are columns that have string values and
    # need to be turned into a numerical value to be used for training
    CATEGORICAL_COLUMNS = (
      "workclass",
      "education",
      "marital_status",
      "occupation",
      "relationship",
      "race",
      "sex",
      "native_country",
    )
    
    # load the arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('--training-dir', dest='training_dir', default=os.getenv('AIP_MODEL_DIR'), type=str,help='get the staging directory')
    args = parser.parse_args()
    
    # Load the training data
    X_train = pd.read_csv(os.path.join(args.training_dir,"train.csv"))
    # Remove the column we are trying to predict ('income-level') from our features list
    # Convert the Dataframe to a lists of lists
    train_features = X_train.drop(TARGET, axis=1).to_numpy().tolist()
    # Create our training labels list, convert the Dataframe to a lists of lists
    train_labels = X_train[TARGET].to_numpy().tolist()
    
    # Since the census data set has categorical features, we need to convert
    # them to numerical values. We'll use a list of pipelines to convert each
    # categorical column and then use FeatureUnion to combine them before calling
    # the RandomForestClassifier.
    categorical_pipelines = []
    
    # Each categorical column needs to be extracted individually and converted to a numerical value.
    # To do this, each categorical column will use a pipeline that extracts one feature column via
    # SelectKBest(k=1) and a LabelBinarizer() to convert the categorical value to a numerical one.
    # A scores array (created below) will select and extract the feature column. The scores array is
    # created by iterating over the COLUMNS and checking if it is a CATEGORICAL_COLUMN.
    for i, col in enumerate(COLUMNS):
       if col in CATEGORICAL_COLUMNS:
          # Create a scores array to get the individual categorical column.
          # Example:
          #  data = [39, 'State-gov', 77516, 'Bachelors', 13, 'Never-married', 'Adm-clerical',
          #         'Not-in-family', 'White', 'Male', 2174, 0, 40, 'United-States']
          #  scores = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
          #
          # Returns: [['Sate-gov']]
          scores = []
          # Build the scores array
          for j in range(len(COLUMNS)):
             if i == j:  # This column is the categorical column we want to extract.
                scores.append(1)  # Set to 1 to select this column
             else:  # Every other column should be ignored.
                scores.append(0)
          skb = SelectKBest(k=1)
          skb.scores_ = scores
          # Convert the categorical column to a numerical value
          lbn = LabelBinarizer()
          r = skb.transform(train_features)
          lbn.fit(r)
          # Create the pipeline to extract the categorical feature
          categorical_pipelines.append(
             (
                "categorical-{}".format(i),
                Pipeline([("SKB-{}".format(i), skb), ("LBN-{}".format(i), lbn)]),
             )
          )
    
    # Create pipeline to extract the numerical features
    skb = SelectKBest(k=6)
    # From COLUMNS use the features that are numerical
    skb.scores_ = [1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0]
    categorical_pipelines.append(("numerical", skb))
    
    # Combine all the features using FeatureUnion
    preprocess = FeatureUnion(categorical_pipelines)
    
    # Create the classifier
    classifier = RandomForestClassifier()
    
    # Transform the features and fit them to the classifier
    classifier.fit(preprocess.transform(train_features), train_labels)
    
    # Create the overall model as a single pipeline
    pipeline = Pipeline([("union", preprocess), ("classifier", classifier)])
    
    # Save the model pipeline
    joblib.dump(pipeline, os.path.join(args.training_dir,"model.joblib"))
    
  3. יוצרים קובץ __init__.py בכל תת-ספרייה כדי להפוך אותה לחבילה:

    !touch training_package/__init__.py
    !touch training_package/trainer/__init__.py
    
  4. יוצרים סקריפט הגדרות של חבילת Python:

    %%writefile training_package/setup.py
    from setuptools import find_packages
    from setuptools import setup
    
    setup(
       name='trainer',
       version='0.1',
       packages=find_packages(),
       include_package_data=True,
       description='Training application package for census income classification.'
    )
    
  5. משתמשים בפקודה sdist כדי ליצור את הפצת המקור של אפליקציית האימון:

    !cd training_package && python setup.py sdist --formats=gztar
    
  6. מעתיקים את חבילת Python לקטגוריית ה-staging:

    !gcloud storage cp training_package/dist/trainer-0.1.tar.gz $BUCKET_URI/
    
  7. מוודאים שקטגוריית ה-Staging מכילה שלושה קבצים:

    !gcloud storage ls $BUCKET_URI
    

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

    gs://$BUCKET_NAME/test.csv
    gs://$BUCKET_NAME/train.csv
    gs://$BUCKET_NAME/trainer-0.1.tar.gz
    

אימון המודל

בקטע הזה תאמנו את המודל באמצעות יצירה והרצה של משימת אימון בהתאמה אישית.

  1. ב-JupyterLab notebook, מריצים את הפקודה הבאה כדי ליצור משימת אימון בהתאמה אישית:

    !gcloud ai custom-jobs create --display-name=income-classification-training-job \
       --project=$PROJECT_ID \
       --worker-pool-spec=replica-count=1,machine-type='e2-highmem-2',executor-image-uri='us-docker.pkg.dev/vertex-ai/training/sklearn-cpu.1-0:latest',python-module=trainer.task \
       --python-package-uris=$BUCKET_URI/trainer-0.1.tar.gz \
       --args="--training-dir","/gcs/$BUCKET_NAME" \
       --region=$REGION
    

    הפלט אמור להיראות כך: המספר הראשון בכל נתיב של משימה מותאמת אישית הוא מספר הפרויקט (PROJECT_NUMBER). המספר השני הוא המזהה של המשימה המותאמת אישית (CUSTOM_JOB_ID). שימו לב למספרים האלה, כי תצטרכו להשתמש בהם בשלב הבא.

    Using endpoint [https://us-central1-aiplatform.googleapis.com/]
    CustomJob [projects/721032480027/locations/us-central1/customJobs/1100328496195960832] is submitted successfully.
    
    Your job is still active. You may view the status of your job with the command
    
    $ gcloud ai custom-jobs describe projects/721032480027/locations/us-central1/customJobs/1100328496195960832
    
    or continue streaming the logs with the command
    
    $ gcloud ai custom-jobs stream-logs projects/721032480027/locations/us-central1/customJobs/1100328496195960832
    
  2. מריצים את משימת האימון בהתאמה אישית ומציגים את ההתקדמות באמצעות סטרימינג של יומנים מהמשימה בזמן שהיא פועלת:

    !gcloud ai custom-jobs stream-logs projects/PROJECT_NUMBER/locations/us-central1/customJobs/CUSTOM_JOB_ID
    

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

    • ‫PROJECT_NUMBER: מספר הפרויקט מהפלט של הפקודה הקודמת
    • CUSTOM_JOB_ID: מזהה המשימה הייעודית מהפלט של הפקודה הקודמת

    משימת האימון בהתאמה אישית פועלת עכשיו. התהליך נמשך כ-10 דקות.

    בסיום המשימה, אתם יכולים לייבא את המודל מקטגוריית ה-Staging אל מרשם המודלים של Gemini Enterprise Agent Platform.

ייבוא המודל

משימת האימון בהתאמה אישית מעלה את המודל שאומן לקטגוריית ה-staging. בסיום המשימה, אתם יכולים לייבא את המודל מהקטגוריה אל מרשם המודלים ב-Gemini Enterprise Agent Platform.

  1. ב-notebook של JupyterLab, מייבאים את המודל באמצעות הפקודה הבאה:

    !gcloud ai models upload --container-image-uri="us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.1-2:latest" \
       --display-name=income-classifier-model \
       --artifact-uri=$BUCKET_URI \
       --project=$PROJECT_ID \
       --region=$REGION
    
  2. מציגים את המודלים של Gemini Enterprise Agent Platform בפרויקט באופן הבא:

    !gcloud ai models list --region=us-central1
    

    הפלט אמור להיראות כך: אם יש ברשימה שני מודלים או יותר, המודל הראשון ברשימה הוא המודל האחרון שייבאתם.

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

    Using endpoint [https://us-central1-aiplatform.googleapis.com/]
    MODEL_ID             DISPLAY_NAME
    1871528219660779520  income-classifier-model
    

    אפשר גם להציג את המודלים בפרויקט באופן הבא:

    במסוף Cloud de Confiance , בקטע Agent Platform, נכנסים לדף Gemini Enterprise Agent Platform Model Registry.

    לדף Model Registry ב-Gemini Enterprise Agent Platform

    כדי לראות את מזהי המודלים ופרטים נוספים על מודל מסוים, לוחצים על שם המודל ואז על הכרטיסייה Version Details.

קבלת הסקות באצווה מהמודל

עכשיו אתם יכולים לבקש הסקות באצווה מהמודל. בקשות ההסקה באצווה נשלחות ממכונת ה-VM‏ on-prem-client.

יצירת בקשה להסקת מסקנות באצווה

בשלב הזה משתמשים ב-ssh כדי להתחבר למכונה הווירטואלית on-prem-client. במכונה הווירטואלית, יוצרים קובץ טקסט בשם request.json שמכיל את המטען הייעודי (payload) של בקשת curl לדוגמה, ששולחים למודל כדי לקבל הסקות באצווה.

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

    projectid=PROJECT_ID
    gcloud config set project ${projectid}
    
  2. מתחברים למכונה הווירטואלית של on-prem-client באמצעות ssh:

    gcloud compute ssh on-prem-client \
      --project=$projectid \
      --zone=us-central1-a
    
  3. במכונה הווירטואלית on-prem-client, משתמשים בכלי לעריכת טקסט כמו vim או nano כדי ליצור קובץ חדש בשם request.json שמכיל את הטקסט הבא:

    {
      "displayName": "income-classification-batch-job",
      "model": "projects/PROJECT_ID/locations/us-central1/models/MODEL_ID",
      "inputConfig": {
        "instancesFormat": "csv",
        "gcsSource": {
          "uris": ["BUCKET_URI/test.csv"]
        }
      },
      "outputConfig": {
        "predictionsFormat": "jsonl",
        "gcsDestination": {
          "outputUriPrefix": "BUCKET_URI"
        }
      },
      "dedicatedResources": {
        "machineSpec": {
          "machineType": "n1-standard-4",
          "acceleratorCount": "0"
        },
        "startingReplicaCount": 1,
        "maxReplicaCount": 2
      }
    }
    

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

    • ‫PROJECT_ID: מזהה הפרויקט
    • ‫MODEL_ID: מזהה המודל שלכם
    • ‫BUCKET_URI: ה-URI של קטגוריית האחסון שבה המודל הועלה ל-Staging
  4. מריצים את הפקודה הבאה כדי לשלוח את בקשת ההסקה באצווה:

    curl -X POST \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       -H "Content-Type: application/json; charset=utf-8" \
       -d @request.json \
       "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/batchPredictionJobs"
    

    מחליפים את PROJECT_ID במזהה הפרויקט.

    השורה הבאה אמורה להופיע בתשובה:

    "state": "JOB_STATE_PENDING"
    

    משימת ההסקה באצווה פועלת עכשיו באופן אסינכרוני. הבדיקה נמשכת כ-20 דקות.

  5. במסוף Cloud de Confiance , בקטע Agent Platform, נכנסים לדף Batch predictions.

    כניסה לדף Batch predictions

    בזמן שמשימת ההסקה באצווה פועלת, הסטטוס שלה הוא Running. כשהתהליך מסתיים, הסטטוס משתנה ל-Finished.

  6. לוחצים על השם של משימת ההסקה באצווה (income-classification-batch-job), ואז על הקישור Export location בדף הפרטים כדי לראות את קובצי הפלט של המשימה באצווה ב-Cloud Storage.

    אפשר גם ללחוץ על הסמל View prediction output on Cloud Storage (בין העמודה Last updated לתפריט Actions).

  7. לוחצים על הקישור לקובץ prediction.results-00000-of-00002 או prediction.results-00001-of-00002, ואז לוחצים על הקישור כתובת URL לאימות כדי לפתוח את הקובץ.

    הפלט של משימת הסקת הנתונים באצווה אמור להיראות כמו בדוגמה הבאה:

    {"instance": ["27", " Private", "391468", " 11th", "7", " Divorced", " Craft-repair", " Own-child", " White", " Male", "0", "0", "40", " United-States"], "prediction": " <=50K"}
    {"instance": ["47", " Self-emp-not-inc", "192755", " HS-grad", "9", " Married-civ-spouse", " Machine-op-inspct", " Wife", " White", " Female", "0", "0", "20", " United-States"], "prediction": " <=50K"}
    {"instance": ["32", " Self-emp-not-inc", "84119", " HS-grad", "9", " Married-civ-spouse", " Craft-repair", " Husband", " White", " Male", "0", "0", "45", " United-States"], "prediction": " <=50K"}
    {"instance": ["32", " Private", "236543", " 12th", "8", " Divorced", " Protective-serv", " Own-child", " White", " Male", "0", "0", "54", " Mexico"], "prediction": " <=50K"}
    {"instance": ["60", " Private", "160625", " HS-grad", "9", " Married-civ-spouse", " Prof-specialty", " Husband", " White", " Male", "5013", "0", "40", " United-States"], "prediction": " <=50K"}
    {"instance": ["34", " Local-gov", "22641", " HS-grad", "9", " Never-married", " Protective-serv", " Not-in-family", " Amer-Indian-Eskimo", " Male", "0", "0", "40", " United-States"], "prediction": " <=50K"}
    {"instance": ["32", " Private", "178623", " HS-grad", "9", " Never-married", " Other-service", " Not-in-family", " Black", " Female", "0", "0", "40", " ?"], "prediction": " <=50K"}
    {"instance": ["28", " Private", "54243", " HS-grad", "9", " Divorced", " Transport-moving", " Not-in-family", " White", " Male", "0", "0", "60", " United-States"], "prediction": " <=50K"}
    {"instance": ["29", " Local-gov", "214385", " 11th", "7", " Divorced", " Other-service", " Unmarried", " Black", " Female", "0", "0", "20", " United-States"], "prediction": " <=50K"}
    {"instance": ["49", " Self-emp-inc", "213140", " HS-grad", "9", " Married-civ-spouse", " Exec-managerial", " Husband", " White", " Male", "0", "1902", "60", " United-States"], "prediction": " >50K"}
    

הסרת המשאבים

כדי להימנע מצבירת חיובים בחשבון Cloud de Confiance by S3NS על המשאבים שבהם השתמשתם במדריך הזה, אתם יכולים למחוק את הפרויקט שמכיל את המשאבים, או להשאיר את הפרויקט ולמחוק את המשאבים הנפרדים.

כדי למחוק את המשאבים הנפרדים במסוף Cloud de Confiance :

  1. כדי למחוק את משימת הסקת הנתונים באצווה:

    1. במסוף Cloud de Confiance , בקטע Agent Platform, נכנסים לדף Batch predictions.

      כניסה לדף Batch predictions

    2. ליד השם של משימת החיזוי באצווה (income-classification-batch-job), לוחצים על תפריט הפעולות ובוחרים באפשרות מחיקת משימת החיזוי באצווה.

  2. כדי למחוק את המודל:

    1. במסוף Cloud de Confiance , בקטע Agent Platform, נכנסים לדף מרשם המודלים.

      כניסה לדף Model Registry

    2. ליד שם המודל (income-classifier-model), לוחצים על תפריט Actions ובוחרים באפשרות Delete model.

  3. כדי למחוק את המכונה של Agent Platform Workbench:

    1. במסוף Cloud de Confiance , בקטע Gemini Enterprise Agent Platform, נכנסים לכרטיסייה Instances בדף Workbench.

      כניסה ל-Agent Platform Workbench

    2. בוחרים את המכונה של workbench-tutorial Agent Platform Workbench ולוחצים על Delete.

  4. כדי למחוק את המכונה הווירטואלית של Compute Engine:

    1. במסוף Cloud de Confiance , נכנסים לדף Compute Engine.

      כניסה ל-Compute Engine

    2. בוחרים את המכונה הווירטואלית on-prem-client ולוחצים על Delete.

  5. מוחקים את מנהרות ה-VPN באופן הבא:

    1. נכנסים לדף VPN במסוף Cloud de Confiance .

      מעבר אל VPN

    2. בדף VPN, לוחצים על הכרטיסייה Cloud VPN Tunnels.

    3. ברשימת מנהרות ה-VPN, בוחרים את ארבע מנהרות ה-VPN שיצרתם במדריך הזה ולוחצים על Delete.

  6. מוחקים את שערי ה-HA VPN באופן הבא:

    1. בדף VPN, לוחצים על הכרטיסייה Cloud VPN Gateways.

      כניסה לדף Cloud VPN Gateways

    2. ברשימת שערי ה-VPN, לוחצים על onprem-vpn-gw1.

    3. בדף Cloud VPN gateway details, לוחצים על Delete VPN Gateway.

    4. אם צריך, לוחצים על החץ חזרה כדי לחזור לרשימת שערי ה-VPN, ואז לוחצים על vertex-networking-vpn-gw1.

    5. בדף Cloud VPN gateway details, לוחצים על Delete VPN Gateway.

  7. כדי למחוק את ה-Cloud Routers:

    1. נכנסים לדף Cloud Routers.

      כניסה לדף Cloud Routers

    2. ברשימת הנתבים של Cloud Router, בוחרים את ארבעת הנתבים שיצרתם במדריך הזה.

    3. כדי למחוק את הנתבים, לוחצים על Delete.

      הפעולה הזו תמחק גם את שני שערי Cloud NAT שמחוברים ל-Cloud Routers.

  8. מוחקים את כלל ההעברה pscvertex של רשת ה-VPC‏ vertex-networking-vpc באופן הבא:

    1. נכנסים לכרטיסייה Frontends בדף Load balancing.

      כניסה לדף Frontends

    2. ברשימת כללי ההעברה, לוחצים על pscvertex.

    3. בדף פרטי כלל העברה, לוחצים על מחיקה.

  9. מוחקים את רשתות ה-VPC באופן הבא:

    1. נכנסים לדף VPC networks.

      כניסה לדף VPC networks

    2. ברשימת רשתות ה-VPC, לוחצים על onprem-vpc.

    3. בדף פרטי רשת VPC, לוחצים על מחיקת רשת VPC.

      כשמוחקים כל רשת, נמחקים גם רשתות המשנה, הנתיבים וכללי חומת האש שלה.

    4. ברשימת רשתות ה-VPC, לוחצים על vertex-networking-vpc.

    5. בדף פרטי רשת VPC, לוחצים על מחיקת רשת VPC.

  10. מוחקים את קטגוריית האחסון באופן הבא:

    1. פותחים את הדף Cloud Storage במסוף Cloud de Confiance .

      כניסה ל-Cloud Storage

    2. בוחרים את קטגוריית האחסון ולוחצים על Delete.

  11. מוחקים את חשבונות השירות workbench-sa ו-onprem-user-managed-sa באופן הבא:

    1. נכנסים לדף Service accounts.

      כניסה לדף Service accounts

    2. בוחרים את חשבונות השירות onprem-user-managed-sa ו-workbench-sa ולוחצים על Delete.

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