Optimize Generative AI Systems and Model Performance · Topic 3 of 3
Fine-Tuning Methods, Synthetic Data and Production Deployment
AI-300 optimization: choose fine-tuning methods such as SFT and DPO, build synthetic data, monitor tuned models and deploy them to production safely.
- 6 min
- Order of effort: prompt, then RAG, then fine-tuning.
- SFT uses prompt and response pairs; DPO uses preferred and non preferred responses.
- Keep a clean, real validation and evaluation set; filter synthetic data.
What it is
Fine-tuning continues training a model on your examples so it learns a style, format or behaviour. It is one of three levers, and the most expensive to maintain, so use the cheaper ones first. Synthetic data is training data generated by a stronger model (and then filtered) when real examples are scarce. A tuned model is a versioned asset that moves from development to production like any other.
How it works
Prompting, RAG or fine-tuning
| Need | Best lever |
|---|---|
| Better instructions, format, tone | Prompt engineering and few shot examples |
| Fresh or private knowledge, citations | RAG |
| Consistent style or structure, domain behaviour, shorter prompts, a smaller cheaper model matching a larger one | Fine-tuning |
| Teach a model new facts that change often | Not fine-tuning; use RAG |
Fine-tuning changes how a model behaves, not reliably what it knows.
Advanced methods
| Method | What it trains on | Use for |
|---|---|---|
| Supervised fine-tuning (SFT) | Prompt and ideal response pairs | Teach format, style, task behaviour |
| Direct preference optimization (DPO) | A prompt with a preferred and a non preferred response | Align outputs to preferences: tone, safety, choosing better answers |
| Reinforcement fine-tuning | A grader that scores the model's own attempts | Reasoning tasks where answers can be graded (availability limited to some models) |
| Distillation | Outputs of a large teacher model used to train a smaller student | Lower cost and latency for a narrow task |
| Parameter efficient (LoRA family) | A small set of added weights | Cheaper tuning of open models; adapters can be served on managed compute (preview) |
Data formats are JSONL. SFT for chat models:
{"messages": [{"role": "system", "content": "You are a support agent. Answer in two sentences."}, {"role": "user", "content": "How do I reset my token?"}, {"role": "assistant", "content": "Open the Security portal and choose Reset token. A new token is sent within a minute."}]}
DPO:
{"input": {"messages": [{"role": "user", "content": "Summarize this ticket."}]}, "preferred_output": [{"role": "assistant", "content": "Customer cannot sign in after a password reset."}], "non_preferred_output": [{"role": "assistant", "content": "The ticket is about a thing."}]}
A training job takes a training file, an optional validation file, and hyperparameters such as n_epochs, batch_size and learning_rate_multiplier:
training = client.files.create(file=open("train.jsonl", "rb"), purpose="fine-tune")
validation = client.files.create(file=open("val.jsonl", "rb"), purpose="fine-tune")
job = client.fine_tuning.jobs.create(
model=base_model,
training_file=training.id,
validation_file=validation.id,
method={"type": "supervised",
"supervised": {"hyperparameters": {"n_epochs": 3}}},
extra_body={"trainingType": "GlobalStandard"},
)
Here client comes from AIProjectClient(...).get_openai_client(), and base_model supports fine-tuning for the method you choose. For DPO use method={"type": "dpo"}. The training type is Standard (region), Data zone, Global (cheaper, no residency guarantee) or Developer (idle capacity, can be preempted). Foundry User is enough to train; deploying the tuned model also needs Foundry Owner or a role that can write deployments. Quality beats quantity.
Synthetic data
- Write seed examples by hand that show exactly the target behaviour.
- Use a stronger teacher model to generate many variations (new inputs and ideal responses), prompting for diversity across topics, lengths and difficulty.
- Filter: validate the format, remove duplicates, drop low quality items with a judge model or rules, check for personal data and for accidental copies of test cases.
- Mix with real examples when you have them, and keep the evaluation set real and untouched.
- Version and document the data: generator model and prompt, date, filters and counts, stored in Git or as a data asset.
Check the teacher model's terms of use before training on its outputs. Synthetic data can repeat the teacher's mistakes and be too uniform, so sample and read it.
Monitor and optimize the tuned model
Training produces metrics: training loss, validation loss and token accuracy. Validation loss rising while training loss falls means overfitting. Remedies: fewer epochs, more or more varied data, or a lower learning rate multiplier. Then:
- Evaluate the tuned model against the base model (with the best prompt) on the same held out set, using task, quality and safety evaluators.
- Check for regression on general abilities and safety, since tuning can weaken them.
- Compare cost and latency: a tuned small model with a short prompt may beat a large model.
- Do error analysis on failures, add targeted examples, and retrain; this loop is normal.
- In production, run continuous evaluation, track input drift, and re-tune when behaviour or data changes.
Development to production
| Stage | Practice |
|---|---|
| Develop | Train in a dev Foundry resource; record base model, data version, hyperparameters and evaluation scores |
| Evaluate | Gate on thresholds against the base model and safety checks |
| Approve | Review, then record the approved model name and version in Git or an asset registry |
| Deploy | Create a named deployment of the tuned model; the Developer deployment type (24 hour life, no SLA) suits candidate tests |
| Release | Canary traffic, monitor, then cut over; keep the previous deployment ready for rollback |
| Operate | Monitor, and retire stale deployments |
Tuned models carry hosting charges (the Developer type has no hourly hosting fee), so delete deployments you do not use. Cancelling a training job does not delete a deployment or stop its charges. Automate retraining and deployment in a pipeline (GitHub Actions) with the same evaluation gates as for prompts.
A worked example
A claims team needs summaries in a strict template. They hand write 40 seed examples, generate 2,000 more with a teacher model, filter to 1,400, and add 300 real examples. After SFT with three epochs, validation loss flattens, template compliance rises from 71 to 97 percent, and a smaller model replaces the larger one with a shorter prompt. The tuned deployment gets 10 percent of traffic first, with the old one kept for rollback.
How the exam asks about this
- "Teach consistent output structure; knowledge changes weekly." Fine-tune for structure and use RAG for knowledge.
- "Model outputs must follow reviewer preferences between two answers." DPO with preferred and non preferred outputs.
- "Validation loss rises while training loss falls." Overfitting; reduce epochs or add data.
What to remember for the exam
- Order of effort: prompt, then RAG, then fine-tuning.
- SFT uses prompt and response pairs; DPO uses preferred and non preferred responses.
- Keep a clean, real validation and evaluation set; filter synthetic data.
- Compare tuned and base models on the same evaluators, including safety.
- Tuned model deployments cost per hour; manage lifecycle and rollback.
Do not evaluate a tuned model on data that came from the same synthetic generator that trained it. Scores will look better than reality.
Common mistakes
Fine-tuning to add facts. It does not reliably store them. Use retrieval.
Training on unfiltered synthetic data. Errors and duplicates are learned.
Skipping the base model comparison. You may pay for a tuned model that is no better than a good prompt.
Check yourself
Which fine-tuning method needs preferred and non preferred responses?
Direct preference optimization (DPO).
What does rising validation loss with falling training loss indicate?
Overfitting.
Why keep the evaluation set separate from synthetic training data?
So scores reflect real performance and not memorized or generated patterns.
Topic 3 of 3 in Optimize Generative AI Systems and Model Performance
Test yourself on Optimize Generative AI Systems and Model Performance
The full Microsoft AI-300 question bank has 650 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Microsoft. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.