The fine-tuning service automatically pauses RFT jobs once they hit $5,000 in total training costs (training + grading). You can deploy the most recent checkpoint or resume the training job. If you decide to resume the job, billing continues for the job with no further cost-based limits.
Model support
Reinforcement fine-tuning is supported for the following models:
* GPT-5 support for reinforcement fine-tuning is generally available, but access is gated and available by invitation only. Contact your Microsoft account team if you’re interested in enrollment.
Requirements
Reinforcement fine-tuning (RFT) requires training and validation data formatted as JSONL and containing amessages array that uses the chat completions format.
However, RFT has more requirements:
- Data
- Assign the final “message” in the data a
userrole. - Include extra fields and values for use by a grader.
- Provide both a training and a validation dataset.
- Assign the final “message” in the data a
- Graders
- Define a grader to score the quality of your fine-tuned model and guide learning.
- Provide only a single grader, but you can combine multiple graders by using a multigrader.
Example training data
The following example shows how to present prompts to the model and include ground truth that a grader can access.This example is split across multiple lines for demonstration purposes only. It must be a single line in your JSONL file.
Graders
Graders provide the reward function used during training and have access to any user-supplied fields in the dataset. Multiple types of graders are available:- text comparison: score response content based on its text
- model: score responses using a language model and prompt
- custom code: score responses using custom code
- multigrader: score based on a combination of scores from other graders
{{ }}) containing a reference to a variable.
Each template reference must be namespaced using a pattern like {{ namespace.variable }}. For any complex, nested data, a JSON-path like syntax is supported.
The following namespaces are supported:
sample- model output to be graded appears under thesamplenamespace in a format similar to a chat completions response.item- optional, extra fields provided in training data appear under theitemnamespace.
{{ sample.output_text }}- substitute the model output as a string{{ sample.output_json }}- if the model produced structured outputs, reference it as JSON{{ item.answer }}- substitute the “answer” field in the dataset{{ item.ground_truth.date }}- substitute the “date” field of a “ground_truth” object defined in the dataset
Text comparison graders
Use text comparison graders when the use case requires the model output to be either a definitive label or if the output must resemble a known ground truth answer.String-check-grader
String-check graders apply a given operation to the input and a reference to return a0 or 1, providing a simple pass/fail function.
Text similarity
Text-similarity graders compute a score based on a select algorithm for quantifying similarity between the input text and a given reference text. Specification:fuzzy_match– fuzzy string match, using the RapidFuzz algorithmbleu– computes BLEU (bilingual evaluation understudy) score between stringsgleu– computes Google BLEU score between stringsmeteor– computes METEOR score between stringsrouge-*- as defined by the rouge python library
Model graders
Model graders take a prompt to a grader model that instructs it how to evaluate and score a given response. This flexibility allows for prompt engineering complex graders that support explaining the reason for a given score. Use the following models as model graders:Model graders don’t require model deployments in Foundry.
Score model
Score model graders output a numeric score based on their given input and prompt. Any providedsampling_params control the behavior of the scoring model and allow for customizing things like temperature and reasoning effort.
Code graders
Model graders are flexible but nondeterministic. When you need deterministic scoring, use code graders instead.Python grader
The Python grader executes arbitrary Python code to produce a score. The provided code must define agrade function that takes two positional arguments: sample and item. The function must return a numeric score.
Within the Python runtime, the provided code can use the following modules and versions:
- numpy==2.2.4
- scipy==1.15.2
- sympy==1.13.3
- pandas==2.2.3
- rapidfuzz==3.10.1
- scikit-learn==1.6.1
- rouge-score==0.1.2
- deepdiff==8.4.2
- jsonschema==4.23.0
- pydantic==2.10.6
- pyyaml==6.0.2
- nltk==3.9.1
- sqlparse==0.5.3
- rdkit==2024.9.6
- scikit-bio==0.6.3
- ast-grep-py==0.36.2
Endpoint grader (preview)
Endpoint graders call a remote endpoint through an HTTP API to score the model response. They’re perfect for use cases that require access to ground truth for accurate scoring or the ability to implement the grader in a language other than Python.While in private preview, the API for endpoint graders isn’t published.
Multigrader
A multigrader combines the output of multiple graders to produce a single score based on an arithmetic expression provided incalculate_output.
calculate_output expression references the individual scores from the provided graders by the key in the graders object.
Operators:
Functions:
As an example, a multigrader defined with two graders, “similarity-score” and “label-checker,” that must average their outputs could look like:
Response format (optional)
During training, you can configure the model to produce structured outputs. This structure can align with the intended use case of the model or make grading the output easier. The response format configuration follows the same specification as Chat Completions, either supporting text (the default) or JSON. When the model should output JSON, you must provide a JSON Schema. To continue with the previous example, if the model must output the response in a structured format such as:Hyperparameter selection
Reinforcement fine-tuning supports the same hyperparameters as supervised fine-tuning. Additionally, the following hyperparameters control features specific to RFT:The training service automatically replaces hyperparameters set to
auto with defaults based on heuristics on the provided training data.Interpreting training results
Reinforcement fine-tuning provides both automatic evaluations of the model during training and real-time training metrics.Training metrics
When you monitor a running job or inspect a completed job, thereward and reasoning metrics provide an indicator of training success.
Reward
Reward metrics track the resulting scores from the grader acting as the reward function.train_reward_mean: the average reward across the batch of training data at a given step. Because each batch might be different across steps, the trend of this metric is more important than comparing values across steps.valid_reward_mean: the average reward across the samples taken from the validation set at a given step.
Reasoning tokens
Each training job tracks the number of reasoning tokens produced by the model. Reasoning token metrics capture how the model changes its behavior over the lifetime of the training job.train_reasoning_tokens_mean: the average number of reasoning tokens produced across the batch of training data at a given step.valid_reasoning_tokens_mean: the average number of reasoning tokens produced across the validation data at a given step.
Automatic evaluations
The system automatically creates an evaluation for each RFT job. At regular intervals defined by theeval_interval hyperparameter, the training system executes an evaluation run by using the validation data. You can view scores for each run through the linked evaluation, which you can discover from the Foundry user interface.
Inspecting these evaluations provides an extra data point for deciding on early stopping. If the model exhibits learning during training, the results of each evaluation run should improve over the lifetime of the job.
Example projects and datasets
The following example demos and datasets provide starting points for new users of reinforcement fine-tuning:- Countdown Demo - end-to-end demo of using RFT to improve mathematical reasoning.
- MedMCQ - sample dataset and graders for answering multiple-choice questions from the medical domain.
- ClauseMatching - sample dataset and graders showcasing both summarization and content interpretation in the legal domain.