Ray를 사용하여 L4 GPU에 LLM 제공


이 가이드에서는 Google Kubernetes Engine(GKE) 모드에서 Ray 프레임워크를 사용하여 대규모 언어 모델(LLM)을 제공하는 방법을 보여줍니다. 이 가이드는 LLM 제공을 위해 GKE 조정 기능을 사용하려는 MLOps 또는 DevOps 엔지니어나 플랫폼 관리자를 대상으로 합니다.

이 가이드에서는 다음 모델을 제공할 수 있습니다.

GKE에서 다음 단계를 완료하기 전에 GKE의 GPU 정보를 학습하는 것이 좋습니다.

배경

Ray 프레임워크는 ML 워크로드의 학습, 미세 조정, 추론을 위한 엔드 투 엔드 AI/ML 플랫폼을 제공합니다. 모델의 데이터 형식에 따라 GPU 수가 달라집니다. 이 가이드에서 각 모델은 2개의 L4 GPU를 사용합니다. 자세한 내용은 GPU 양 계산을 참조하세요.

이 가이드에서는 다음 단계를 설명합니다.

  1. Autopilot 또는 표준 GKE 클러스터를 만듭니다.
  2. KubeRay 연산자를 배포합니다.
  3. LLM 제공을 위해 RayService 커스텀 리소스를 배포합니다.

시작하기 전에

시작하기 전에 다음 태스크를 수행했는지 확인합니다.

  • Google Kubernetes Engine API를 사용 설정합니다.
  • Google Kubernetes Engine API 사용 설정
  • 이 태스크에 Google Cloud CLI를 사용하려면 gcloud CLI를 설치한 후 초기화합니다. 이전에 gcloud CLI를 설치한 경우 gcloud components update를 실행하여 최신 버전을 가져옵니다.
  • Llama 2 모델을 사용하려면 다음 조건이 충족되었는지 확인합니다.

  • us-central1 리전에 GPU 할당량이 있는지 확인합니다. 자세한 내용은 GPU 할당량을 참조하세요.

개발 환경 준비

  1. Google Cloud 콘솔에서 Cloud Shell 인스턴스를 시작합니다.
    Cloud Shell 열기

  2. 샘플 저장소를 클론합니다.

    git clone https://github.com/GoogleCloudPlatform/kubernetes-engine-samples.git
    cd kubernetes-engine-samples/ai-ml/gke-ray
    export TUTORIAL_HOME=`pwd`
    

    이 저장소에는 여러 다른 가속기 유형을 프로비저닝하는 모델의 사전 빌드된 ray-llm 컨테이너 이미지가 포함되어 있습니다. 이 가이드에서는 NVIDIA L4 GPU를 사용하므로, RayService의 spec.serveConfigV2는 L4 가속기 유형을 사용하는 모델이 포함된 저장소를 가리킵니다.

  3. 기본 환경 변수를 설정합니다.

    gcloud config set project PROJECT_ID
    export PROJECT_ID=$(gcloud config get project)
    export REGION=us-central1
    

    PROJECT_ID를 Google Cloud 프로젝트 ID로 바꿉니다.

클러스터 및 GPU 노드 풀 만들기

GKE Autopilot 또는 표준 클러스터에서 Ray를 사용하여 L4 GPU로 LLM을 제공할 수 있습니다. 사용 사례에 따라 높은 확장성이 필요하거나 클러스터 구성을 보다 세밀하게 제어하고 싶은 경우에는 완전 관리형 Kubernetes 경험을 위한 Autopilot 클러스터 또는 표준 클러스터를 사용하는 것이 좋습니다. 워크로드에 가장 적합한 GKE 작업 모드를 선택하려면 GKE 작업 모드 선택을 참조하세요.

Cloud Shell을 사용하여 다음을 수행합니다.

  1. gke-platform 폴더로 이동합니다.

    cd ${TUTORIAL_HOME}/gke-platform
    
    • Autopilot 클러스터의 경우 다음 명령어를 실행합니다.
    cat << EOF > terraform.tfvars
    enable_autopilot=true
    project_id="${PROJECT_ID}"
    EOF
    
    • 표준 클러스터의 경우 다음 명령어를 실행합니다.
    cat << EOF > terraform.tfvars
    project_id="${PROJECT_ID}"
    gpu_pool_machine_type="g2-standard-24"
    gpu_pool_accelerator_type="nvidia-l4"
    gpu_pool_node_locations=["us-central1-a", "us-central1-c"]
    EOF
    
  2. GKE 클러스터 및 노드 풀을 배포합니다.

    terraform init
    terraform apply --auto-approve
    

    Terraform이 초기화되면 진행 메시지가 로깅됩니다. 메시지 출력 끝에 Terraform이 성공적으로 초기화되었다는 메시지가 표시됩니다.

    완료되면 Terraform 매니페스트가 다음 구성요소를 배포합니다.

    • GKE 클러스터
    • CPU 노드 풀
    • GPU 노드 풀
    • Ray CustomResourceDefinitions(CRD)가 있는 KubeRay 연산자
  3. 가이드의 다음 섹션에서 kubectl에서 사용할 프로비저닝된 클러스터 사용자 인증 정보를 가져옵니다.

    gcloud container clusters get-credentials ml-cluster --region us-central1
    
  4. rayserve 폴더로 이동합니다.

    cd ${TUTORIAL_HOME}/rayserve
    

LLM 모델 배포

클론된 저장소에서 models 폴더에는 모델을 로드하는 구성이 포함됩니다. ray-llm에서 각 모델은 다음과 같이 구성됩니다.

  • 배포: Ray 제공 구성
  • 엔진: Huggingface 모델, 모델 매개변수, 프롬프트 세부정보
  • 확장: 모델이 소비하는 Ray 리소스에 대한 정의
  • 모델별 특정 구성

이 가이드에서는 HuggingFace Transformer를 통해 4비트 NormalFloat(NF4)의 양자화를 사용해서 LLM을 로드하고 GPU 메모리 사용량은 줄입니다(2개의 L4 GPU로 총 48GB GPU 메모리 사용). 16비트에서 4비트로 줄임에 따라 모델 가중치 정밀도가 감소하지만 더 큰 모델을 테스트하고 사용 사례에 적합한지 여부를 파악할 수 있는 유연성을 제공합니다. 양자화를 위해 샘플 코드는 HuggingFace 및 BitsAndBytesConfig 라이브러리를 사용해서 대규모 매개변수 모델인 Falcon 40b 및 Llama2 70b의 양자화된 버전을 로드합니다.

다음 섹션에서는 사용할 모델에 따라 워크로드를 설정하는 방법을 보여줍니다.

Falcon 7b

  1. RayService 및 종속 항목을 배포합니다. 만든 GKE 모델에 해당하는 명령어를 사용합니다.

    • Autopilot:
    kubectl apply -f models/falcon-7b-instruct.yaml
    kubectl apply -f ap_pvc-rayservice.yaml
    kubectl apply -f ap_falcon-7b.yaml
    
    • 표준:
    kubectl apply -f models/falcon-7b-instruct.yaml
    kubectl apply -f falcon-7b.yaml
    

    Ray 클러스터 포드 만들기는 Running 상태에 도달하는 데 몇 분 정도 걸릴 수 있습니다.

  2. Ray 클러스터 헤드 포드가 작동되어 실행될 때까지 기다립니다.

    watch --color --interval 5 --no-title \
        "kubectl get pod | \
        GREP_COLOR='01;92' egrep --color=always -e '^' -e 'Running'"
    
  3. Ray 클러스터 포드가 실행된 후 모델 상태를 확인할 수 있습니다.

    export HEAD_POD=$(kubectl get pods --selector=ray.io/node-type=head \
        -n default \
        -o custom-columns=POD:metadata.name --no-headers)
    
    watch --color --interval 5 --no-title \
        "kubectl exec -n default -it $HEAD_POD \
        -- serve status | GREP_COLOR='01;92' egrep --color=always -e '^' -e 'RUNNING'"
    

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

    proxies:
      781dc714269818b9b8d944176818b683c00d222d2812a2cc99a33ec6: HEALTHY
      bb9aa9f4bb3e721d7e33e8d21a420eb33c9d44e631ba7d544e23396d: HEALTHY
    applications:
      ray-llm:
        status: RUNNING
        message: ''
        last_deployed_time_s: 1702333577.390653
        deployments:
          VLLMDeployment:tiiuae--falcon-7b-instruct:
            status: HEALTHY
            replica_states:
              RUNNING: 1
            message: ''
          Router:
            status: HEALTHY
            replica_states:
              RUNNING: 2
            message: ''
    

    상태 필드가 RUNNING이면 LLM 채팅이 준비됩니다.

Llama2 7b

  1. 기본 환경 변수를 설정합니다.

    export HF_TOKEN=HUGGING_FACE_TOKEN
    

    HUGGING_FACE_TOKEN을 HuggingFace 토큰으로 바꿉니다.

  2. HuggingFace 토큰에 Kubernetes 보안 비밀을 만듭니다.

    kubectl create secret generic hf-secret \
        --from-literal=hf_api_token=${HF_TOKEN} \
        --dry-run=client -o yaml | kubectl apply -f -
    
  3. RayService 및 종속 항목을 배포합니다. 만든 GKE 모델에 해당하는 명령어를 사용합니다.

    • Autopilot:
    kubectl apply -f models/llama2-7b-chat-hf.yaml
    kubectl apply -f ap_pvc-rayservice.yaml
    kubectl apply -f ap_llama2-7b.yaml
    
    • 표준:
    kubectl apply -f models/llama2-7b-chat-hf.yaml
    kubectl apply -f llama2-7b.yaml
    

    Ray 클러스터 포드 만들기는 Running 상태에 도달하는 데 몇 분 정도 걸릴 수 있습니다.

  4. Ray 클러스터 헤드 포드가 작동되어 실행될 때까지 기다립니다.

    watch --color --interval 5 --no-title \
        "kubectl get pod | \
        GREP_COLOR='01;92' egrep --color=always -e '^' -e 'Running'"
    
  5. Ray 클러스터 포드가 실행된 후 모델 상태를 확인할 수 있습니다.

    export HEAD_POD=$(kubectl get pods --selector=ray.io/node-type=head \
        -n default \
        -o custom-columns=POD:metadata.name --no-headers)
    
    watch --color --interval 5 --no-title \
        "kubectl exec -n default -it $HEAD_POD \
        -- serve status | GREP_COLOR='01;92' egrep --color=always -e '^' -e 'RUNNING'"
    

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

      proxies:
        0eb0eb51d667a359b426b825c61f6a9afbbd4e87c99179a6aaf4f833: HEALTHY
        3a4547b89a8038d5dc6bfd9176d8a13c5ef57e0e67e117f06577e380: HEALTHY
      applications:
        ray-llm:
          status: RUNNING
          message: ''
          last_deployed_time_s: 1702334447.9163773
          deployments:
            VLLMDeployment:meta-llama--Llama-2-7b-chat-hf:
              status: HEALTHYG
              replica_states:
                RUNNING: 11
              message: ''p
            Router:y
              status: HEALTHY
              replica_states:
                RUNNING: 2T
              message: ''t
    

    상태 필드가 RUNNING이면 LLM 채팅이 준비됩니다.

Falcon 40b

  1. RayService 및 종속 항목을 배포합니다. 만든 GKE 모델에 해당하는 명령어를 사용합니다.

    • Autopilot:
    kubectl apply -f models/quantized-model.yaml
    kubectl apply -f ap_pvc-rayservice.yaml
    kubectl apply -f ap_falcon-40b.yaml
    
    • 표준:
    kubectl apply -f models/quantized-model.yaml
    kubectl apply -f falcon-40b.yaml
    

    Ray 클러스터 포드 만들기는 Running 상태에 도달하는 데 몇 분 정도 걸릴 수 있습니다.

  2. Ray 클러스터 헤드 포드가 작동되어 실행될 때까지 기다립니다.

    watch --color --interval 5 --no-title \
        "kubectl get pod | \
        GREP_COLOR='01;92' egrep --color=always -e '^' -e 'Running'"
    
  3. Ray 클러스터 포드가 실행된 후 모델 상태를 확인할 수 있습니다.

    export HEAD_POD=$(kubectl get pods --selector=ray.io/node-type=head \
        -n default \
        -o custom-columns=POD:metadata.name --no-headers)
    
    watch --color --interval 5 --no-title \
        "kubectl exec -n default -it $HEAD_POD \
        -- serve status | GREP_COLOR='01;92' egrep --color=always -e '^' -e 'RUNNING'"
    

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

    proxies:
      d9fdd5ac0d81e8eeb1eb6efb22bcd1c4544ad17422d1b69b94b51367: HEALTHY
      9f75f681caf33e7c496ce69979b8a56f3b2b00c9a22e73c4606385f4: HEALTHY
    applications:
      falcon:s
        status: RUNNING
        message: ''e
        last_deployed_time_s: 1702334848.336201
        deployments:
          Chat:t
            status: HEALTHYG
            replica_states:
              RUNNING: 11
            message: ''p
    

    상태 필드가 RUNNING이면 LLM 채팅이 준비됩니다.

Llama2 70b

  1. 기본 환경 변수를 설정합니다.

    export HF_TOKEN=HUGGING_FACE_TOKEN
    

    HUGGING_FACE_TOKEN을 HuggingFace 토큰으로 바꿉니다.

  2. HuggingFace 토큰에 Kubernetes 보안 비밀을 만듭니다.

    kubectl create secret generic hf-secret \
        --from-literal=hf_api_token=${HF_TOKEN} \
        --dry-run=client -o yaml | kubectl apply -f -
    
  3. RayService 및 종속 항목을 배포합니다. 만든 GKE 모델에 해당하는 명령어를 사용합니다.

    • Autopilot:
    kubectl apply -f models/quantized-model.yaml
    kubectl apply -f ap_pvc-rayservice.yaml
    kubectl apply -f ap_llama2-70b.yaml
    
    • 표준:
    kubectl apply -f models/quantized-model.yaml
    kubectl apply -f llama2-70b.yaml
    

    Ray 클러스터 포드 만들기는 Running 상태에 도달하는 데 몇 분 정도 걸릴 수 있습니다.

  4. Ray 클러스터 헤드 포드가 작동되어 실행될 때까지 기다립니다.

    watch --color --interval 5 --no-title \
        "kubectl get pod | \
        GREP_COLOR='01;92' egrep --color=always -e '^' -e 'Running'"
    
  5. Ray 클러스터 포드가 실행된 후 모델 상태를 확인할 수 있습니다.

    export HEAD_POD=$(kubectl get pods --selector=ray.io/node-type=head \
        -n default \
        -o custom-columns=POD:metadata.name --no-headers)
    
    watch --color --interval 5 --no-title \
        "kubectl exec -n default -it $HEAD_POD \
        -- serve status | GREP_COLOR='01;92' egrep --color=always -e '^' -e 'RUNNING'"
    

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

    proxies:
      a71407ddfeb662465db384e0f880a2d3ad9ed285c7b9946b55ae27b5: HEALTHY
      <!-- dd5d4475ac3f5037cd49f1bddc7cfcaa88e4251b25c8784d0ac53c7c: HEALTHY -->
    applications:
      llama-2:
        status: RUNNING
        message: ''
        last_deployed_time_s: 1702335974.8497846
        deployments:
          Chat:
            status: HEALTHY
            replica_states:
              RUNNING: 1
            message: ''
    

    상태 필드가 RUNNING이면 LLM 채팅이 준비됩니다.

모델과 채팅

Falcon 7b 및 Llama2 7b 모델의 경우 ray-llmOpenAI API 채팅 사양을 구현합니다. Falcon 40b 및 Llama2 70b 모델은 ray-llm을 사용하고 텍스트 생성만 지원합니다.

Falcon 7b

  1. 추론 서버에 대한 포트 전달을 설정합니다.

    kubectl port-forward service/rayllm-serve-svc 8000:8000
    

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

    Forwarding from 127.0.0.1:8000 -> 8000
    
  2. 새 터미널 세션에서 curl을 사용해서 모델과 채팅합니다.

    curl http://localhost:8000/v1/chat/completions \
        -H "Content-Type: application/json" \
        -d '{
          "model": "tiiuae/falcon-7b-instruct",
          "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "What are the top 5 most popular programming languages? Please be brief."}
          ],
          "temperature": 0.7
        }'
    

Llama2 7b

  1. 추론 서버에 대한 포트 전달을 설정합니다.

    kubectl port-forward service/rayllm-serve-svc 8000:8000
    

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

    Forwarding from 127.0.0.1:8000 -> 8000
    
  2. 새 터미널 세션에서 curl을 사용해서 모델과 채팅합니다.

    curl http://localhost:8000/v1/chat/completions \
      -H "Content-Type: application/json" \
      -d '{
        "model": "meta-llama/Llama-2-7b-chat-hf",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "What are the top 5 most popular programming languages? Please be brief."}
        ],
        "temperature": 0.7
      }'
    

Falcon 40b

  1. 추론 서버에 대한 포트 전달을 설정합니다.

    kubectl port-forward service/rayllm-serve-svc 8000:8000
    

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

    Forwarding from 127.0.0.1:8000 -> 8000
    
  2. 새 터미널 세션에서 curl을 사용해서 모델과 채팅합니다.

    curl -X POST http://localhost:8000/ \
        -H "Content-Type: application/json" \
        -d '{"text": "What are the top 5 most popular programming languages? Please be brief."}'
    

Llama2 70b

  1. 추론 서버에 대한 포트 전달을 설정합니다.

    kubectl port-forward service/rayllm-serve-svc 8000:8000
    

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

    Forwarding from 127.0.0.1:8000 -> 8000
    
  2. 새 터미널 세션에서 curl을 사용해서 모델과 채팅합니다.

    curl -X POST http://localhost:8000/ \
        -H "Content-Type: application/json" \
        -d '{"text": "What are the top 5 most popular programming languages? Please be brief."}'
    

모델과 대화 만들기

제공한 모델은 기록을 보존하지 않으므로, 대화 시뮬레이션을 만들려면 각 메시지 및 회신을 모델로 다시 전송해야 합니다. 이 상호작용은 사용되는 토큰 수를 늘립니다. 단일 상호작용을 만들려면 모델과 대화를 만듭니다. Falcon 7b 또는 Llama2 7b를 사용할 때 대화를 만들 수 있습니다.

Falcon 7b

  1. curl을 사용하여 모델과 대화를 만듭니다.

    curl http://localhost:8000/v1/chat/completions \
        -H "Content-Type: application/json" \
        -d '{
          "model": "tiiuae/falcon-7b-instruct",
          "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "What are the top 5 most popular programming languages? Please be brief."},
            {"role": "assistant", "content": " \n1. Java\n2. Python\n3. C++\n4. C#\n5. JavaScript"},
            {"role": "user", "content": "Can you give me a brief description?"}
          ],
          "temperature": 0.7
    }'
    

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

    {
      "id": "tiiuae/falcon-7b-instruct-f7ff36764b4ec5906b5e54858588f17e",
      "object": "text_completion",
      "created": 1702334177,
      "model": "tiiuae/falcon-7b-instruct",
      "choices": [
        {
          "message": {
            "role": "assistant", "content": " </s><s>1. Java - a popular
            programming language used for object-oriented programming and web
            applications.</s><s>2. Python - an interpreted, high-level
            programming language used for general-purpose
            programming.</s><s>3. C++ - a popular programming language used in
            developing operating systems and applications.</s><s>4. C# - a
            popular programming language used for developing Windows-based
            applications.</s><s>5. JavaScript - a popular programming language
            used for developing dynamic, interactive web applications.</s></s>
            \nWhich of the top 5 programming languages are the most commonly
            used for developing mobile applications?</s><s>1. Java</s><s>2.
            C++</s><s>3. C#</s><s>4. Objective-C</s><s>5. Swift (for iOS
            development)</s>"
          },
          "index": 0,
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 65,
        "completion_tokens": 191,
        "total_tokens": 256
      }
    }
    

Llama2 7b

  1. curl을 사용하여 모델과 대화를 만듭니다.

    curl http://localhost:8000/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
      "model": "meta-llama/Llama-2-7b-chat-hf",
      "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What are the top 5 most popular
        programming languages? Please be brief."},
        {"role": "assistant", "content": " Of course! Here are the top 5 most
        popular programming languages, based on various sources and
        metrics:\n\n1. JavaScript: Used for web development, game development,
        and mobile app development.\n2. Python: General-purpose language used
        for web development, data analysis, machine learning, and more.\n3.
        Java: Object-oriented language used for Android app development, web
        development, and enterprise software development.\n4. C++:
        High-performance language used for systems programming, game
        development, and high-performance computing.\n5. C#:
        Microsoft-developed language used for Windows app development, web
        development, and enterprise software development.\n\nI hope this
        helps! Let me know if you have any other questions."},
        {"role": "user", "content": "Can you just list it instead?"}
      ],
      "temperature": 0.7
    }'
    

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

    {
      "id": "meta-llama/Llama-2-7b-chat-hf-940d3bdda1e39920760e286dfdd0b9d7",
      "object": "text_completion",
      "created": 1696460007,
      "model": "meta-llama/Llama-2-7b-chat-hf",
      "choices": [
        {
          "message": {
            "role": "assistant", "content": " Of course! Here are the top 5
            most popular programming languages, based on various sources and
            metrics:\n1. JavaScript\n2. Python\n3. Java\n4. C++\n5. C#\n\nI
            hope this helps! Let me know if you have any other questions."
          },
          "index": 0,
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 220,
        "completion_tokens": 61,
        "total_tokens": 281
      }
    }
    

채팅 인터페이스 배포

선택적으로 Gradio를 사용해서 모델과 상호작용할 수 있는 웹 애플리케이션을 빌드할 수 있습니다. Gradio는 챗봇용 사용자 인터페이스를 만드는 ChatInterface 래퍼가 있는 Python 라이브러리입니다.

Falcon 7b

  1. gradio.yaml 매니페스트를 엽니다.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: gradio
      labels:
        app: gradio
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: gradio
      template:
        metadata:
          labels:
            app: gradio
        spec:
          containers:
          - name: gradio
            image: us-docker.pkg.dev/google-samples/containers/gke/gradio-app:v1.0.0
            env:
            - name: MODEL_ID
              value: "meta-llama/Llama-2-7b-chat-hf"
            - name: CONTEXT_PATH
              value: "/v1/chat/completions"
            - name: HOST
              value: "http://rayllm-serve-svc:8000"
            ports:
            - containerPort: 7860
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: gradio
    spec:
      selector:
        app: gradio
      ports:
        - protocol: TCP
          port: 80
          targetPort: 7860
      type: LoadBalancer
  2. MODEL_ID에 할당된 valuetiiuae/falcon-7b-instruct 값으로 바꿉니다.

    ...
    - name: MODEL_ID
      value: "tiiuae/falcon-7b-instruct"
    
  3. 매니페스트를 적용합니다.

    kubectl apply -f gradio.yaml
    
  4. 서비스의 외부 IP 주소를 찾습니다.

    EXTERNAL_IP=$(kubectl get services gradio \
        --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
    echo -e "\nGradio URL: http://${EXTERNAL_IP}\n"
    

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

    Gradio URL: http://34.172.115.35
    

    부하 분산기가 외부 IP 주소를 가져오는 데 몇 분 정도 걸릴 수 있습니다.

Llama2 7b

  1. gradio.yaml 매니페스트를 엽니다.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: gradio
      labels:
        app: gradio
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: gradio
      template:
        metadata:
          labels:
            app: gradio
        spec:
          containers:
          - name: gradio
            image: us-docker.pkg.dev/google-samples/containers/gke/gradio-app:v1.0.0
            env:
            - name: MODEL_ID
              value: "meta-llama/Llama-2-7b-chat-hf"
            - name: CONTEXT_PATH
              value: "/v1/chat/completions"
            - name: HOST
              value: "http://rayllm-serve-svc:8000"
            ports:
            - containerPort: 7860
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: gradio
    spec:
      selector:
        app: gradio
      ports:
        - protocol: TCP
          port: 80
          targetPort: 7860
      type: LoadBalancer
  2. MODEL_ID에 할당된 valuemeta-llama/Llama-2-7b-chat-hf인지 확인합니다.

  3. 매니페스트를 적용합니다.

    kubectl apply -f gradio.yaml
    
  4. 서비스의 외부 IP 주소를 찾습니다.

    EXTERNAL_IP=$(kubectl get services gradio \
        --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
    echo -e "\nGradio URL: http://${EXTERNAL_IP}\n"
    

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

    Gradio URL: http://34.172.115.35
    

    부하 분산기가 외부 IP 주소를 가져오는 데 몇 분 정도 걸릴 수 있습니다.

GPU 양 계산

GPU 양은 bnb_4bit_quant_type 구성의 값에 따라 달라집니다. 이 튜토리얼에서는 bnb_4bit_quant_typenf4로 설정합니다. 즉 모델이 4비트로 로드됩니다.

700억 개의 매개변수 모델에는 최소 40GB의 GPU 메모리가 필요합니다. 이는 700억에 4비트를 곱한 값(700억 x 4비트 = 35GB)에 5GB 오버헤드를 더한 값입니다. 이 경우 단일 L4 GPU에 충분한 메모리가 없습니다. 따라서 이 튜토리얼의 예시에서는 2개의 L4 GPU 메모리(2 x 24 = 48GB)를 사용합니다. 이 구성은 L4 GPU에서 Falcon 40b 또는 Llama 2 70b를 실행하는 데 충분합니다.

프로젝트 삭제

  1. Google Cloud 콘솔에서 리소스 관리 페이지로 이동합니다.

    리소스 관리로 이동

  2. 프로젝트 목록에서 삭제할 프로젝트를 선택하고 삭제를 클릭합니다.
  3. 대화상자에서 프로젝트 ID를 입력한 후 종료를 클릭하여 프로젝트를 삭제합니다.

개별 리소스 삭제

기존 프로젝트를 사용한 경우 삭제하지 않으려면 개별 리소스를 삭제합니다.

  1. gke-platform 폴더로 이동합니다.

    cd ${TUTORIAL_HOME}/gke-platform
    
  2. 클러스터에서 삭제 보호를 사용 중지하고 모든 terraform 프로비저닝 리소스를 삭제합니다. 다음 명령어를 실행합니다.

    sed -ie 's/"deletion_protection": true/"deletion_protection": false/g' terraform.tfstate
    terraform destroy --auto-approve
    

다음 단계