All Products
Search
Document Center

Platform For AI:Reinforcement learning practice for single-turn mathematical reasoning with GRPO

Last Updated:Nov 20, 2026

This tutorial trains a model for single-turn mathematical reasoning with GRPO on the GSM8K dataset in PAI-RLS. You can submit a job from the built-in job template and then verify that the training works layer by layer from the training overview, performance metrics, and trajectory inspection.

Background and objectives

Reinforcement learning (RL) differs from the usual supervised fine-tuning (SFT). SFT makes a model imitate a reference answer token by token. RL lets the model generate its own solutions, score the results (rewards), and then update parameters toward higher reward. The core idea is not to learn from the answer, but to learn from the outcome. As long as you can signal that a correct solution is good, the model can amplify that signal into a stronger capability on its own.

Mathematical reasoning is a natural fit for this mechanism. A math problem has a clear, automatically verifiable right or wrong answer. By checking the model's final answer against the reference answer, you can obtain a reward directly, without human labeling or interaction with an external environment. Therefore, you can use a correct solution as the reward signal and let the model learn more reliable derivations through repeated generate, verify, and update cycles, reducing hallucinations in intermediate steps instead of memorizing reference solutions.

After one round of training, the expected result is that the base model's pass@1 accuracy on GSM8K improves, and the reasoning chain becomes more stable and focused on effective derivation. This tutorial shows the complete process of running one round of single-turn mathematical reasoning RL training with the GRPO algorithm in PAI-RLS, and then uses the training output to select a suitable checkpoint for evaluation, closing the loop of training and evaluation.

Prerequisites

Before you begin, make sure that the following preparations are complete:

  • Alibaba Cloud PAI is activated, and an available resource quota is bound in PAI-RLS. The quota must be a subscription quota that supports Lingjun intelligent computing or general computing.

  • The base model for training is selected, and GPU specifications that can be allocated are available.

This scenario uses single-turn generation, and the reward comes from verifiable checks of the answer. The training process does not interact with an external sandbox environment. Therefore, you do not need to configure a sandbox service, an EAS service, or a custom image.

H20, H200, L20X, PPU, and other GPU types are supported, and the model version provides the corresponding adapter specification labels. When you submit a job, select a specification with an adapter label.

image.png

Dataset

This tutorial uses the public mathematical reasoning dataset GSM8K. When you create a job, set the dataset source to Public Dataset and specify GSM8K. You do not need to upload the dataset.

GSM8K consists of elementary school math word problems. Each sample mainly contains the question text and a verifiable reference answer. The following is a typical sample:

question: 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?
answer:   Natalia sold 48/2 = 24 clips in May.
          Natalia sold 48+24 = 72 clips altogether in April and May. #### 72
        

The question field is the problem text, which the platform passes to the model as the prompt. The answer field is the reference solution with its reasoning process. The number after #### at the end (72 in this example) is the final answer. The platform uses it to determine whether the model's answer is correct and assigns a reward or evaluation score accordingly.

GSM8K contains both a training set and an evaluation set. This tutorial uses the training set for RL training and the evaluation set for scoring.

Create a training job

In RLS, choose Create Training Job. The platform provides the GRPO single-turn math RL job template. Apply the template to submit the job with one click. The sampling, training, and resource values use the template defaults, so you do not need to fill them in one by one.

Create a job from a template:

image.png

Adjust parameters:

image.png

Basic information

Enter a name and description for the job so that you can distinguish and find it in the job list.

Sampling configuration (Rollout)

Controls how answers are generated and how many answers are generated. This is the core of RL sampling.

Parameter

Description

Samples per Prompt

Number of responses sampled for each prompt. GRPO computes advantages by comparing multiple responses in the same group.

Sampling Temperature

Sampling temperature. Higher values produce more diverse responses; lower values produce more deterministic responses.

Top-p Sampling

Nucleus sampling threshold, which controls the range of candidate tokens.

Max Prompt Length (Tokens)

Maximum allowed length of the input prompt.

Max Response Length (Tokens)

Maximum length of a single generated response.

Max Assistant Turns

Maximum number of turns that the model can take in a single trajectory. Set this to 1 for single-turn math scenarios.

Max Length per Turn (Tokens)

Maximum number of tokens that can be generated in each turn.

Rollout Timeout (s)

Timeout for sampling a single trajectory. If the timeout is reached, the trajectory is marked as failed.

Agent Task Timeout (s)

Timeout for sampling client requests.

Agent Task Retries

Number of retries after a trajectory sampling failure.

Tensor Parallel Size

Tensor parallelism during sampling (inference). This affects per-GPU memory usage and throughput.

Training configuration (Train)

Controls which model is used and how parameters are updated.

Parameter

Description

Base Model

Starting model for RL post-training.

Training Mode

Full parameter fine-tuning (Full Tuning).

Algorithm Type

RL algorithm. This tutorial uses GRPO (group-relative advantage, no critic).

Training Batch Size (Prompts)

Batch size of samples used in each training step.

Actor Learning Rate

Learning rate of the actor (policy model). This controls the magnitude of parameter updates.

Pos/Neg Clip Range

Clip range for samples with positive and negative advantages. This constrains the deviation of policy updates and keeps training stable.

Total Training Steps

Total number of training steps.

Max Gradient Norm

Gradient clipping threshold that prevents exploding gradients.

Shuffle Training Data

Whether to shuffle the training data in each epoch.

Checkpoint Save Frequency

How often (in training steps) a model checkpoint is saved. The template saves a checkpoint every 20 steps by default.

Resource and scheduling configuration

Controls which resources are used and how they are scheduled.

Parameter

Description

Scheduling Mode

Execution orchestration for sampling and training. This tutorial uses synchronous mode, in which sampling and training alternate.

Sampling (Inference) Resources

Resource specifications used in the Rollout generation phase.

Training Resources

Resources used in the Train update phase, including the resource quota, number of nodes, and GPU, CPU, and memory per node.

After you complete the configuration, click Submit. The job enters the Running state. For complete parameters and configuration details, see Create a training job.

Monitor the training process

After you submit the job, you are redirected to the job details page. Training observation follows a top-down approach from the macro level to the micro level. First, check the overall health in the training overview. Then, use performance metrics to determine whether the model is improving and to select a suitable checkpoint. If a specific sample has a problem, drill down to trajectory inspection. Finally, use job logs to locate details.

Training overview

image.png

image.png

image.png

This page provides a global view of the training job. Focus on three types of information: the running progress and health of each module (Rollout sampling and Train); key resource metrics, such as GPU utilization, memory usage, and training and sampling throughput; and an overview of performance metrics, such as average reward, answer accuracy, KL divergence, and entropy.

Performance metrics

This page is key to determining whether training is effective and to selecting a checkpoint. Focus on how several curves change with training steps: whether the average reward converges and rises steadily, whether answer accuracy gradually improves, and whether KL divergence and entropy remain in a stable range. If the reward does not increase, or if the curves oscillate or collapse sharply, the learning rate or the clip range usually needs adjustment.

Training outputs are saved at the checkpoint save frequency (every 20 steps by default in the template). You can use these checkpoints to select one for subsequent evaluation.

Trajectory inspection

Rollout trajectories are generated by the model in real time at each step. They reflect the current capability of the model and are an important entry point for troubleshooting. In multi-turn or agent scenarios, the multiple turns in one sampling run accumulate deviation turn by turn, so inspecting trajectories is especially important.

At the training step level, you can view the overall output and progress of the trajectories in a single training step. At the sample level, you can view the flow distribution of a group of trajectories (P50/P90/P99 slow samples, which help identify slow or abnormal trajectories). At the trajectory level, you can reconstruct the action, returned result, and final reward of each step in a single trajectory.

image.png

image.png

image.png

Job logs

When you need to troubleshoot a specific error or performance detail, view the job logs to obtain the raw runtime output and locate issues such as sampling timeouts, out-of-memory (OOM) errors, and grading exceptions.

image.png

Conclusion

This tutorial demonstrated the complete process of single-turn mathematical reasoning RL with GRPO on PAI-RLS. It uses a dataset such as GSM8K, which has verifiable answers, treats correct solutions as the reward signal, and applies a job template to complete training. It then observes the training layer by layer in the job details page, from the overview to performance metrics and trajectories, evaluates the training result based on performance metrics, and selects a checkpoint as needed. Finally, it evaluates the selected checkpoint to obtain an independent final score. The entire process requires no external environment setup and no manual reward labeling, which is the typical value of RL in verifiable scenarios such as mathematics.