Gemini 모델의 지도 미세 조정에서 체크포인트 사용

체크포인트는 미세 조정 프로세스의 특정 시점에서의 모델 상태 스냅샷입니다. Gemini 모델 미세 조정에서 중간 체크포인트를 사용하여 다음 작업을 할 수 있습니다.

  • 조정 진행 상황을 저장합니다.
  • 중간 체크포인트의 성능을 비교합니다.
  • 과적합이 발생하기 전에 성능이 가장 우수한 체크포인트를 선택하여 기본 체크포인트로 설정합니다.

에포크가 10개 미만인 조정 작업의 경우 각 에포크가 끝날 때마다 체크포인트가 하나씩 저장됩니다. 10개가 넘는 에포크가 있는 조정 작업의 경우 모든 에포크가 학습된 직후에 저장되는 최종 체크포인트를 제외하고 약 10개의 체크포인트가 균등하게 분포되어 저장됩니다.

중간 체크포인트는 조정이 진행됨에 따라 순차적으로 새 엔드포인트에 배포됩니다. 조정된 모델 엔드포인트는 기본 체크포인트의 엔드포인트를 나타내고, 조정된 모델 체크포인트에는 모든 체크포인트와 해당 엔드포인트가 포함됩니다.

지원되는 모델

다음 Gemini 모델은 체크포인트를 지원합니다.

Gemini 모델 버전에 관한 자세한 내용은 Google 모델모델 버전 및 수명 주기를 참조하세요.

체크포인트를 내보내는 조정 작업 만들기

Google Gen AI SDK 또는 Google Cloud 콘솔을 사용하여 체크포인트를 내보내는 지도 미세 조정 작업을 만들 수 있습니다.

콘솔

체크포인트를 내보내는 조정 작업을 만들려면 Vertex AI Studio 페이지로 이동하여 조정 탭을 선택합니다. 자세한 내용은 모델 조정을 참조하세요.

Google Gen AI SDK

(프리뷰) 각 체크포인트 후에 평가가 자동으로 실행되도록 Gen AI Evaluation Service를 구성할 수 있습니다. 이 평가 구성은 us-central1 리전에서 사용할 수 있습니다.

import time

from google import genai
from google.genai.types import HttpOptions, CreateTuningJobConfig, TuningDataset, EvaluationConfig, OutputConfig, GcsDestination, Metric

# TODO(developer): Update and un-comment below line
# output_gcs_uri = "gs://your-bucket/your-prefix"

client = genai.Client(http_options=HttpOptions(api_version="v1beta1"))

training_dataset = TuningDataset(
    gcs_uri="gs://cloud-samples-data/ai-platform/generative_ai/gemini/text/sft_train_data.jsonl",
)
validation_dataset = TuningDataset(
    gcs_uri="gs://cloud-samples-data/ai-platform/generative_ai/gemini/text/sft_validation_data.jsonl",
)

evaluation_config = EvaluationConfig(
    metrics=[
        Metric(
            name="FLUENCY",
            prompt_template="""Evaluate this {prediction}"""
        )
    ],
    output_config=OutputConfig(
        gcs_destination=GcsDestination(
            output_uri_prefix=output_gcs_uri,
        )
    ),
)

tuning_job = client.tunings.tune(
    base_model="gemini-2.5-flash",
    training_dataset=training_dataset,
    config=CreateTuningJobConfig(
        tuned_model_display_name="Example tuning job",
        # Set to True to disable tuning intermediate checkpoints. Default is False.
        export_last_checkpoint_only=False,
        validation_dataset=validation_dataset,
        evaluation_config=evaluation_config,
    ),
)

running_states = set([
    "JOB_STATE_PENDING",
    "JOB_STATE_RUNNING",
])

while tuning_job.state in running_states:
    print(tuning_job.state)
    tuning_job = client.tunings.get(name=tuning_job.name)
    time.sleep(60)

print(tuning_job.tuned_model.model)
print(tuning_job.tuned_model.endpoint)
print(tuning_job.experiment)
# Example response:
# projects/123456789012/locations/us-central1/models/1234567890@1
# projects/123456789012/locations/us-central1/endpoints/123456789012345
# projects/123456789012/locations/us-central1/metadataStores/default/contexts/tuning-experiment-2025010112345678

if tuning_job.tuned_model.checkpoints:
    for i, checkpoint in enumerate(tuning_job.tuned_model.checkpoints):
        print(f"Checkpoint {i + 1}: ", checkpoint)
    # Example response:
    # Checkpoint 1:  checkpoint_id='1' epoch=1 step=10 endpoint='projects/123456789012/locations/us-central1/endpoints/123456789000000'
    # Checkpoint 2:  checkpoint_id='2' epoch=2 step=20 endpoint='projects/123456789012/locations/us-central1/endpoints/123456789012345'

조정 작업의 체크포인트 나열

Google Cloud 콘솔에서 완료된 조정 작업의 체크포인트를 보거나 Google Gen AI SDK를 사용하여 나열할 수 있습니다.

중간 체크포인트가 중지된 경우 최종 체크포인트만 표시되거나 반환됩니다.

콘솔

  1. Google Cloud 콘솔에서 조정된 모델을 찾으려면 Vertex AI Studio 페이지로 이동합니다.

    Vertex AI Studio로 이동

  2. 조정 탭에서 모델을 찾아 모니터링을 클릭합니다.

    모델의 조정 측정항목과 체크포인트가 표시됩니다. 각 측정항목 그래프에서 체크포인트 번호는 다음과 같이 주석으로 표시됩니다.

    • 각 에포크에는 단계 번호와 에포크 번호가 표시됩니다.
    • 단계 번호는 체크포인트가 저장된 정확한 단계입니다.
    • 에포크 번호는 체크포인트가 속한 예상 에포크 번호입니다. 단, 완료된 조정 작업의 최종 체크포인트는 정확한 에포크 번호를 갖습니다.

Google Gen AI SDK

from google import genai
from google.genai.types import HttpOptions

client = genai.Client(http_options=HttpOptions(api_version="v1"))

# Get the tuning job and the tuned model.
# Eg. tuning_job_name = "projects/123456789012/locations/us-central1/tuningJobs/123456789012345"
tuning_job = client.tunings.get(name=tuning_job_name)

if tuning_job.tuned_model.checkpoints:
    for i, checkpoint in enumerate(tuning_job.tuned_model.checkpoints):
        print(f"Checkpoint {i + 1}: ", checkpoint)
# Example response:
# Checkpoint 1:  checkpoint_id='1' epoch=1 step=10 endpoint='projects/123456789012/locations/us-central1/endpoints/123456789000000'
# Checkpoint 2:  checkpoint_id='2' epoch=2 step=20 endpoint='projects/123456789012/locations/us-central1/endpoints/123456789012345'

모델 세부정보 및 체크포인트 보기

Google Cloud 콘솔에서 조정된 모델을 보거나 Google Gen AI SDK를 사용하여 엔드포인트와 체크포인트를 비롯한 모델 세부정보를 가져올 수 있습니다.

모델의 Endpoint 필드가 다음과 같이 업데이트됩니다.

  • 기본 체크포인트를 기반으로 업데이트되며, 조정 중에 업데이트된 기본 체크포인트를 위해 조정 작업에서 생성한 엔드포인트를 나타냅니다.
  • 모델이 없거나 조정 작업에서 모델을 가져오지 못하면 Endpoint 값이 비어 있습니다.
  • 기본 체크포인트가 배포되지 않은 경우(조정이 아직 진행 중이거나 배포가 실패한 경우) Endpoint 값이 비어 있습니다.

콘솔

온라인 예측 엔드포인트 페이지의 Vertex AI Model Registry에서 조정된 모델을 볼 수 있습니다.

  1. Google Cloud 콘솔의 Vertex AI 섹션에서 Model Registry 페이지로 이동합니다.

    Model Registry 페이지로 이동

  2. 모델 이름을 클릭합니다.

    모델의 기본 버전이 표시됩니다.

  3. 버전 세부정보 탭을 클릭하여 모델 버전에 관한 정보를 확인합니다.

    목표Large model, 모델 유형Foundation, 소스Vertex AI Studio tuning입니다.

  4. 배포 및 테스트 탭을 클릭하여 모델이 배포된 엔드포인트를 확인합니다.

  5. 엔드포인트 이름을 클릭하여 엔드포인트 페이지로 이동하여 엔드포인트에 배포된 체크포인트 목록을 확인합니다. 체크포인트마다 모델 버전 ID와 체크포인트 ID가 표시됩니다.

또는 조정 작업 세부정보 페이지에서 체크포인트를 볼 수도 있습니다. 이 페이지를 보려면 조정 페이지로 이동하여 조정 작업 중 하나를 클릭하세요.

조정 페이지로 이동

Google Gen AI SDK

from google import genai
from google.genai.types import HttpOptions

client = genai.Client(http_options=HttpOptions(api_version="v1"))

# Get the tuning job and the tuned model.
# Eg. tuning_job_name = "projects/123456789012/locations/us-central1/tuningJobs/123456789012345"
tuning_job = client.tunings.get(name=tuning_job_name)
tuned_model = client.models.get(model=tuning_job.tuned_model.model)
print(tuned_model)
# Example response:
# Model(name='projects/123456789012/locations/us-central1/models/1234567890@1', ...)

print(f"Default checkpoint: {tuned_model.default_checkpoint_id}")
# Example response:
# Default checkpoint: 2

if tuned_model.checkpoints:
    for _, checkpoint in enumerate(tuned_model.checkpoints):
        print(f"Checkpoint {checkpoint.checkpoint_id}: ", checkpoint)
# Example response:
# Checkpoint 1:  checkpoint_id='1' epoch=1 step=10
# Checkpoint 2:  checkpoint_id='2' epoch=2 step=20

각 체크포인트 후에 평가를 실행하도록 Gen AI Evaluation Service를 구성한 경우 평가 결과를 위해 구성한 Cloud Storage 버킷을 확인합니다.

체크포인트 테스트

Vertex AI Model Registry에서 체크포인트 목록을 보고 각 체크포인트를 테스트할 수 있습니다. 또는 Google Gen AI SDK를 사용하여 체크포인트를 나열하고 테스트할 수 있습니다.

콘솔

  1. Google Cloud 콘솔에서 조정된 모델을 찾으려면 Vertex AI Studio 페이지로 이동합니다.

    Vertex AI Studio로 이동

  2. 조정 탭에서 모델을 찾아 모니터링을 클릭합니다.

  3. 모니터링 창의 체크포인트 테이블에서 원하는 체크포인트 옆에 있는 테스트 링크를 클릭합니다.

Google Gen AI SDK

from google import genai
from google.genai.types import HttpOptions

client = genai.Client(http_options=HttpOptions(api_version="v1"))

# Get the tuning job and the tuned model.
# Eg. tuning_job_name = "projects/123456789012/locations/us-central1/tuningJobs/123456789012345"
tuning_job = client.tunings.get(name=tuning_job_name)

contents = "Why is the sky blue?"

# Predicts with the default checkpoint.
response = client.models.generate_content(
    model=tuning_job.tuned_model.endpoint,
    contents=contents,
)
print(response.text)
# Example response:
# The sky is blue because ...

# Predicts with Checkpoint 1.
checkpoint1_response = client.models.generate_content(
    model=tuning_job.tuned_model.checkpoints[0].endpoint,
    contents=contents,
)
print(checkpoint1_response.text)
# Example response:
# The sky is blue because ...

# Predicts with Checkpoint 2.
checkpoint2_response = client.models.generate_content(
    model=tuning_job.tuned_model.checkpoints[1].endpoint,
    contents=contents,
)
print(checkpoint2_response.text)
# Example response:
# The sky is blue because ...

새 기본 체크포인트 선택

기본 체크포인트를 사용하여 성능이 가장 우수한 체크포인트를 나타낼 수 있습니다. 기본적으로 기본 체크포인트는 조정 작업의 최종 체크포인트입니다.

체크포인트가 있는 모델을 배포하면 기본 체크포인트가 배포됩니다.

체크포인트가 있는 모델을 복사하면 대상 모델의 기본 체크포인트 ID가 소스 모델과 동일합니다. 모든 체크포인트가 복사되므로 대상 모델의 새 기본 체크포인트를 선택할 수 있습니다.

기본 체크포인트를 업데이트하면 조정 작업 엔드포인트가 업데이트되며, 예측에 이 새 엔드포인트를 사용할 수 있습니다.

콘솔

  1. Google Cloud 콘솔에서 조정된 모델을 찾으려면 Vertex AI Studio 페이지로 이동합니다.

    Vertex AI Studio로 이동

  2. 조정 탭에서 모델을 찾아 모니터링을 클릭합니다.

  3. 모니터링 창의 체크포인트 테이블에서 원하는 체크포인트 옆에 있는 작업을 클릭하고 기본값으로 설정을 선택합니다.

  4. 확인을 클릭합니다.

    측정항목 그래프와 체크포인트 테이블이 업데이트되어 새 기본 체크포인트를 표시합니다. 조정 작업 세부정보 페이지의 엔드포인트가 업데이트되어 새 기본 체크포인트의 엔드포인트가 표시됩니다.

Google Gen AI SDK

from google import genai
from google.genai.types import HttpOptions, UpdateModelConfig

client = genai.Client(http_options=HttpOptions(api_version="v1"))

# Get the tuning job and the tuned model.
# Eg. tuning_job_name = "projects/123456789012/locations/us-central1/tuningJobs/123456789012345"
tuning_job = client.tunings.get(name=tuning_job_name)
tuned_model = client.models.get(model=tuning_job.tuned_model.model)

print(f"Default checkpoint: {tuned_model.default_checkpoint_id}")
print(f"Tuned model endpoint: {tuning_job.tuned_model.endpoint}")
# Example response:
# Default checkpoint: 2
# projects/123456789012/locations/us-central1/endpoints/123456789012345

# Set a new default checkpoint.
# Eg. checkpoint_id = "1"
tuned_model = client.models.update(
    model=tuned_model.name,
    config=UpdateModelConfig(default_checkpoint_id=checkpoint_id),
)

print(f"Default checkpoint: {tuned_model.default_checkpoint_id}")
print(f"Tuned model endpoint: {tuning_job.tuned_model.endpoint}")
# Example response:
# Default checkpoint: 1
# projects/123456789012/locations/us-central1/endpoints/123456789000000

다음 단계