Lesson 25 Fine-Tuning via API
Theme:

Homework

Complete these tasks before Lesson 26. Each task builds on the lab exercises and deepens your understanding of API-based fine-tuning. Budget approximately 1–2 hours total.

Task 1: Fine-Tune for a New Domain

Goal: Apply the full fine-tuning pipeline to a domain of your choice, reinforcing each step from the lab.

Instructions

Choose a domain different from the customer-support scenario used in the lab. Good options include:

For your chosen domain:

  1. Write a clear system prompt that defines the assistant's role, tone, and output format.
  2. Create a JSONL file with at least 30 examples (more is better). Split 80/20 into training and validation sets.
  3. Run your validation script from Exercise 2 and fix any issues.
  4. Upload and fine-tune using the OpenAI API (or simulate with a dry-run if you want to avoid the cost).
  5. Evaluate on 5+ held-out test prompts, comparing fine-tuned vs. base model.

Deliverable

Your JSONL files (train.jsonl, val.jsonl) and a short written summary (~200 words) covering:

Self-check

Task 2: Hyperparameter Experiment

Goal: Build intuition for how hyperparameters affect fine-tuning outcomes.

Instructions

Using either your lab dataset (TechFlow support) or your Task 1 dataset, run three fine-tuning jobs with different epoch counts:

Jobn_epochsOther params
A1defaults
B3defaults
C6defaults

For each job, record:

  1. Final training loss
  2. Final validation loss (if you provided a validation file)
  3. Training time
  4. Evaluation scores on 5 held-out test prompts (use the same scorecard from Exercise 4)

Create a comparison table and answer these questions:

Cost Note

Running three fine-tuning jobs will cost approximately 3x a single job. For a 50-example dataset, this is still under $3 total. If cost is a concern, you can run Jobs A and C only (1 vs. 6 epochs) to see the contrast more clearly with just two jobs.

Deliverable

A comparison table (markdown or printed output) showing metrics for each job, plus a written paragraph (~150 words) explaining what you learned about epoch selection.

Self-check

Task 3: Cost Analysis — Fine-Tuning vs. Few-Shot

Goal: Make a data-driven decision about when fine-tuning is worth the investment compared to few-shot prompting.

Instructions

Consider a production workload with the following characteristics:

Calculate and compare:

  1. Monthly inference cost for few-shot approach on gpt-4o-mini
  2. Monthly inference cost for fine-tuned gpt-4o-mini (remember: fine-tuned inference rates are higher)
  3. One-time training cost for the fine-tuned model
  4. Break-even point: after how many days does the fine-tuning investment pay for itself?

Use the following rates (approximate, check current pricing):

ModelInput (per 1M tokens)Output (per 1M tokens)
gpt-4o-mini (base)$0.15$0.60
gpt-4o-mini (fine-tuned inference)$0.30$1.20
gpt-4o-mini (training)$3.00 / 1M tokens

Deliverable

A written analysis (~200–300 words) that includes:

Self-check

📥 Reference Solution

⬇ lab_answer.py

Submission

There is no formal submission for this course. These tasks are for your own development. However:

Next lesson: Lesson 26 — Dataset Curation — building and maintaining high-quality training datasets at scale.