Implementation:Googleapis Python genai Tunings Tune
| Knowledge Sources | |
|---|---|
| Domains | Fine_Tuning, Model_Training |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for launching model fine-tuning jobs provided by the google-genai tunings module.
Description
Tunings.tune submits a fine-tuning job to the Google AI service. It accepts a base model ID, a TuningDataset, and optional CreateTuningJobConfig. The method validates inputs, sends the request via the appropriate backend (Gemini Developer API or Vertex AI), and returns a TuningJob object with the job's resource name, state, and metadata. The tuning job runs asynchronously server-side.
Usage
Call client.tunings.tune with the base model, training dataset, and optional config. Store the returned TuningJob's name for monitoring. The job runs in the background; use tunings.get to check progress.
Code Reference
Source Location
- Repository: googleapis/python-genai
- File: google/genai/tunings.py
- Lines: L1725
Signature
class Tunings:
def tune(
self,
*,
base_model: str,
training_dataset: types.TuningDatasetOrDict,
config: Optional[types.CreateTuningJobConfigOrDict] = None,
) -> types.TuningJob:
"""Launches a fine-tuning job.
Args:
base_model: Base model ID to fine-tune (e.g., 'gemini-1.5-flash-002').
training_dataset: Training data (TuningDataset or dict).
config: Optional tuning job configuration.
"""
Import
from google import genai
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| base_model | str | Yes | Base model to fine-tune (e.g., 'gemini-1.5-flash-002') |
| training_dataset | TuningDatasetOrDict | Yes | Training data from TuningDataset |
| config | Optional[CreateTuningJobConfigOrDict] | No | Tuning job configuration |
Outputs
| Name | Type | Description |
|---|---|---|
| TuningJob | types.TuningJob | Job object with .name, .state, .tuned_model, .create_time |
Usage Examples
Launch a Tuning Job
from google import genai
from google.genai import types
client = genai.Client(
vertexai=True,
project="my-project",
location="us-central1"
)
tuning_job = client.tunings.tune(
base_model="gemini-1.5-flash-002",
training_dataset=types.TuningDataset(
gcs_uri="gs://my-bucket/training_data.jsonl"
),
config=types.CreateTuningJobConfig(
epoch_count=5,
tuned_model_display_name="my-classifier",
),
)
print(f"Job name: {tuning_job.name}")
print(f"State: {tuning_job.state}")
Launch with Inline Examples
tuning_job = client.tunings.tune(
base_model="gemini-1.5-flash-002",
training_dataset=types.TuningDataset(
examples=[
types.TuningExample(text_input="Hello", output="Hi there!"),
types.TuningExample(text_input="Bye", output="Goodbye!"),
]
),
)