Menyajikan LLM di GKE dengan strategi penyediaan GPU yang hemat biaya dan memiliki ketersediaan tinggi


Panduan ini menunjukkan cara mengoptimalkan biaya workload saat Anda men-deploy model bahasa besar (LLM). Infrastruktur GKE menggunakan kombinasi profil kelas komputasi kustom, Spot VM, dan flex-start untuk mengoptimalkan biaya workload.

Panduan ini menggunakan Mixtral 8x7b sebagai contoh LLM yang dapat Anda deploy.

Panduan ini ditujukan untuk engineer Machine Learning (ML), admin dan operator Platform, serta untuk spesialis Data dan AI yang tertarik untuk menggunakan kemampuan orkestrasi penampung Kubernetes untuk menayangkan LLM. Untuk mengetahui informasi selengkapnya tentang peran umum dan contoh tugas yang kami referensikan dalam konten Google Cloud , lihat Peran dan tugas pengguna GKE Enterprise umum.

Latar belakang

Bagian ini menjelaskan teknik yang tersedia yang dapat Anda gunakan untuk mendapatkan resource komputasi, termasuk akselerator GPU, berdasarkan persyaratan workload AI/ML Anda. Teknik ini disebut strategi ketersediaan akselerator di GKE.

GPU

Unit pemrosesan grafis (GPU) memungkinkan Anda mempercepat beban kerja tertentu seperti machine learning dan pemrosesan data. GKE menawarkan node yang dilengkapi dengan GPU canggih ini untuk mengoptimalkan performa tugas pemrosesan data dan machine learning. GKE menyediakan berbagai opsi jenis mesin untuk konfigurasi node, termasuk jenis mesin dengan GPU NVIDIA H100, A100, dan L4.

Untuk mengetahui informasi selengkapnya, lihat Tentang GPU di GKE.

Mode penyediaan flex-start

Mode penyediaan fleksibel adalah jenis reservasi GPU tempat GKE mempertahankan permintaan GPU Anda dan secara otomatis menyediakan resource saat kapasitas tersedia. Pertimbangkan untuk menggunakan flex-start untuk workload yang memerlukan kapasitas GPU dalam waktu terbatas, hingga tujuh hari, dan tidak memiliki tanggal mulai tetap. Untuk mengetahui informasi selengkapnya, lihat flex-start.

Spot VM

Anda dapat menggunakan GPU dengan Spot VM jika workload Anda dapat menoleransi seringnya gangguan node. Menggunakan Spot VM atau flex-start akan mengurangi harga GPU yang berjalan. Menggunakan Spot VM yang dikombinasikan dengan flex-start memberikan opsi penggantian saat kapasitas Spot VM tidak tersedia.

Untuk mengetahui informasi selengkapnya, lihat Menggunakan Spot VM dengan node pool GPU.

Class komputasi kustom

Anda dapat meminta GPU menggunakan class komputasi kustom. Class komputasi kustom memungkinkan Anda menentukan hierarki konfigurasi node agar GKE dapat memprioritaskan selama keputusan penskalaan node, sehingga workload berjalan di hardware yang Anda pilih. Untuk informasi selengkapnya, lihat Tentang class komputasi kustom.

Sebelum memulai

  • Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  • In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  • Make sure that billing is enabled for your Google Cloud project.

  • In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  • Make sure that billing is enabled for your Google Cloud project.

  • Make sure that you have the following role or roles on the project:

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Buka IAM
    2. Pilih project.
    3. Klik Berikan akses.
    4. Di kolom New principals, masukkan ID pengguna Anda. Ini biasanya adalah alamat email untuk Akun Google.

    5. Di daftar Pilih peran, pilih peran.
    6. Untuk memberikan peran tambahan, klik Tambahkan peran lain, lalu tambahkan setiap peran tambahan.
    7. Klik Simpan.

Mendapatkan akses ke model

Jika Anda belum memilikinya, buat token Hugging Face baru:

  1. Klik Profil Anda > Setelan > Token Akses.
  2. Pilih New Token.
  3. Tentukan nama pilihan Anda dan peran minimal Read.
  4. Pilih Buat token.

Membuat profil class komputasi kustom

Di bagian ini, Anda akan membuat profil class komputasi kustom. Profil class komputasi kustom menentukan jenis dan hubungan antara beberapa resource komputasi yang digunakan oleh beban kerja Anda.

  1. Di Google Cloud konsol, luncurkan sesi Cloud Shell dengan mengklik Ikon aktivasi Cloud Shell Aktifkan Cloud Shell di konsolGoogle Cloud . Sesi akan terbuka di panel bawah Google Cloud console.
  2. Buat file manifes dws-flex-start.yaml:

    apiVersion: cloud.google.com/v1
    kind: ComputeClass
    metadata:
      name: dws-model-inference-class
    spec:
      priorities:
        - machineType: g2-standard-24
          spot: true
        - machineType: g2-standard-24
          flexStart:
            enabled: true
            nodeRecycling:
              leadTimeSeconds: 3600
      nodePoolAutoCreation:
        enabled: true
    
  3. Terapkan manifes dws-flex-start.yaml:

    kubectl apply -f dws-flex-start.yaml
    

GKE men-deploy mesin g2-standard-24 dengan akselerator L4. GKE menggunakan compute class untuk memprioritaskan Spot VM terlebih dahulu, dan flex-start di tempat kedua.

Men-deploy workload LLM

  1. Buat Secret Kubernetes yang berisi token Hugging Face menggunakan perintah berikut:

    kubectl create secret generic model-inference-secret \
        --from-literal=HUGGING_FACE_TOKEN=HUGGING_FACE_TOKEN \
        --dry-run=client -o yaml | kubectl apply -f -
    

    Ganti HUGGING_FACE_TOKEN dengan token akses Hugging Face Anda.

  2. Buat file bernama mixtral-deployment.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: inference-mixtral-ccc
    spec:
      nodeSelector:
        cloud.google.com/compute-class: dws-model-inference-class
      replicas: 1
      selector:
        matchLabels:
          app: llm
      template:
        metadata:
          labels:
            app: llm
        spec:
          containers:
          - name: llm
            image: us-docker.pkg.dev/deeplearning-platform-release/gcr.io/huggingface-text-generation-inference-cu124.2-3.ubuntu2204.py311
            resources:
              requests:
                cpu: "5"
                memory: "40Gi"
                nvidia.com/gpu: "2"
              limits:
                cpu: "5"
                memory: "40Gi"
                nvidia.com/gpu: "2"
            env:
            - name: MODEL_ID
              value: mistralai/Mixtral-8x7B-Instruct-v0.1
            - name: NUM_SHARD
              value: "2"
            - name: PORT
              value: "8080"
            - name: QUANTIZE
              value: bitsandbytes-nf4
            - name: HUGGING_FACE_HUB_TOKEN
              valueFrom:
                secretKeyRef:
                  name: model-inference-secret
                  key: HUGGING_FACE_TOKEN
            volumeMounts:
              - mountPath: /dev/shm
                name: dshm
              - mountPath: /tmp
                name: ephemeral-volume
          volumes:
            - name: dshm
              emptyDir:
                  medium: Memory
            - name: ephemeral-volume
              ephemeral:
                volumeClaimTemplate:
                  metadata:
                    labels:
                      type: ephemeral
                  spec:
                    accessModes: ["ReadWriteOnce"]
                    storageClassName: "premium-rwo"
                    resources:
                      requests:
                        storage: 100Gi
    

    Dalam manifes ini, kolom mountPath ditetapkan ke /tmp, karena merupakan jalur tempat variabel lingkungan HF_HOME di Deep Learning Container (DLC) untuk Text Generation Inference (TGI) ditetapkan, bukan jalur /data default yang ditetapkan dalam image default TGI. Model yang didownload akan disimpan di direktori ini.

  3. Men-deploy model:

    kubectl apply -f  mixtral-deployment.yaml
    

    GKE menjadwalkan Pod baru untuk di-deploy, yang memicu autoscaler node pool untuk menambahkan node kedua sebelum men-deploy replika kedua model.

  4. Verifikasi status model:

    watch kubectl get deploy inference-mixtral-ccc
    

    Jika model berhasil di-deploy, output-nya akan mirip dengan berikut ini:

    NAME                   READY   UP-TO-DATE   AVAILABLE   AGE
    inference-mixtral-ccc  1/1     1            1           10m
    

    Untuk keluar dari smartwatch, tekan CTRL + C.

  5. Lihat node pool yang disediakan GKE:

    kubectl get nodes -L cloud.google.com/gke-nodepool
    

    Outputnya mirip dengan hal berikut ini:

      NAME                                                  STATUS   ROLES    AGE   VERSION               GKE-NODEPOOL
      gke-flex-na-nap-g2-standard--0723b782-fg7v   Ready    <none>   10m   v1.32.3-gke.1152000   nap-g2-standard-24-spot-gpu2-1gbdlbxz
      gke-flex-nap-zo-default-pool-09f6fe53-fzm8   Ready    <none>   32m   v1.32.3-gke.1152000   default-pool
      gke-flex-nap-zo-default-pool-09f6fe53-lv2v   Ready    <none>   32m   v1.32.3-gke.1152000   default-pool
      gke-flex-nap-zo-default-pool-09f6fe53-pq6m   Ready    <none>   32m   v1.32.3-gke.1152000   default-pool
    

    Nama node pool yang dibuat menunjukkan jenis mesin. Dalam hal ini, GKE menyediakan Spot VM.

Berinteraksi dengan model menggunakan curl

Bagian ini menunjukkan cara melakukan pengujian inferensi dasar untuk memverifikasi model yang di-deploy.

  1. Siapkan penerusan port ke model:

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

    Outputnya mirip dengan hal berikut ini:

    Forwarding from 127.0.0.1:8080 -> 8080
    
  2. Dalam sesi terminal baru, chat dengan model Anda menggunakan curl:

    curl http://localhost:8080/v1/completions \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{
        "model": "mixtral-8x7b-instruct-gptq",
        "prompt": "<s>[INST]Who was the first president of the United States?[/INST]",
        "max_tokens": 40}'
    

    Outputnya terlihat mirip dengan yang berikut ini:

    George Washington was a Founding Father and the first president of the United States, serving from 1789 to 1797.
    

Pembersihan

Agar tidak dikenai biaya pada akun Google Cloud Anda untuk resource yang digunakan di halaman ini, hapus project yang berisi resource tersebut, atau simpan project dan hapus setiap resource.

Menghapus project

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

Menghapus resource satu per satu

  1. Hapus resource Kubernetes yang Anda buat dari panduan ini:

    kubectl delete deployment inference-mixtral-ccc
    kubectl delete service llm-service
    kubectl delete computeclass dws-model-inference-class
    kubectl delete secret model-inference-secret
    
  2. Hapus cluster:

    gcloud container clusters delete CLUSTER_NAME
    

Langkah berikutnya