개방형 모델의 지도 및 증류 미세 조정

이 페이지에서는 Llama 3.1과 같은 개방형 모델에 지도 및 증류 미세 조정을 수행하는 방법을 설명합니다. 달리 명시되지 않는 한 이 페이지의 안내는 지도 미세 조정과 증류 미세 조정 모두에 적용됩니다. 증류를 사용하면 더 큰 교사 모델의 출력을 사용하여 더 작은 학생 모델을 조정할 수 있습니다.

지원되는 조정 모드

  • 지도 미세 조정:
    • 전체 미세 조정
    • LoRA (Low-Rank Adaptation): LoRA는 파라미터의 일부만 조정하는 파라미터 효율적 조정 방법입니다. 전체 미세 조정에 비해 비용 효율적이며, 더 적은 학습 데이터로도 가능합니다. 반면, 전체 미세 조정은 모든 파라미터를 조정하므로 품질 잠재력이 더 높습니다.
  • 정제 미세 조정: 정제 미세 조정은 생성형 AI SDK를 사용합니다. 여기에서 티처 모델을 지정하여 응답을 생성한 다음 이를 사용하여 더 작은 스튜던트 모델을 조정합니다.

증류 미세 조정의 권장 사용 사례

증류 미세 조정은 교사 모델이 타겟 작업에서 학생보다 훨씬 더 뛰어난 경우에 가장 효과적입니다. 다음과 같이 복잡한 다단계 추론 기능을 더 큰 교사에서 더 작은 학생으로 전송하는 데 권장됩니다.

  • 수학 및 양적 추론
  • 단계별 추론이 필요한 과학, 의학 및 기타 도메인별 질의 응답
  • '사고' 또는 생각의 사슬 동작이 있는 강력한 교사 모델이 학생보다 일관되게 더 높은 품질의 대답을 생성하는 기타 작업

증류는 학생 모델이 이미 교사에 가까운 성능을 보이는 작업이나 교사의 추론 트레이스가 가치를 더하지 않는 짧은 형식 검색 작업에서는 이점이 적습니다.

지원되는 모델

지도 미세 조정 지원 모델

  • Gemma 3 1B IT (google/gemma3@gemma-3-1b-it)
  • Gemma 3 4B IT (google/gemma3@gemma-3-4b-it)
  • Gemma 3 12B IT (google/gemma3@gemma-3-12b-it)
  • Gemma 3 27B IT(google/gemma3@gemma-3-27b-it)
  • Medgemma 1.5 4B IT (google/medgemma@medgemma-4b-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 4B (qwen/qwen3@qwen3-4b)
  • Qwen 3 8B (qwen/qwen3@qwen3-8b)
  • Qwen 3 14B (qwen/qwen3@qwen3-14b)
  • Qwen3 32B(qwen/qwen3@qwen3-32b)
  • Llama 4 Scout 17B 16E Instruct (meta/llama4@llama-4-scout-17b-16e-instruct)

증류 조정 지원 모델

지원되는 티처 모델:

  • DeepSeek R1 0528 MaaS (deepseek-ai/deepseek-r1-0528-maas)
  • DeepSeek V3.2 MaaS (deepseek-ai/deepseek-v3.2-maas)
  • Qwen 3 Next 80B A3B Thinking MaaS (qwen/qwen3-next-80b-a3b-thinking-maas)

지원되는 학생 모델:

  • Qwen 3 4B (qwen/qwen3@qwen3-4b)
  • Qwen 3 8B (qwen/qwen3@qwen3-8b)
  • Qwen 3 14B (qwen/qwen3@qwen3-14b)
  • Qwen3 32B(qwen/qwen3@qwen3-32b)
  • Gemma 3 1B IT (google/gemma3@gemma-3-1b-it)
  • Gemma 3 4B IT (google/gemma3@gemma-3-4b-it)
  • Gemma 3 12B IT (google/gemma3@gemma-3-12b-it)
  • Gemma 3 27B IT(google/gemma3@gemma-3-27b-it)

지원되는 리전

  • 아이오와(us-central1)
  • 네덜란드(europe-west4)
  • 오리건(us-west1)
  • 콜럼버스(us-east5)
  • 싱가포르(asia-southeast1)

제한사항

모델 사양
Gemma 3 1B IT 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Gemma 3 4B IT 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Gemma 3 12B IT 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Gemma 3 27B IT 조정 모드 Parameter-Efficient Fine-Tuning(PEFT)
전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Medgemma 1.5 4B IT 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Llama 3.1 8B 조정 모드 Parameter-Efficient Fine-Tuning(PEFT)
전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Llama 3.1 8B Instruct 조정 모드 Parameter-Efficient Fine-Tuning(PEFT)
전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Llama 3.2 1B Instruct 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Llama 3.2 3B Instruct 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Llama 3.3 70B Instruct 조정 모드 Parameter-Efficient Fine-Tuning(PEFT)
전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Llama 4 Scout 17B 16E Instruct 조정 모드 Parameter-Efficient Fine-Tuning(PEFT)
최대 시퀀스 길이 2048
형식 텍스트
이미지*

*텍스트 전용 예시와 이미지 예시가 모두 포함된 혼합 데이터 세트는 지원되지 않습니다. 데이터 세트에 이미지 예가 하나 이상 있으면 텍스트 전용 예가 모두 필터링됩니다.
Qwen 3 4B 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Qwen 3 8B 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Qwen 3 14B 조정 모드 전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트
Qwen3 32B 조정 모드 Parameter-Efficient Fine-Tuning(PEFT)
전체 미세 조정
최대 시퀀스 길이 8192
형식 텍스트

시작하기 전에

  1. Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
  2. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Gemini Enterprise Agent Platform 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  5. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Gemini Enterprise Agent Platform 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

SDK를 설치하고 조정 방법의 라이브러리를 가져옵니다.

지도 미세 조정

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.tuning import sft, SourceModel

정제 조정

다음 SDK를 설치합니다.

pip install google-genai

그런 다음 다음 라이브러리를 가져옵니다.

import os
import time
import uuid

from google import genai
from google.genai import types
client = genai.Client(vertexai=True, project=PROJECT_ID, location=REGION)

조정을 위한 데이터 세트 준비

조정에는 학습 데이터 세트가 필요합니다. 조정된 모델의 성능을 평가하려면 선택적으로 검증 데이터 세트를 준비하는 것이 좋습니다.

데이터 세트는 지원되는 JSON Lines(JSONL) 형식 중 하나여야 하며, 각 줄에는 단일 조정 예시가 포함되어야 합니다.

JSONL 파일을 Cloud Storage에 업로드합니다.

텍스트 전용 데이터 세트

프롬프트 완성

{"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"}
]}

GenerateContent

{
"systemInstruction": {
  "parts": [{ "text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles." }]},
"contents": [
  {"role": "user",
    "parts": [{ "text": "Summarize the paper in one paragraph." }]},
  {"role": "assistant",
    "parts": [{ "text": "Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ..." }]}
]}

멀티모달 데이터 세트

턴 기반 채팅 형식

{"messages": [
  {"role": "user", "content": [
    {"type": "text", "text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles."},
    {"type": "image_url", "image_url": {
      "url": "gs://your-gcs-bucket/your-image.jpeg",
      "detail": "low"}}]
  },
  {"role": "assistant", "content": [
    {"type": "text", "text": "Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ..."}]
  },
  {"role": "user", "content": [
    {"type": "text", "text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles."},
    {"type": "image_url", "image_url": {
      "url": "data:image/jpeg;base64,<base64 image>",
      "detail": "low"}}]
  },
  {"role": "assistant", "content": [
    {"type": "text", "text": "Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ..."}]
  },
]}

GenerateContent

{
"systemInstruction": {
  "parts": [{ "text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles." }]},
"contents": [
  {"role": "user",
    "parts": [
      {"text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles." },
      {"file_data": {
        "mime_type": "image/jpeg", "file_uri": "gs://your-gcs-bucket/your-image.jpeg"}}]
  },
  {"role": "assistant",
    "parts": [{ "text": "Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ..." }]}
]}

지원되는 형식에는 JPEG, PNG, WEBP, Base64 인코딩 이미지가 포함됩니다.

이미지가 JSONL 파일과 다른 Cloud Storage 버킷에 저장된 경우 다음 두 서비스 계정의 두 버킷에 스토리지 객체 사용자(roles/storage.objectUser) IAM 역할을 부여해야 합니다.

  • service-PROJECT_NUMBER@gcp-sa-vertex-moss-ft.iam.gserviceaccount.com
  • service-PROJECT_NUMBER@gcp-sa-aiplatform.iam.gserviceaccount.com

튜닝 작업 만들기

다음 중 하나에서 조정을 시작할 수 있습니다.

  • 지원되는 기본 모델(예: Llama 3.1)
  • 지원되는 기본 모델과 동일한 아키텍처를 가진 모델. Hugging Face와 같은 저장소에서 가져온 커스텀 모델 체크포인트 또는 Gemini Enterprise Agent Platform 조정 작업에서 이전에 조정된 모델일 수 있습니다. 이렇게 하면 이미 조정된 모델을 계속 조정할 수 있습니다.

Cloud Console (감독 대상)

  1. 다음 방법으로 미세 조정을 시작할 수 있습니다.

    • 모델 카드로 이동하여 미세 조정을 클릭하고 관리형 조정을 선택합니다.

    Llama 3.1 모델 카드로 이동

    또는

    • 조정 페이지로 이동하여 조정된 모델 만들기를 클릭합니다.

    조정으로 이동

  2. 파라미터를 입력하고 조정 시작을 클릭합니다.

그러면 조정 작업이 시작되며, 관리형 조정 탭의 조정 페이지에서 확인할 수 있습니다.

조정 작업이 완료되면 세부정보 탭에서 조정된 모델의 정보를 확인할 수 있습니다.

Agent Platform SDK (감독)

파라미터 값을 사용자 값으로 바꾼 후 다음 코드를 실행하여 조정 작업을 만듭니다.

sft_tuning_job = sft.train(
    source_model=SourceModel(
      base_model="meta/llama3_1@llama-3.1-8b",
      # Optional, folder that is 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}",
)

GenAI SDK (증류)

파라미터 값을 사용자 값으로 바꾼 후 다음 코드를 실행하여 증류 조정 작업을 만듭니다.

tuning_job = client.tunings.tune(
    base_model="qwen/qwen3@qwen3-4b",
    training_dataset=types.TuningDataset(
        gcs_uri="gs://{STORAGE-URI}"
    ),
    config=types.CreateTuningJobConfig(
        method="DISTILLATION",
        base_teacher_model="qwen/qwen3-next-80b-a3b-thinking-maas",
        epoch_count=3,
        validation_dataset=types.TuningValidationDataset(
            gcs_uri="gs://{STORAGE-URI}"
        ),
        output_uri="gs://{STORAGE-URI}",
    ),
)

조정된 모델 아티팩트

미세 조정 작업이 완료되면 조정된 모델의 모델 아티팩트가 Cloud Storage 출력 디렉터리에 저장됩니다.

gs://<output_dir>/
    # (Distillation tuning only) The labeled dataset from teacher model's inference
    -> distillation_labelled_dataset.jsonl

gs://<output_dir>/postprocess/node-0/checkpoints/
    # Final checkpoint
    -> final/
        -> model-00001-of-000xx.safetensors
        -> model-000yy-of-000xx.safetensors

    # Intermediate checkpoints
    -> checkpoint-M/
        -> model-00001-of-000xx.safetensors
        -> model-000yy-of-000xx.safetensors
        -> checkpoint-N/
        -> model-00001-of-000xx.safetensors
        -> model-000yy-of-000xx.safetensors
  • 최대 10개의 체크포인트가 저장됩니다.
  • 에포크 수 (E)가 10보다 작으면 정확히 E개의 체크포인트가 저장됩니다 (에포크당 하나).
  • 범위 M~N의 중간 체크포인트가 정렬됩니다. 중간 체크포인트는 항상 연속적으로 번호가 매겨지는 것은 아닙니다. 예를 들어 체크포인트는 1, 2, 3, 4가 아닌 1, 3, 5, 10으로 번호가 매겨질 수 있습니다.

조정된 모델 배포

조정된 모델을 Gemini Enterprise Agent Platform 엔드포인트에 배포할 수 있습니다. Cloud Storage에서 조정된 모델을 내보낸 후 다른 환경에 배포할 수도 있습니다.

조정된 모델을 Gemini Enterprise Agent Platform 엔드포인트에 배포하려면 다음 단계를 따르세요.

Cloud Console

  1. Model Garden 페이지로 이동하여 커스텀 가중치로 모델 배포를 클릭합니다.

    Model Garden으로 이동

  2. 파라미터를 입력하고 배포를 클릭합니다.

Agent Platform 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추가 할당량을 요청해야 합니다.

증류 미세 조정은 조정 작업 할당량 외에도 교사 모델을 사용하므로 프로젝트에 지정된 교사 모델에 대한 충분한 할당량이 있어야 합니다. 서비스형으로 제공되는 개방형 모델 (MaaS)은 동적 공유 할당량을 사용합니다. 조정 작업에서 교사 모델을 호출하면 해당 모델에 대한 프로젝트의 공유 할당량이 소모됩니다. 관리형 개방형 모델의 할당량에 관한 자세한 내용은 MaaS용 Gemini Enterprise Agent Platform 관리형 모델을 참고하세요.

가격 책정

조정 비용은 모델 조정 가격 책정에 따라 청구됩니다. 학습 토큰 수는 학습 데이터 세트의 토큰 수와 에포크 수를 곱하여 계산됩니다. 정제 조정의 경우 관리형 모델 가격 책정에 따라 대답을 생성하기 위해 교사 모델에 이루어진 API 호출에 대해서도 요금이 청구됩니다.

또한 Cloud Storage 및 Gemini Enterprise Agent Platform Prediction과 같은 관련 서비스 사용에도 요금이 청구됩니다.

Gemini Enterprise Agent Platform 가격 책정, Cloud Storage 가격 책정에 대해 알아보고 가격 계산기를 사용하여 예상 사용량을 기준으로 예상 비용을 산출할 수 있습니다.

다음 단계