Fine-tune your models with Vertex AI
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
provider="@VERTEX_PROVIDER",
vertex_storage_bucket_name="your_bucket_name", # Specify the GCS bucket name
provider_file_name="your_file_name.jsonl", # Specify the file name in GCS
provider_model="gemini-1.5-flash-001" # Specify the model to fine-tune
)
# Upload a file for fine-tuning
file = portkey.files.create(
file=open("dataset.jsonl", "rb"),
purpose="fine-tune"
)
print(file)
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
provider="@VERTEX_PROVIDER"
)
# Create a fine-tuning job
fine_tune_job = portkey.fine_tuning.jobs.create(
model="gemini-1.5-pro-002", # Base model to fine-tune
training_file="<file_id>", # Encoded GCS path to the training file
suffix="finetune_name", # Custom suffix for the fine-tuned model name
hyperparameters={
"n_epochs": 2
}
)
print(fine_tune_job)
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
provider="@VERTEX_PROVIDER"
)
# List all fine-tuning jobs
jobs = portkey.fine_tuning.jobs.list(
limit=10 # Optional: Number of jobs to retrieve (default: 20)
)
print(jobs)
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
provider="@VERTEX_PROVIDER"
)
# Retrieve a specific fine-tuning job
job = portkey.fine_tuning.jobs.retrieve(
"job_id" # The ID of the fine-tuning job to retrieve
)
print(job)
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
provider="@VERTEX_PROVIDER"
)
# Cancel a fine-tuning job
cancelled_job = portkey.fine_tuning.jobs.cancel(
"job_id" # The ID of the fine-tuning job to cancel
)
print(cancelled_job)
Was this page helpful?