RFT - Amazon SageMaker AI
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

RFT

Reinforcement Fine-Tuning (RFT) uses reinforcement learning to optimize model behavior based on reward signals rather than explicit input-output examples. Amazon SageMaker AI supports two RFT variants: RLVR (Reinforcement Learning with Verifiable Rewards) and RLAIF (Reinforcement Learning from AI Feedback).

RLVR

RLVR uses a code-based reward function that programmatically verifies whether model outputs are correct. Best suited for tasks with objectively right or wrong answers.

When to use

  • Your task has verifiable correct answers (math, code, factual questions)

  • You can write a scoring function that evaluates response correctness

  • You want to improve factual accuracy and reduce hallucinations

Dataset format

Each record contains a prompt and reward model metadata. The reward function evaluates model-generated responses during training.

{ "data_source": "openai/gsm8k", "prompt": [ { "content": "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May? Let's think step by step and output the final answer after \"####\".", "role": "user" } ], "ability": "math", "reward_model": { "ground_truth": "72", "style": "rule" } }

Required fields:

  • prompt — array of message objects with role and content

  • reward_model.style — set to "rule" for programmatic verification

  • reward_model.ground_truth — the correct answer for verification

To implement your own Lambda-based reward function, see RLVR - Custom Lambda. For the supported Lambda response envelopes, see Sample Lambda Output Payload.

Note

If your Lambda reward function returns a malformed payload, RLVR jobs can fail with InvalidLambdaResponseException. Return exactly one of the supported response envelopes described in Sample Lambda Output Payload and make sure each result includes a matching id.

Preset reward functions

  • gsm8k — Grade school math verification

  • prime_code — Code correctness verification

  • prime_math — Mathematical reasoning verification

Python SDK example

Use RLVRTrainer for serverless RLVR customization jobs:

from sagemaker.train import RLVRTrainer trainer = RLVRTrainer( model_id="meta-textgeneration-llama-3-1-8b-instruct", train_data="s3://my-bucket/rlvr-train.jsonl", hyperparameters={ "preset_reward_function": "gsm8k", "learning_rate": 1e-5, "max_epochs": 1, "global_batch_size": 128, "lora_rank": 16, }, ) trainer.train()

To run RLVR with FFT, use the same dataset format and remove LoRA-specific hyperparameters such as lora_rank and lora_alpha.

RLVR LoRA hyperparameters

Note

The tables below show the hyperparameters available when you use serverless model customization. Other hyperparameters are preset by Amazon SageMaker AI using optimized defaults. When you use SageMaker AI Training Jobs or HyperPod, you can access the full list of hyperparameters available in the recipes. See the SageMaker AI Recipes repository to get a recipe and access all hyperparameters.

Parameter Type Required? Range / Values Description
preset_reward_functionstringRequiredgsm8k, prime_code, prime_mathPreset reward function for verification.
learning_ratefloatRequired1e-07–1e-03Step size for weight updates. Set lower for RL (e.g., 1e-5).
lr_warmup_steps_ratiofloatRequired0–1Fraction of steps for LR warmup.
max_epochsintegerRequired1–100Number of passes through the dataset.
global_batch_sizeintegerRequired128, 256, 512, 1024Total samples per optimizer step.
max_prompt_lengthintegerRequired512–16384Maximum tokens for prompt portion.
weight_decayfloatRequired0.0–1.0L2 regularization coefficient.
clip_ratiofloatRequired0.1–1.5GRPO clipping parameter. Limits policy change per update.
kl_loss_coeffloatRequired0–0.1KL divergence penalty weight. Prevents policy drift.
rollout_nintegerRequired1, 2, 4, 8, 16, 32Candidate responses per prompt during rollouts.
rollout_temperaturefloatRequired0.01–2.0Temperature for rollout generation.
lora_rankintegerRequired8, 16, 32, 64, 128LoRA rank. Dimensionality of low-rank matrices.
lora_alphaintegerRequired16, 32, 64, 128, 256LoRA scaling factor. Effective LR scales as alpha/rank.
warmup_stepsintegerRequired-1–100Absolute warmup steps (-1 for auto).
min_lrfloatRequired0.0–1.0Minimum learning rate floor.
clip_ratio_highfloatRequired0.0–0.5Upper clipping threshold.
clip_ratio_lowfloatRequired0.0–0.5Lower clipping threshold.
temperaturefloatRequired0.0–2.0Sampling temperature for evaluation.
use_kl_lossbooleanRequiredtrue, falseAdd KL divergence penalty to loss.
train_val_split_ratiofloatOptional0.0–1.0Train/validation split.

RLVR FFT hyperparameters

Same parameters as RLVR LoRA without lora_rank and lora_alpha.

RLAIF

RLAIF uses another LLM as a judge to evaluate model responses based on a natural language reward prompt. Best suited for tasks with subjective quality criteria that are difficult to evaluate programmatically.

When to use

  • Your quality criteria are subjective (helpfulness, safety, tone)

  • You can describe what "good" looks like in natural language

  • You want to scale feedback beyond what human annotation can provide

Dataset format

Each record contains a prompt and reward model metadata. The LLM judge evaluates model-generated responses during training.

{ "data_source": "WeOpenML/PandaLM", "prompt": [ { "role": "user", "content": "Below are two responses for a given task...Evaluate the responses and generate a reference answer.\n\n### Instruction:\nCompare the given products..." } ], "ability": "pairwise-judging", "reward_model": { "style": "llmj", "ground_truth": "2\n\n### Reason: Response 2 provides a more detailed comparison..." } }

Required fields:

  • prompt — array of message objects with role and content

  • reward_model.style — set to "llmj" for LLM-as-judge

  • reward_model.ground_truth — reference judgment for calibration

Judge templates

The following preset judge templates are provided in the training container. Set judge_prompt_template to one of these values:

Value Container path Use case Example
cot.jinja /opt/ml/code/verl/cot.jinja Chain-of-thought judging RLAIF - Chain of Thought
evaluate.jinja /opt/ml/code/verl/evaluate.jinja General response comparison and scoring Reinforcement Learning from AI Feedback (RLAIF) - Pair-Wise Judging
faithfulness.jinja /opt/ml/code/verl/faithfulness.jinja Groundedness and source faithfulness RLAIF - Faithfulness
summarize.jinja /opt/ml/code/verl/summarize.jinja Summarization quality RLAIF - Summarization

To replace a preset template with your own Jinja prompt, see RLAIF - Custom Prompt.

Python SDK example

Use RLAIFTrainer for serverless RLAIF customization jobs:

from sagemaker.train import RLAIFTrainer trainer = RLAIFTrainer( model_id="meta-textgeneration-llama-3-1-8b-instruct", train_data="s3://my-bucket/rlaif-train.jsonl", hyperparameters={ "judge_prompt_template": "evaluate.jinja", "learning_rate": 1e-5, "max_epochs": 1, "global_batch_size": 128, "lora_rank": 16, }, ) trainer.train()

To run RLAIF with FFT, use the same dataset format and remove LoRA-specific hyperparameters such as lora_rank and lora_alpha.

RLAIF LoRA hyperparameters

Same parameters as RLVR LoRA with the following difference:

ParameterTypeRequired?Range / ValuesDescription
judge_prompt_templatestringOptionalcot.jinja, evaluate.jinja, faithfulness.jinja, summarize.jinjaTemplate for LLM judge evaluation. Replaces preset_reward_function. For the corresponding container paths and example prompts, see Judge templates.

RLAIF FFT hyperparameters

Same parameters as RLAIF LoRA without lora_rank and lora_alpha.