Finetuning
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Data and AI
- MIT
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides the necessary procedures and tools for fine-tuning AI models on Microsoft Foundry. It supports three primary training methodologies: Supervised Fine-Tuning (SFT), Direct Preference Optimization (DPO), and Reinforcement Fine-Tuning (RFT). The skill encompasses the entire lifecycle, including dataset preparation, training job submission, monitoring, model evaluation, and deployment. It also includes specific guidance for agentic RFT, where models are trained to utilize external tools, and provides scripts for data validation, grader calibration, and resource management.
What it does
- Supports SFT, DPO, and RFT training methodologies.
- Provides data validation scripts for SFT, DPO, and RFT formats.
- Facilitates training job submission and monitoring on Microsoft Foundry.
- Enables calibration of RFT graders and pass thresholds.
- Offers tools for model evaluation and deployment via ARM REST API.
- Includes utilities for synthetic data generation and dataset quality scoring.
When to use it
- When you need to adapt a base model to specific tasks or domains.
- When preparing or validating training datasets for SFT, DPO, or RFT.
- When training models for agentic scenarios involving tool calling.
- When you need to evaluate and deploy a fine-tuned model.
- When troubleshooting training jobs or diagnosing poor model performance.
Advantages
- Standardized workflows for different training types.
- Includes built-in validation to prevent common data formatting errors.
- Supports complex agentic RFT training with tool integration.
- Provides robust scripts for monitoring and evaluating training progress.
- Offers clear guidance on grader design and hyperparameter tuning.
Usage examples
- “How do I validate my SFT dataset before training?”
- The agent will instruct you to use the python scripts/validate/validate_sft.py script on your data.jsonl file to ensure it meets the required format.
- “Submit an SFT training job using gpt-4.1-mini.”
- The agent will provide the command using scripts/submit_training.py with the appropriate flags for model, training file, validation file, and type.
- “How can I calibrate my RFT grader?”
- The agent will guide you to use scripts/calibrate_grader.py to find the optimal pass_threshold, aiming for a 25-50% failure rate on the base model.
- “Deploy my fine-tuned model after training.”
- The agent will provide the command to use scripts/deploy_model.py, specifying the model-id and a deployment name.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/microsoft/finetuning/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip finetuning.zip -d .agents/skills
Documentation by Microsoft
Fine-Tuning on Microsoft Foundry
Fine-tune models using SFT (supervised), DPO (preference), or RFT (reinforcement with graders). Covers dataset prep, training, deployment, and evaluation.
When to Use
Use this sub-skill when the user asks about:
Fine-tuning a model (SFT, DPO, or RFT)
Preparing, validating, or formatting training data
Submitting, monitoring, or diagnosing training jobs
Calibrating graders or pass thresholds for RFT
Deploying or evaluating a fine-tuned model
Choosing between training types (SFT vs DPO vs RFT)
Distillation, synthetic data generation, or dataset quality scoring
Large file uploads for training data
Cleaning up fine-tuning resources (files, deployments)
Do NOT use for: General model deployment without fine-tuning (use deploy-model), agent creation (use agents), prompt optimization without training (use prompt-optimizer).
Workflows
| Stage | Guide |
|---|---|
| Quick start | workflows/quickstart.md |
| Full pipeline | workflows/full-pipeline.md |
| Create data | workflows/dataset-creation.md |
| Iterate | workflows/iterative-training.md |
| Diagnose | workflows/diagnose-poor-results.md |
References
| Topic | File |
|---|---|
| SFT vs DPO vs RFT | references/training-types.md |
| Hyperparameters | references/hyperparameters.md |
| Data formats | references/dataset-formats.md |
| Grader design (RFT) | references/grader-design.md |
| Reward hacking | references/reward-hacking.md |
| Agentic RFT (tools) | references/agentic-rft.md |
| Deployment | references/deployment.md |
| Training curves | references/training-curves.md |
| Evaluation | references/evaluation.md |
| Vision fine-tuning | references/vision-fine-tuning.md |
| Large file uploads | references/large-file-uploads.md |
| Platform gotchas | references/platform-gotchas.md |
Scripts
| Script | Purpose |
|---|---|
scripts/submit_training.py | Submit SFT/DPO/RFT jobs |
scripts/monitor_training.py | Poll job until completion |
scripts/calibrate_grader.py | Find optimal RFT pass_threshold |
scripts/check_training.py | Analyze curves, list checkpoints |
scripts/deploy_model.py | Deploy via ARM REST API |
scripts/evaluate_model.py | LLM judge evaluation |
scripts/convert_dataset.py | Convert between SFT/DPO/RFT formats |
scripts/generate_distillation_data.py | Generate synthetic training data |
scripts/score_dataset.py | Quality scoring on training data |
scripts/cleanup.py | Delete old files and deployments |
scripts/validate/ | Data validators (SFT, DPO, RFT) + stats |
Rules
Always baseline first — evaluate the base model before fine-tuning
Validate data before submitting — run
scripts/validate/validate_sft.pyCalibrate RFT graders — target 25-50% failure rate on the base model
Evaluate checkpoints — don't blindly deploy the final one
Measure token cost alongside accuracy when comparing models
Quick Reference
| Task | Command |
|---|---|
| Validate SFT data | python scripts/validate/validate_sft.py data.jsonl |
| Submit SFT job | python scripts/submit_training.py --model gpt-4.1-mini --training-file train.jsonl --validation-file val.jsonl --type sft |
| Monitor job | python scripts/monitor_training.py --job-id ftjob-xxx |
| Analyze curves | python scripts/check_training.py --job-id ftjob-xxx |
| Deploy model | python scripts/deploy_model.py --model-id ft:gpt-4.1-mini:... --name my-eval |
| Evaluate model | python scripts/evaluate_model.py --deployment-name my-eval --test-file test.jsonl |
Error Handling
| Error | Cause | Fix |
|---|---|---|
| "API version not supported" | Older openai SDK on /v1/ endpoint | Upgrade to openai>=1.0 |
| "does not support fine-tuning with Standard TrainingType" | OSS model needs globalStandard | Use --use-rest flag or script auto-falls back |
| Job stuck in post-training eval | Under-provisioned tool endpoint (RFT) | Scale to S2+, enable Always On |
| "DeploymentNotReady" after ARM succeeds | ARM/data-plane race condition | Delete and recreate deployment, wait 5 min |
| Content safety block at deployment | PII-dense training data | Remove problematic document types |
Files
- ATTRIBUTION.mdAdded by AutoGineer998 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md5.4 KiB
- references/agentic-rft.md3.2 KiB
- references/dataset-formats.md3.7 KiB
- references/deployment.md3.4 KiB
- references/evaluation.md5.8 KiB
- references/grader-design.md3.4 KiB
- references/hyperparameters.md3.2 KiB
- references/large-file-uploads.md927 B
- references/platform-gotchas.md2.0 KiB
- references/reward-hacking.md2.9 KiB
- references/training-curves.md4.1 KiB
- references/training-types.md3.1 KiB
- references/vision-fine-tuning.md4.1 KiB
- scripts/calibrate_grader.pyScript9.3 KiB
- scripts/check_training.pyScript7.8 KiB
- scripts/cleanup.pyScript9.5 KiB
- scripts/common.pyScript7.6 KiB
- scripts/convert_dataset.pyScript10.7 KiB
- scripts/deploy_model.pyScript9.4 KiB
- scripts/evaluate_model.pyScript11.4 KiB
- scripts/generate_distillation_data.pyScript10.1 KiB
- scripts/monitor_training.pyScript5.7 KiB
- scripts/score_dataset.pyScript7.7 KiB
- scripts/submit_training.pyScript10.8 KiB
- scripts/validate/__init__.pyScript305 B
- scripts/validate/data_stats.pyScript6.2 KiB
- scripts/validate/validate_dpo.pyScript3.7 KiB
- scripts/validate/validate_rft.pyScript8.6 KiB
- scripts/validate/validate_sft.pyScript4.5 KiB
- workflows/dataset-creation.md3.1 KiB
- workflows/diagnose-poor-results.md2.3 KiB
- workflows/full-pipeline.md3.1 KiB
- workflows/iterative-training.md3.1 KiB
- workflows/quickstart.md4.5 KiB
references/evaluation.md
Evaluation Methodology
Principles
Always establish a baseline: Evaluate the base (un-tuned) model first. Without a baseline, you can't measure improvement.
Use a held-out test set: Never evaluate on training or validation data. The model has seen those.
Use the same test set for every model: This is the only way to compare results fairly.
Use task-specific graders: Built-in generic evaluators (Coherence, Fluency) measure general quality and won't detect fine-tuning improvements. Use custom graders (Python, score model, string check) for task-specific evaluation.
Measure cost alongside accuracy: Report completion tokens per response when comparing models or checkpoints. A model that achieves the same accuracy with fewer tokens is strictly better — cheaper inference and lower latency.
Two-Layer Evaluation Strategy
Use the Azure AI Evaluation SDK (azure-ai-evaluation) for all evaluation.
| Layer | Purpose | Grader Type | When |
|---|---|---|---|
| Task-specific (primary) | Measure FT improvement | AzureOpenAIScoreModelGrader, AzureOpenAIPythonGrader, AzureOpenAIStringCheckGrader | Every eval |
| General quality (guardrail) | Verify model didn't degrade | CoherenceEvaluator, FluencyEvaluator | Spot-check only |
Generic built-in evaluators (Coherence, Fluency, TaskAdherence) are guardrails, not metrics — they often show no difference between base and fine-tuned models even when domain-specific evaluation reveals clear improvement.
Custom Graders (Primary FT Evaluation)
1. Score Model Grader (LLM judge with task-specific rubric)
Best for: subjective tasks (summarization, alignment, style).
from azure.ai.evaluation import AzureOpenAIScoreModelGrader
summarization_grader = AzureOpenAIScoreModelGrader(
model_config=model_config,
name="summarization_quality",
prompt="""Rate this news summary on a scale of 1-5.
Article: {{item.article}}
Summary: {{sample.output_text}}
Criteria:
- Captures ALL key facts (who, what, when, where)
- No hallucinated information not in the article
- Concise (under 3 sentences)
Score 1: Missing key facts or hallucinations
Score 3: Captures main point but misses details
Score 5: Perfect summary — all facts, no extras, concise
Return ONLY a number 1-5.""",
output_type="numeric",
pass_threshold=3,
)2. Python Grader (programmatic/exact-match evaluation)
Best for: code generation, math, entity extraction, structured output.
from azure.ai.evaluation import AzureOpenAIPythonGrader
entity_grader = AzureOpenAIPythonGrader(
name="entity_extraction_accuracy",
source="""
import json
def grade(item, sample):
try:
extracted = json.loads(sample["output_text"])
reference = json.loads(item["ground_truth"])
except (json.JSONDecodeError, KeyError):
return {"score": 0, "reason": "Invalid JSON output"}
required_keys = ["people", "organizations", "locations", "dates"]
missing = [k for k in required_keys if k not in extracted]
if missing:
return {"score": 0.5, "reason": f"Missing keys: {missing}"}
total, matched = 0, 0
for key in required_keys:
ref_set = set(str(v).lower() for v in reference.get(key, []))
ext_set = set(str(v).lower() for v in extracted.get(key, []))
total += len(ref_set)
matched += len(ref_set & ext_set)
score = matched / total if total > 0 else 1.0
return {"score": score, "reason": f"{matched}/{total} entities matched"}
""",
pass_threshold=0.7,
)3. String Check Grader (pattern matching)
Best for: classification, format compliance, tool calling format.
from azure.ai.evaluation import AzureOpenAIStringCheckGrader
tool_format_grader = AzureOpenAIStringCheckGrader(
name="tool_call_format",
input="{{sample.output_text}}",
operation="like", # or "eq", "starts_with", "contains"
reference="function_call",
pass_threshold=1,
)
classification_grader = AzureOpenAIStringCheckGrader(
name="classification_accuracy",
input="{{sample.output_text}}",
operation="eq",
reference="{{item.expected_label}}",
pass_threshold=1,
)Running an Evaluation
The evaluate() function runs multiple graders over an entire dataset:
from azure.ai.evaluation import evaluate, F1ScoreEvaluator
result = evaluate(
data="eval_data.jsonl",
evaluators={
"task_grader": my_custom_score_grader, # primary
"f1": F1ScoreEvaluator(), # token overlap
},
output_path="./eval_results.json",
)
for metric, value in result["metrics"].items():
print(f"{metric}: {value}")Test Set Design
Size: 30–100 examples is sufficient.
Diversity: Cover easy/medium/hard, edge cases, and different sub-categories.
Quality: Reference answers must be gold-standard correct. A wrong reference penalizes correct outputs.
Interpreting Results
| Score Type | Range | Meaning |
|---|---|---|
| AI quality (1–5) | 1–2 Poor, 3 Adequate, 4 Good, 5 Excellent | |
| NLP (0–1) | <0.3 Wrong, 0.3–0.6 Partial, 0.6–0.8 Good, >0.8 Strong |
With 50+ eval examples, a difference of ~0.3 points (on 1–5 scale) is usually meaningful.
Evaluating RFT Models
Evaluate with a DIFFERENT rubric than the training grader — otherwise you measure overfitting to the grader.
Use
F1ScoreEvaluatorfor exact-match accuracy.Use
SimilarityEvaluatorto catch semantically correct but differently formatted answers.Compare against the base model, not just other fine-tunes.
Reference
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
What our scanner noticed· Low risk
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Microsoft
- Publisher
- Microsoft (Official)
- Source
- microsoft/skills · .github/plugins/azure-skills/skills/microsoft-foundry/finetuning · commit 0696600
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from .github/plugins/azure-skills/LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Also distributed in
- microsoft/azure-skills
AutoGineer is not affiliated with or endorsed by Microsoft or Microsoft.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download finetuning.zip