C.W.K.
Stream
Lesson 03 of 04 · published

Creating & Monitoring Jobs

~22 min · openai, jobs, hyperparameters, monitoring

Level 0Observer
0 XP0/43 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Create the job

Once your files are uploaded, kick off the fine-tuning job. "auto" on every hyperparameter is the right default for most projects — OpenAI tunes them based on dataset size.

Monitoring

The job goes through queued → running → succeeded/failed. Watch the events stream for training and validation loss; OpenAI emits a metrics line every ~50 steps.

Hyperparameter guide

ParameterDefaultWhen to override
n_epochsauto (usually 3)If validation loss rises early → reduce to 1 or 2.
batch_sizeautoRarely needed. Auto picks a sane size based on dataset.
learning_rate_multiplierautoLower (0.5–1.0) for small datasets, higher (1.5–2.0) for large.

Code

Create a job, then watch events + checkpoints·python
from openai import OpenAI
import time

client = OpenAI()

job = client.fine_tuning.jobs.create(
    training_file="file-abc123",
    validation_file="file-def456",
    model="gpt-4.1-mini-2025-04-14",
    suffix="my-custom-model",
    hyperparameters={
        "n_epochs": 3,
        "batch_size": "auto",
        "learning_rate_multiplier": "auto",
    },
    seed=42,  # reproducibility
)
print(f"Job ID: {job.id}, status: {job.status}")

# Poll for events as the job runs
last_seen = None
while True:
    events = client.fine_tuning.jobs.list_events(
        fine_tuning_job_id=job.id, limit=20
    )
    for e in reversed(events.data):
        if last_seen is None or e.created_at > last_seen:
            print(f"{e.created_at}: {e.message}")
    last_seen = events.data[0].created_at if events.data else last_seen

    j = client.fine_tuning.jobs.retrieve(job.id)
    if j.status in ("succeeded", "failed", "cancelled"):
        print(f"Final status: {j.status}")
        if j.status == "succeeded":
            print(f"Fine-tuned model: {j.fine_tuned_model}")
        break
    time.sleep(60)

# After completion: list checkpoints
checkpoints = client.fine_tuning.jobs.checkpoints.list(job.id)
for cp in checkpoints.data:
    print(f"step {cp.step_number}: {cp.fine_tuned_model_checkpoint}")
    print(f"  train loss: {cp.metrics.get('train_loss')}")
    print(f"  valid loss: {cp.metrics.get('valid_loss')}")

External links

Exercise

Using the file IDs from the previous lesson, kick off a fine-tuning job with seed=42 and three epochs. Poll the events stream until completion. Record training and validation loss at each checkpoint. Pick the checkpoint with the lowest validation loss as your production model.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.