Gemini モデルの教師ありファインチューニングでチェックポイントを使用する

チェックポイントとは、ファインチューニング プロセスの特定の時点でのモデルの状態のスナップショットです。Gemini モデルのファインチューニングで中間チェックポイントを使用すると、次のことができます。

  • チューニングの進行状況を保存する。
  • 中間チェックポイントのパフォーマンスを比較する。
  • 過学習前のパフォーマンスが最も高いチェックポイントをデフォルト チェックポイントとして選択する。

エポック数が 10 未満のチューニング ジョブの場合、おおよそ各エポックの後に 1 つのチェックポイントが保存されます。エポック数が 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. [確認] をクリックします。

    指標グラフとチェックポイント テーブルが更新され、新しいデフォルト チェックポイントが表示されます。TuningJob の詳細ページのエンドポイントが更新され、新しいデフォルト チェックポイントのエンドポイントが表示されます。

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

次のステップ