이 페이지에서는 Llama 3.1과 같은 공개 모델에서 지도 미세 조정을 실행하는 방법을 설명합니다.
지원되는 조정 방법
Low-Rank Adaptation (LoRA): LoRA는 매개변수의 하위 집합만 조정하는 파라미터 효율적 튜닝 방법입니다. 전체 미세 조정보다 비용 효율적이고 학습 데이터가 적게 필요합니다. 반면 전체 미세 조정은 모든 매개변수를 조정하여 품질이 더 높아질 수 있습니다.
지원되는 모델
meta/llama3_1@llama-3.1-8b
meta/llama3_1@llama-3.1-8b-instruct
meta/llama3-2@llama-3.2-1b-instruct
: 전체 미세 조정만 지원meta/llama3-2@llama-3.2-3b-instruct
: 전체 미세 조정만 지원meta/llama3-3@llama-3.3-70b-instruct
시작하기 전에
- 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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI and Cloud Storage APIs.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI and Cloud Storage APIs.
- Python용 Vertex AI SDK 설치 및 초기화
- 다음 라이브러리를 가져옵니다.
import os import time import uuid import vertexai vertexai.init(project=PROJECT_ID, location=REGION) from google.cloud import aiplatform from vertexai.preview.tuning import sft, SourceModel
- Llama 3.1과 같은 지원되는 기본 모델
지원되는 기본 모델 중 하나와 동일한 아키텍처를 가진 모델 Hugging Face와 같은 저장소의 맞춤 모델 체크포인트이거나 Vertex AI 조정 작업의 이전에 조정된 모델일 수 있습니다. 이렇게 하면 이미 조정된 모델을 계속 조정할 수 있습니다.
다음과 같은 방법으로 미세 조정을 시작할 수 있습니다.
모델 카드로 이동하여 미세 조정을 클릭하고 관리형 튜닝을 선택합니다.
또는
조정 페이지로 이동하여 조정된 모델 만들기를 클릭합니다.
매개변수를 입력하고 조정 시작을 클릭합니다.
Model Garden 페이지로 이동하여 맞춤 가중치로 모델 배포를 클릭합니다.
매개변수를 입력하고 배포를 클릭합니다.
조정을 위한 데이터 세트 준비
조정에는 학습 데이터 세트가 필요합니다. 조정된 모델의 성능을 평가하려면 선택적 검증 데이터 세트를 준비하는 것이 좋습니다.
데이터 세트는 지원되는 다음 JSON Lines (JSONL) 형식 중 하나여야 하며, 각 줄에는 단일 조정 예시가 포함되어야 합니다.
턴 기반 채팅 형식
{"messages": [
{"content": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles.",
"role": "system"},
{"content": "Summarize the paper in one paragraph.",
"role": "user"},
{"content": " Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ...",
"role": "assistant"}
]}
JSONL 파일을 Cloud Storage에 업로드합니다.
튜닝 작업 만들기
다음에서 조정할 수 있습니다.
Cloud Console
그러면 조정 작업이 시작되며, 관리형 조정 탭의 조정 페이지에서 확인할 수 있습니다.
조정 작업이 완료되면 세부정보 탭에서 조정된 모델에 관한 정보를 확인할 수 있습니다.
Python용 Vertex AI SDK
매개변수 값을 자체 값으로 바꾼 후 다음 코드를 실행하여 튜닝 작업을 만듭니다.
sft_tuning_job = sft.preview_train(
source_model=SourceModel(
base_model="meta/llama3_1@llama-3.1-8b",
# Optional, folder that either a custom model checkpoint or previously tuned model
custom_base_model="gs://{STORAGE-URI}",
),
tuning_mode="FULL", # FULL or PEFT_ADAPTER
epochs=3,
train_dataset="gs://{STORAGE-URI}", # JSONL file
validation_dataset="gs://{STORAGE-URI}", # JSONL file
output_uri="gs://{STORAGE-URI}",
)
작업이 완료되면 조정된 모델의 모델 아티팩트가 <output_uri>/postprocess/node-0/checkpoints/final
폴더에 저장됩니다.
조정된 모델 배포
조정된 모델을 Vertex AI 엔드포인트에 배포할 수 있습니다. Cloud Storage에서 조정된 모델을 내보내 다른 곳에 배포할 수도 있습니다.
조정된 모델을 Vertex AI 엔드포인트에 배포하려면 다음 단계를 따르세요.
Cloud Console
Python용 Vertex AI SDK
사전 빌드된 컨테이너를 사용하여 G2 machine
를 배포합니다.
from vertexai.preview import model_garden
MODEL_ARTIFACTS_STORAGE_URI = "gs://{STORAGE-URI}/postprocess/node-0/checkpoints/final"
model = model_garden.CustomModel(
gcs_uri=MODEL_ARTIFACTS_STORAGE_URI,
)
# deploy the model to an endpoint using GPUs. Cost will incur for the deployment
endpoint = model.deploy(
machine_type="g2-standard-12",
accelerator_type="NVIDIA_L4",
accelerator_count=1,
)
추론 가져오기
배포가 완료되면 텍스트 프롬프트와 함께 엔드포인트에 요청을 보낼 수 있습니다. 처음 몇 개의 프롬프트는 실행하는 데 시간이 더 오래 걸립니다.
# Loads the deployed endpoint
endpoint = aiplatform.Endpoint("projects/{PROJECT_ID}/locations/{REGION}/endpoints/{endpoint_name}")
prompt = "Summarize the following article. Article: Preparing a perfect risotto requires patience and attention to detail. Begin by heating butter in a large, heavy-bottomed pot over medium heat. Add finely chopped onions and minced garlic to the pot, and cook until they're soft and translucent, about 5 minutes. Next, add Arborio rice to the pot and cook, stirring constantly, until the grains are coated with the butter and begin to toast slightly. Pour in a splash of white wine and cook until it's absorbed. From there, gradually add hot chicken or vegetable broth to the rice, stirring frequently, until the risotto is creamy and the rice is tender with a slight bite.. Summary:"
# Define input to the prediction call
instances = [
{
"prompt": "What is a car?",
"max_tokens": 200,
"temperature": 1.0,
"top_p": 1.0,
"top_k": 1,
"raw_response": True,
},
]
# Request the prediction
response = endpoint.predict(
instances=instances
)
for prediction in response.predictions:
print(prediction)
배포된 모델에서 추론을 가져오는 방법에 대한 자세한 내용은 온라인 추론 가져오기를 참고하세요.
관리형 오픈 모델은 배포된 모델에서 사용하는 predict
메서드 대신 chat.completions
메서드를 사용합니다. 관리형 모델에서 추론을 가져오는 방법에 관한 자세한 내용은 Llama 모델 호출하기를 참고하세요.
한도 및 할당량
할당량은 동시 조정 작업 수에 적용됩니다. 모든 프로젝트에는 조정 작업을 최소 하나 이상 실행할 수 있는 기본 할당량이 제공됩니다. 이 할당량은 사용 가능한 모든 리전 및 지원되는 모델에서 공유되는 전역 할당량입니다. 더 많은 작업을 동시에 실행하려면 Global
concurrent managed OSS model fine-tuning jobs per project
의 추가 할당량을 요청해야 합니다.
가격 책정
모델 조정 가격 책정에 따라 조정 비용이 청구됩니다.
Cloud Storage 및 Vertex AI Prediction과 같은 관련 서비스에 대한 요금도 청구됩니다.
Vertex AI 가격 책정, Cloud Storage 가격 책정에 대해 알아보고 가격 계산기를 사용하여 예상 사용량을 기반으로 비용을 추정해 보세요.