R e FT : Reasoning with Reinforced Fine-Tuning (2024)

Abstract: One way to enhance the reasoning capability of Large Language Models (LLMs) is to conduct Supervised Fine-Tuning (SFT) using Chain-of-Thought (CoT) annotations. This approach does not show sufficiently strong generalization ability, however, because the training only relies on the given CoT data. In math problem-solving, for example, there is usually only one annotated reasoning path for each question in the training data. Intuitively, it would be better for the algorithm to learn from multiple annotated reasoning paths given a question. To address this issue, we propose a simple yet effective approach called Reinforced Fine-Tuning (ReFT) to enhance the generalizability of learning LLMs for reasoning, with math problem-solving as an example. ReFT first warmups the model with SFT, and then employs on-line reinforcement learning, specifically the PPO algorithm in this paper, to further fine-tune the model, where an abundance of reasoning paths are automatically sampled given the question and the rewards are naturally derived from the ground-truth answers. Extensive experiments on GSM8K, MathQA, and SVAMP datasets show that ReFT significantly outperforms SFT, and the performance can be potentially further boosted by combining inference-time strategies such as majority voting and re-ranking. Note that ReFT obtains the improvement by learning from the same training questions as SFT, without relying on extra or augmented training questions. This indicates a superior generalization ability for ReFT.

## introduction the state-of-the-art approaches to solving math problems @xcite employ supervised fine-tuning (sft) to train the models using chain-of-thought (cot) annotations @xcite . as shown in figure 1 , a chain-of-thought (e): we need to calculate her hourly rate and then multiply it by the amount of time she worked. first, we need to convert 50 minutes to hours. there are 60 minutes in an hour, so 50 minutes is equal to 50/60 = 5/6 hours. next, we can calculate weng's earnings by multiplying her hourly rate by the amount of time she worked: @xmath010. therefore, weng earned $10 for 50 minutes of babysitting. the answer is 10. cot annotation outlines the intermediate reasoning steps toward solving a math problem. usually there is one cot annotation for each question in the training data, i.e., one correct reasoning path, which is utilized in sft. we observe that this may result in relatively weak generalization abilities of the sft models. it is often the case that multiple valid cot annotations exist for the same question @xcite , underscoring the need for a more powerful fine-tuning approach. to address this problem, we propose a simple yet effective approach called reinforced fine-tuning (reft) (figure 1 bottom). reft commences with a warm-up stage involving supervised fine-tuning (sft) in one or two epochs (figure 1 , shaded box). this initial stage equips the model with the ability to generate correct responses to mathematical problems to some extent, as demonstrated in prior work @xcite . next, reft proceeds to further refine the model through the utilization of an online reinforcement learning (rl) algorithm (sutton and barto, 2018), specifically proximal policy optimization (ppo) @xcite in this paper. in this way, reft is able to sample multiple correct reasoning paths or cot annotations and learn from them (figure 2 , right). since the training data include ground-truth answers, the golden rewards can be naturally derived from them when training ppo. consequently, there is no requirement for a separately trained reward model. in contrast, rlhf @xcite has to utilize a reward model that is learned from human-labeled data. during the warm-up stage, reft acquires a certain level of accuracy by supervised learning. in the rl stage, reft further enhances its ability by reinforcement learning through sampling various cot reasoning paths. in this way, reft gets much richer supervision signals than sft. this approach enables reft to greatly improve generalization in math problem-solving @xcite . note that reft outperforms sft by using the same training questions, without relying on extra or augmented training questions. in fact, reft does not conflict with such data engineering and can be seamlessly combined with it. our contributions are as follows: reft exhibits enhanced generalization capabilities compared to conventional supervised fine-tuning when trained on the same dataset. ## method in this work, we focus on natural language cot (n-cot) @xcite (figure 1 ) and programbased cot @xcite (p-cot) using python. @xcite proposed the programbased cot for math problem solving. we can simply execute the program to obtain the answer. to ensure clarity and avoid ambiguity, we use the terms n-cot and p-cot to represent natural language and program-based cots, respectively. ## analysis generalization figure 4 shows the mean reward, evaluation accuracy, and the kl divergence during training of reft foot_4 on gsm8k p-cot using codellama as foundation model. sft converges and becomes overfiting when approaching 40 th epoch. however, we can see the mean reward is around 80% to 90% for the reft policy at 40 th epoch, and the value accuracy is also increasing. in addition, we can see that the kl divergence (figure 4 (c) ) is very large in the beginning and then maintains a reasonable value between 0 and 10. the stable kl divergence indicates our policy performs exploration within a space that contains appropriate programs. the underlying reinforcement learning mechanism greatly improves the generalization ability of @xcite . ## conclusion we have introduced reinforced fine-tuning (reft) as a new method for fine-tuning models to solve math problems. in contrast to sft, reft optimizes a non-differentiable objective by exploring multiple cot annotations in the search for the correct answer, rather than relying on a single annotation. 14 we only show 60 epochs for illustration purposes. the performance for the later epoch is shown in figure 4 through extensive experimentation on three datasets using two foundation models, we have demonstrated that reft outperforms sft in terms of performance and generalization ability. moreover, we have showcased the compatibility of models trained with reft with techniques such as majority voting @xcite and reward model reranking @xcite . furthermore, reft has exhibited superior performance compared to several publicly available open-source models of comparable sizes in math problem-solving. this demonstrates the effectiveness and practical value of the reft approach.