Skip to content

Commit 3258c60

Browse files
AliciaFrameCopilot
andauthored
Add monitor_training + calibrate_grader scripts, fix 4 bugs (#30)
* Add monitor + calibrate scripts, fix 4 bugs from code review New scripts: - monitor_training.py: Poll a running job until completion, stream events in real time with status icons for reward steps, errors, and milestones - calibrate_grader.py: Run base model on training data, score with your Python grader, output pass rates at every threshold, recommend optimal pass_threshold. Automates the most critical pre-RFT step. Bug fixes (from code review, missed in PR #29 squash): - submit_training.py, deploy_model.py: Add missing 'requests' to PEP 723 deps - submit_training.py: Fix file handle leak on grader file read - evaluate_model.py: Fix StopIteration crash on malformed test data - validate/validate_rft.py: Fix broken newline escape detection logic Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add quickstart guide: 5-step path to first fine-tuned model New workflow: quickstart.md — goes from zero to a deployed fine-tuned model in 5 steps (credentials, data prep, submit, monitor, deploy+test). Targets novice users who just want to get started without reading the full pipeline guide. SKILL.md updated to list quickstart as the first workflow option. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Revise quickstart: synthetic data from prompt, baseline step, comparison - Step 2: Generate training data from a prompt (no pre-existing data needed) - Step 3: Baseline the base model before training (see what you're improving) - Step 6: Side-by-side comparison of base vs fine-tuned on same questions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add cleanup.py: list and delete old files, deployments, pending jobs Helps users avoid quota exhaustion (max 100 files per resource). Supports: - --list (all/jobs/deployments/files) for resource inventory - --delete-files with optional --older-than N days filter - --cancel-pending to cancel queued jobs - --dry-run to preview before executing Includes quota warning when approaching 80/100 file limit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix: JSON parsing for LLM output, align failure rate docs to 25-50% 1. quickstart.md: Use regex to extract JSON from code fences — the simple strip() approach fails when LLM adds preamble text before the JSON block 2. grader-design.md: Change prose from '30-50%' to '25-50%' to match the table and calibrate_grader.py code Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update README, CHANGELOG, and GETTING_STARTED for agent skills README.md: - Add quickstart + agent-assisted paths to Quick Start section - Update AI Agent Skills counts (12 scripts, 14 references, 6 workflows) CHANGELOG.md: - Add entries for PRs #24, #26, #28, #29, #30 - Restructure into versioned releases (1.0.0, 1.1.0, 2.0.0, Unreleased) GETTING_STARTED.md: - Add Option A (AI-Assisted) path before the manual demo path - Fix repo URL (Azure/fine-tuning -> microsoft-foundry/fine-tuning) - Renumber steps to accommodate new section Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update Skills/README.md: auto-discovery, new scripts, uv support, grader guidance - Quick Start: add auto-discovery path (symlinks), uv as recommended install - What This Skill Covers: add grader calibration, monitoring, cleanup, token cost - Directory Structure: add monitor_training, calibrate_grader, cleanup, quickstart, grader-design; update descriptions for accuracy - Guidance Highlights: add grader calibration, Python grader default, token cost Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * CHANGELOG: set Unreleased to v2.1.0 (2026-04-21) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix: SKILL.md missing DPO in submit description, remove unused requests dep from cleanup.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 134810c commit 3258c60

14 files changed

Lines changed: 927 additions & 48 deletions

CHANGELOG.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,48 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7-
## [Unreleased]
7+
## [2.1.0] - 2026-04-21
8+
9+
### Added
10+
- `monitor_training.py` — poll a running job until completion with real-time event streaming
11+
- `calibrate_grader.py` — calibrate RFT grader pass_threshold on base model outputs
12+
- `cleanup.py` — list and delete old files, deployments, and pending jobs to reclaim quota
13+
- `workflows/quickstart.md` — 6-step guide from zero to a deployed fine-tuned model
14+
- `references/grader-design.md` — comprehensive RFT grader design guide (type selection, partial credit, threshold calibration)
15+
- RFT-specific metrics section in `references/training-curve-analysis.md` (reward curves, token growth, parse errors, checkpoint selection)
16+
- LLM augmentation approach in `workflows/dataset-creation.md`
17+
- Agent discovery symlinks (`.github/skills/`, `.claude/skills/`, `.agents/skills/`) for auto-discovery by Copilot, Claude, and Codex
18+
- PEP 723 inline script metadata on all scripts for `uv run` support
19+
- `HelpOnErrorParser` for better CLI error messages across all scripts
20+
- `DefaultAzureCredential` fallback in `common.py` for keyless authentication
21+
- AI Agent Skills section in README with usage instructions for all supported agents
22+
23+
### Changed
24+
- Updated hyperparameter recommendations in `references/agentic-rft.md` (LR=1.0, compute_multiplier=1.5)
25+
- Restructured `workflows/dataset-creation.md` into three equal approaches (manual, LLM augmentation, synthetic generation)
26+
- Updated `references/evaluation-methodology.md` to include token cost alongside accuracy
27+
- Generalized experiment-specific numbers across all docs
28+
29+
### Fixed
30+
- `submit_training.py`, `deploy_model.py`: Added missing `requests` to PEP 723 dependencies
31+
- `submit_training.py`: Fixed file handle leak when reading grader files
32+
- `evaluate_model.py`: Fixed `StopIteration` crash on malformed test data
33+
- `validate/validate_rft.py`: Fixed broken newline escape detection logic
34+
- `convert_dataset.py`: Fixed DPO generation to include system messages for base model
35+
36+
## [2.0.0] - 2026-04-16
37+
38+
### Added
39+
- **Azure AI Fine-Tuning coding agent skill** (`Skills/`) — comprehensive agent skill for SFT, DPO, and RFT workflows on Azure AI Foundry
40+
- `SKILL.md` with full lifecycle guidance, platform gotchas, and rules
41+
- 8 reusable Python scripts (submit, check, deploy, evaluate, convert, generate, score, common)
42+
- Data validators for SFT, DPO, and RFT formats with cost estimates
43+
- 11 reference docs covering hyperparameters, dataset formats, deployment, evaluation, agentic RFT, reward hacking prevention, vision FT, cost management, and more
44+
- 5 guided workflows (full pipeline, dataset creation, iterative training, diagnosis, experiment review)
45+
- Sample data for SFT, DPO, and RFT formats
46+
- RFT best practice guidance (PR #24, contributed by Blanca Li)
47+
48+
## [1.1.0] - 2026-02-02
849

950
### Added
1051
- Enhanced main README with navigation table, quickstart section, and demo links
@@ -22,8 +63,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2263
### Fixed
2364
- Fixed placeholder URLs in CONTRIBUTING.md
2465

25-
---
26-
2766
## [1.0.0] - 2025-01-15
2867

2968
### Added

GETTING_STARTED.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,33 @@ Ensure you have these roles on your Azure AI Foundry project:
3333
## Step 1: Clone the Repository
3434

3535
```bash
36-
git clone https://github.com/Azure/fine-tuning.git
36+
git clone https://github.com/microsoft-foundry/fine-tuning.git
3737
cd fine-tuning
3838
```
3939

4040
---
4141

42-
## Step 2: Choose Your First Demo
42+
## Step 2: Choose Your Path
43+
44+
### Option A: AI-Assisted (Recommended)
45+
46+
If you have **GitHub Copilot**, **Claude Code**, or another coding agent:
47+
48+
1. Open this repo in your editor (VS Code, cursor, etc.)
49+
2. Ask your coding agent: *"Help me fine-tune a model on my data"*
50+
3. The agent auto-discovers the fine-tuning skill and guides you through:
51+
- Data preparation and validation
52+
- Job submission with correct parameters
53+
- Monitoring and training curve analysis
54+
- Deployment and evaluation
55+
56+
Or follow the step-by-step quickstart without an agent: **[Skills/workflows/quickstart.md](Skills/workflows/quickstart.md)**
57+
58+
### Option B: Follow a Demo Notebook
59+
60+
If you prefer to follow a notebook manually, continue below.
61+
62+
## Step 3: Choose Your First Demo
4363

4464
We recommend starting with **Supervised Fine-Tuning (SFT)** as it covers the most common use cases.
4565

@@ -53,7 +73,7 @@ We recommend starting with **Supervised Fine-Tuning (SFT)** as it covers the mos
5373

5474
---
5575

56-
## Step 3: Set Up the Demo Environment
76+
## Step 4: Set Up the Demo Environment
5777

5878
Navigate to your chosen demo folder:
5979

@@ -93,7 +113,7 @@ pip install -r requirements.txt
93113

94114
---
95115

96-
## Step 4: Run the Notebook
116+
## Step 5: Run the Notebook
97117

98118
1. Open the notebook in VS Code or Jupyter:
99119
```bash
@@ -110,7 +130,7 @@ pip install -r requirements.txt
110130

111131
---
112132

113-
## Step 5: Understand the Data Format
133+
## Step 6: Understand the Data Format
114134

115135
Each fine-tuning technique requires a specific data format. See the schema documentation:
116136

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ This repository contains **12 end-to-end demos** and **sample datasets** for fin
2020
1. **[SFT_CNN_DailyMail](Demos/SFT_CNN_DailyMail/)** - Best first demo! Learn Supervised Fine-Tuning with news summarization
2121
2. **[Sample_Datasets](Sample_Datasets/)** - Understand data formats for SFT, DPO, and RFT
2222

23+
**Want an AI coding assistant to guide you?**
24+
- Open this repo in VS Code with Copilot, or use Claude/Codex — the agent skill auto-discovers and walks you through the full workflow
25+
- Or follow **[Skills/workflows/quickstart.md](Skills/workflows/quickstart.md)** — fine-tune your first model in 6 steps (no demo notebook needed)
26+
2327
**Ready for advanced techniques?**
2428
- **[DPO_Intel_Orca](Demos/DPO_Intel_Orca/)** - Direct Preference Optimization
2529
- **[RFT_Countdown](Demos/RFT_Countdown/)** - Reinforcement Fine-Tuning
@@ -79,9 +83,9 @@ This repo includes a fine-tuning skill that coding agents can auto-discover and
7983

8084
All three paths are symlinks to the canonical skill at **[Skills/](Skills/)**, which includes:
8185
- **SKILL.md** — Agent instructions covering SFT, DPO, and RFT workflows
82-
- **8 scripts** — submit, monitor, deploy, evaluate, validate, score, convert, distill
83-
- **11 reference docs** — hyperparameters, dataset formats, agentic RFT, cost management, and more
84-
- **5 guided workflows** — full pipeline, dataset creation, iterative training, diagnosis
86+
- **12 scripts** — submit, monitor, calibrate, check, deploy, evaluate, validate, score, convert, generate, cleanup, and shared utilities
87+
- **14 reference docs** grader design, hyperparameters, dataset formats, agentic RFT, cost management, and more
88+
- **6 guided workflows**quickstart, full pipeline, dataset creation, iterative training, diagnosis, experiment review
8589
- **Sample data** — SFT, DPO, and RFT example JSONL files
8690

8791
### Using with GitHub Copilot (VS Code)

Skills/README.md

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,48 @@ A **skill** is a structured set of instructions, reference documentation, and re
1010

1111
| Stage | What the agent does |
1212
|-------|-------------------|
13-
| **Dataset creation** | Generate synthetic training data using Data Designer, or prepare existing data |
13+
| **Dataset creation** | Generate synthetic training data, curate examples, or augment with LLM rephrasings |
1414
| **Dataset validation** | Validate JSONL schema, token limits, and format for SFT / DPO / RFT |
1515
| **Base model evaluation** | Benchmark the un-tuned model to establish a baseline |
1616
| **Training type selection** | Choose between SFT, DPO, and RFT based on your task |
17+
| **Grader calibration** | For RFT: test your grader on base model outputs and find the optimal pass_threshold |
1718
| **Job submission** | Submit training jobs via SDK, REST API, or `azd` CLI |
18-
| **Training curve analysis** | Detect overfitting, recommend checkpoints |
19+
| **Job monitoring** | Poll running jobs with real-time event streaming |
20+
| **Training curve analysis** | Detect overfitting, monitor token growth, recommend checkpoints |
1921
| **Iterative experimentation** | Plan successive runs based on results |
2022
| **Model deployment** | Deploy fine-tuned models with the correct format and SKU |
21-
| **Model evaluation** | Score outputs with custom LLM judges |
23+
| **Model evaluation** | Score outputs with custom LLM judges, compare accuracy and token cost |
24+
| **Resource cleanup** | Delete old files and deployments to reclaim quota |
2225

2326
## Quick Start
2427

25-
### 1. Install the skill
28+
### 1. Set up the skill
2629

27-
**GitHub Copilot (VS Code / CLI):**
28-
Copy the `Skills/` directory into your project and reference `SKILL.md` in your Copilot instructions, or use it as a [Copilot custom instructions](https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions).
30+
**Auto-discovery (recommended):**
31+
If you cloned the [microsoft-foundry/fine-tuning](https://github.com/microsoft-foundry/fine-tuning) repo, coding agents auto-discover the skill via symlinks:
32+
- GitHub Copilot → `.github/skills/azure-ai-fine-tuning`
33+
- Claude Code → `.claude/skills/azure-ai-fine-tuning`
34+
- Codex / other agents → `.agents/skills/azure-ai-fine-tuning`
2935

30-
**Claude Code:**
31-
Add the skill directory to your project and reference `SKILL.md` in your `CLAUDE.md` or system prompt.
36+
Just open the repo and start asking questions — no manual setup needed.
3237

33-
**Any agent:**
34-
Point your agent at `SKILL.md` as a context file. It will discover the workflows, references, and scripts from there.
38+
**Manual setup:**
39+
Copy the `Skills/` directory into your project and reference `SKILL.md` in your agent's instructions file (`copilot-instructions.md`, `CLAUDE.md`, etc.).
3540

3641
### 2. Set up your environment
3742

43+
**Option A: `uv` (zero-setup, recommended):**
44+
All scripts have [PEP 723](https://peps.python.org/pep-0723/) inline dependency declarations. Just run them with `uv`:
3845
```bash
39-
cp Skills/.env.template Skills/.env
40-
# Edit .env with your Azure OpenAI endpoint, API key, and resource coordinates
46+
uv run Skills/scripts/submit_training.py --help
4147
```
4248

43-
Required Python packages:
49+
**Option B: Manual install:**
4450
```bash
45-
pip install openai azure-identity tiktoken requests
46-
```
51+
cp Skills/.env.template Skills/.env
52+
# Edit .env with your Azure AI Foundry endpoint and API key
4753

48-
Optional (for specific workflows):
49-
```bash
50-
pip install pandas pyarrow # Dataset conversion and statistics
51-
pip install azure-ai-evaluation azure-ai-projects # Azure AI Evaluation SDK integration
54+
pip install openai azure-identity requests
5255
```
5356

5457
### 3. Start fine-tuning
@@ -64,7 +67,7 @@ The agent will read the appropriate workflow and guide you step by step.
6467

6568
```
6669
Skills/
67-
├── SKILL.md # Main skill file (entry point)
70+
├── SKILL.md # Main skill file (agent entry point)
6871
├── .env.template # Environment variable template
6972
├── README.md # This file
7073
├── references/
@@ -73,7 +76,8 @@ Skills/
7376
│ ├── dataset-formats.md # JSONL format specs for each training type
7477
│ ├── deployment-formats.md # Model format, SKU, and version mapping
7578
│ ├── evaluation-methodology.md # Eval rubric design and grader types
76-
│ ├── training-curve-analysis.md # Reading training logs and curves
79+
│ ├── training-curve-analysis.md # Reading training logs and curves (SFT + RFT)
80+
│ ├── grader-design.md # RFT grader design (type selection, partial credit, calibration)
7781
│ ├── foundry-cli.md # azd ai finetuning CLI reference
7882
│ ├── vision-fine-tuning.md # Image/video fine-tuning (gpt-4o, gpt-4.1)
7983
│ ├── cost-management.md # Training costs and budget planning
@@ -82,20 +86,24 @@ Skills/
8286
│ ├── reward-hacking-prevention.md # Preventing reward hacking in RFT
8387
│ └── platform-bugs.md # Known platform bugs and workarounds
8488
├── workflows/
85-
│ ├── full-pipeline.md # End-to-end workflow (start here)
86-
│ ├── dataset-creation.md # Data generation with Data Designer
89+
│ ├── quickstart.md # 6-step quickstart (fine-tune your first model)
90+
│ ├── full-pipeline.md # End-to-end workflow
91+
│ ├── dataset-creation.md # Data generation (manual, LLM augmentation, synthetic)
8792
│ ├── iterative-training.md # Training and HP tuning loop
8893
│ ├── diagnose-poor-results.md # Troubleshooting bad results
8994
│ └── experiment-review.md # Post-experiment review and next steps
9095
├── scripts/
91-
│ ├── submit_training.py # Submit SFT/RFT jobs (SDK + REST fallback)
92-
│ ├── generate_distillation_data.py # Generate distillation training data
93-
│ ├── check_training.py # Training curve analysis
96+
│ ├── submit_training.py # Submit SFT/DPO/RFT jobs (SDK + REST fallback)
97+
│ ├── monitor_training.py # Poll a running job until completion
98+
│ ├── calibrate_grader.py # RFT grader threshold calibration
99+
│ ├── check_training.py # Training curve analysis and checkpoints
94100
│ ├── deploy_model.py # Deploy via ARM REST API
95101
│ ├── evaluate_model.py # LLM judge evaluation
96102
│ ├── convert_dataset.py # Format conversion (SFT↔DPO↔RFT)
103+
│ ├── generate_distillation_data.py # Generate distillation training data
97104
│ ├── score_dataset.py # Dataset quality scoring
98-
│ ├── common.py # Shared auth helpers
105+
│ ├── cleanup.py # Delete old files, deployments, pending jobs
106+
│ ├── common.py # Shared auth helpers + HelpOnErrorParser
99107
│ └── validate/
100108
│ ├── validate_sft.py # SFT JSONL validator
101109
│ ├── validate_dpo.py # DPO JSONL validator
@@ -137,8 +145,10 @@ Key patterns encoded in this skill:
137145

138146
- **Start with SFT distillation** — the most reliable fine-tuning pattern, achieving high teacher gap closure with 200–500 examples
139147
- **Always baseline first** — evaluate the base model before fine-tuning to confirm there's room for improvement
148+
- **Calibrate your RFT grader** — target 25-50% failure rate on the base model; recalibrate when you change your dataset
149+
- **Python grader as default for RFT** — fast, deterministic, and reliable; endpoint graders only when you need external API calls during grading
140150
- **DPO is risky when the base is already strong** — it can degrade quality if the model already handles the task well
141-
- **RFT is for verifiable tasks**math, code with test suites, structured output with exact-match graders
151+
- **Measure cost alongside accuracy**compare completion tokens per response, not just accuracy scores
142152
- **Quality over quantity** — 200–500 high-quality examples is a good starting point
143153

144154
## Contributing

Skills/SKILL.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $ARGUMENTS
2525

2626
Read the workflow file that matches the user's current stage:
2727

28+
- **First time / just want to get started**`workflows/quickstart.md`
2829
- **Starting from scratch**`workflows/full-pipeline.md`
2930
- **Need a dataset**`workflows/dataset-creation.md`
3031
- **Training and iterating**`workflows/iterative-training.md`
@@ -60,10 +61,13 @@ Reusable Python scripts in `scripts/`. Each is self-contained with inline docume
6061

6162
| Script | Purpose |
6263
|--------|---------|
63-
| `submit_training.py` | Submit SFT or RFT jobs (SDK + REST fallback) |
64+
| `submit_training.py` | Submit SFT, DPO, or RFT jobs (SDK + REST fallback) |
65+
| `monitor_training.py` | Poll a running job until completion, streaming events in real time |
66+
| `calibrate_grader.py` | Run base model through your RFT grader to find optimal pass_threshold |
6467
| `generate_distillation_data.py` | Generate training data from a teacher model for distillation |
6568
| `check_training.py` | Pull training curves, detect overfitting, list checkpoints |
6669
| `deploy_model.py` | Deploy fine-tuned models via ARM REST API |
70+
| `cleanup.py` | List and delete old deployments, files, and pending jobs to reclaim quota |
6771
| `evaluate_model.py` | Run held-out eval with 2-dimension LLM judge |
6872
| `convert_dataset.py` | Convert between SFT, DPO, and RFT JSONL formats |
6973
| `score_dataset.py` | LLM-judge quality scoring on training data |

Skills/references/grader-design.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ for threshold in [0.5, 0.6, 0.7, 0.8, 0.85, 0.9, 0.95]:
138138
print(f" @{threshold}: pass={pass_rate:.0%}, fail={fail_rate:.0%}")
139139
```
140140

141-
4. Choose the threshold where **30-50% of base model rollouts fail**
141+
4. Choose the threshold where **25-50% of base model rollouts fail**
142+
143+
Use `scripts/calibrate_grader.py` to automate this workflow:
144+
```bash
145+
python calibrate_grader.py --model o4-mini --data train.jsonl --grader grader.py --n 30
146+
```
142147

143148
| Failure Rate | Signal Quality |
144149
|-------------|----------------|

0 commit comments

Comments
 (0)