이 페이지에서는 Llama 3.1과 같은 개방형 모델에 지도 미세 조정을 수행하는 방법을 설명합니다.
지원되는 조정 모드
LoRA (Low-Rank Adaptation): LoRA는 매개변수의 일부만 조정하는 파라미터 효율적 튜닝 모드입니다. 전체 미세 조정에 비해 비용 효율적이며, 더 적은 학습 데이터로도 가능합니다. 반면, 전체 미세 조정은 모든 파라미터를 조정하므로 품질 잠재력이 더 높습니다.
지원되는 모델
- Gemma 3 27B IT** (
google/gemma-3-27b-it
) - Llama 3.1 8B(
meta/llama3_1@llama-3.1-8b
) - Llama 3.1 8B Instruct (
meta/llama3_1@llama-3.1-8b-instruct
) - Llama 3.2 1B Instruct* (
meta/llama3-2@llama-3.2-1b-instruct
) - Llama 3.2 3B Instruct* (
meta/llama3-2@llama-3.2-3b-instruct
) - Llama 3.3 70B Instruct (
meta/llama3-3@llama-3.3-70b-instruct
) - Qwen 3 32B** (
qwen/qwen3@qwen3-32b
)
* 전체 미세 조정만 지원
** 파라미터 효율적인 미세 조정만 지원
시작하기 전에
- 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.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. - Vertex AI SDK for Python 설치 및 초기화
- 다음 라이브러리를 가져옵니다.
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) 형식 중 하나여야 하며, 각 줄에는 단일 조정 예시가 포함되어야 합니다.
프롬프트 완성
{"prompt": "<prompt text>", "completion": "<ideal generated text>"}
턴 기반 채팅 형식
{"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 콘솔
그러면 조정 작업이 시작되며, 관리형 조정 탭의 조정 페이지에서 확인할 수 있습니다.
조정 작업이 완료되면 세부정보 탭에서 조정된 모델의 정보를 확인할 수 있습니다.
Vertex AI SDK for Python
파라미터 값을 사용자 값으로 바꾼 후 다음 코드를 실행하여 조정 작업을 만듭니다.
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 콘솔
Vertex AI SDK for Python
사전 빌드된 컨테이너를 사용하여 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 가격 책정에 대해 알아보고 가격 계산기를 사용하여 예상 사용량을 기준으로 예상 비용을 산출할 수 있습니다.