비용 최적화 및 가용성 높은 GPU 프로비저닝 전략으로 GKE에서 LLM 제공


이 가이드에서는 대규모 언어 모델 (LLM)을 배포할 때 워크로드 비용을 최적화하는 방법을 보여줍니다. GKE 인프라는 유연한 시작 프로비저닝 모드, 스팟 VM, 맞춤 컴퓨팅 클래스 프로필을 조합하여 워크로드 비용을 최적화합니다.

이 가이드에서는 배포할 수 있는 LLM의 예로 Mixtral 8x7b를 사용합니다.

이 가이드는 LLM을 제공하기 위해 Kubernetes 컨테이너 조정 기능을 사용하는 데 관심이 있는 머신러닝 (ML) 엔지니어, 플랫폼 관리자 및 운영자, 데이터 및 AI 전문가를 대상으로 합니다. Google Cloud 콘텐츠에서 참조하는 일반적인 역할 및 예시 작업에 대해 자세히 알아보려면 일반 GKE Enterprise 사용자 역할 및 작업을 참고하세요.

배경

이 섹션에서는 AI/ML 워크로드의 요구사항에 따라 GPU 가속기를 비롯한 컴퓨팅 리소스를 가져오는 데 사용할 수 있는 기법을 설명합니다. 이러한 기법을 GKE에서는 가속기 가용성 전략이라고 합니다.

GPU

그래픽 처리 장치 (GPU)를 사용하면 머신러닝 및 데이터 처리와 같은 특정 워크로드를 가속화할 수 있습니다. GKE는 머신러닝 및 데이터 처리 작업의 성능을 최적화하기 위해 이러한 강력한 GPU가 장착된 노드를 제공합니다. GKE는 NVIDIA H100, A100, L4 GPU가 있는 머신 유형을 포함하여 노드 구성에 사용되는 다양한 머신 유형 옵션을 제공합니다.

자세한 내용은 GKE의 GPU 정보를 참고하세요.

유연한 시작 프로비저닝 모드

유연한 시작 프로비저닝 모드는 GKE가 GPU 요청을 유지하고 용량을 사용할 수 있게 되면 리소스를 자동으로 프로비저닝하는 GPU 예약 유형입니다. 최대 7일 동안 한시적으로 GPU 용량이 필요하고 시작일이 고정되어 있지 않은 워크로드에는 유연한 시작 프로비저닝 모드를 사용하는 것이 좋습니다. 자세한 내용은 flex-start 프로비저닝 모드를 참고하세요.

스팟 VM

빈번한 노드 중단에도 워크로드를 처리할 수 있는 경우 스팟 VM에서 GPU를 사용할 수 있습니다. Spot VM 또는 flex-start 프로비저닝 모드를 사용하면 GPU 실행 비용이 줄어듭니다. 스팟 VM을 flex-start 프로비저닝 모드와 함께 사용하면 스팟 VM 용량을 사용할 수 없는 경우 대체 옵션을 제공할 수 있습니다.

자세한 내용은 GPU 노드 풀에 스팟 VM 사용을 참고하세요.

커스텀 컴퓨팅 클래스

맞춤 컴퓨팅 클래스를 사용하여 GPU를 요청할 수 있습니다. 커스텀 컴퓨팅 클래스를 사용하면 노드 확장 결정 중에 GKE가 우선순위를 지정할 노드 구성의 계층 구조를 정의하여 선택한 하드웨어에서 워크로드를 실행할 수 있습니다. 자세한 내용은 커스텀 컴퓨팅 클래스 정보를 참고하세요.

시작하기 전에

  • 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.

      IAM으로 이동
    2. 프로젝트를 선택합니다.
    3. 액세스 권한 부여를 클릭합니다.
    4. 새 주 구성원 필드에 사용자 식별자를 입력합니다. 일반적으로 Google 계정의 이메일 주소입니다.

    5. 역할 선택 목록에서 역할을 선택합니다.
    6. 역할을 추가로 부여하려면 다른 역할 추가를 클릭하고 각 역할을 추가합니다.
    7. 저장을 클릭합니다.

모델 액세스 권한 얻기

토큰이 없는 경우 새 Hugging Face 토큰을 생성합니다.

  1. 내 프로필 > 설정 > 액세스 토큰을 클릭합니다.
  2. 새 토큰을 선택합니다.
  3. 원하는 이름과 Read 이상의 역할을 지정합니다.
  4. 토큰 생성을 선택합니다.

맞춤 컴퓨팅 클래스 프로필 만들기

이 섹션에서는 맞춤 컴퓨팅 클래스 프로필을 만듭니다. 맞춤 컴퓨팅 클래스 프로필은 워크로드에서 사용하는 여러 컴퓨팅 리소스의 유형과 관계를 정의합니다.

  1. Google Cloud 콘솔에서 Google Cloud 콘솔Cloud Shell 활성화 아이콘 Cloud Shell 활성화를 클릭하여 Cloud Shell 세션을 시작합니다. Google Cloud 콘솔 하단 창에서 세션이 열립니다.
  2. 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. dws-flex-start.yaml 매니페스트를 적용합니다.

    kubectl apply -f dws-flex-start.yaml
    

GKE는 L4 가속기가 있는 g2-standard-24 머신을 배포합니다. GKE는 컴퓨팅 클래스를 사용하여 Spot VM을 먼저, 유연한 시작 프로비저닝 모드를 나중에 우선시합니다.

LLM 워크로드 배포

  1. 다음 명령어를 사용하여 Hugging Face 토큰이 포함된 Kubernetes 보안 비밀을 만듭니다.

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

    HUGGING_FACE_TOKEN을 Hugging Face 액세스 토큰으로 바꿉니다.

  2. 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
    

    이 매니페스트에서 mountPath 필드는 /tmp로 설정됩니다. 텍스트 생성 추론 (TGI)을 위한 Deep Learning Containers (DLC)의 HF_HOME 환경 변수가 TGI 기본 이미지 내에 설정된 기본 /data 경로 대신 설정되는 경로이기 때문입니다. 다운로드한 모델은 이 디렉터리에 저장됩니다.

  3. 모델을 배포합니다.

    kubectl apply -f  mixtral-deployment.yaml
    

    GKE는 배포할 새 포드를 예약하고, 이로 인해 노드 풀 자동 확장 처리가 트리거되어 모델의 두 번째 복제본을 배포하기 전에 두 번째 노드를 추가합니다.

  4. 모델의 상태를 확인합니다.

    watch kubectl get deploy inference-mixtral-ccc
    

    모델이 성공적으로 배포되면 출력은 다음과 비슷합니다.

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

    확인을 종료하려면 CTRL + C를 누릅니다.

  5. GKE에서 프로비저닝한 노드 풀을 확인합니다.

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

    출력은 다음과 비슷합니다.

      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
    

    생성된 노드 풀의 이름은 머신 유형을 나타냅니다. 이 경우 GKE에서 스팟 VM을 프로비저닝했습니다.

curl을 사용하여 모델과 상호작용

이 섹션에서는 기본 추론 테스트를 수행하여 배포된 모델을 확인하는 방법을 보여줍니다.

  1. 모델로의 포트 전달을 설정합니다.

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

    출력은 다음과 비슷합니다.

    Forwarding from 127.0.0.1:8080 -> 8080
    
  2. 새 터미널 세션에서 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}'
    

    결과는 다음과 유사합니다.

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

삭제

이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 리소스가 포함된 프로젝트를 삭제하거나 프로젝트는 유지하되 개별 리소스를 삭제하세요.

프로젝트 삭제

  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.

개별 리소스 삭제

  1. 이 가이드에서 만든 Kubernetes 리소스를 삭제합니다.

    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. 다음과 같이 클러스터를 삭제합니다.

    gcloud container clusters delete CLUSTER_NAME
    

다음 단계