Unified supervision fine-tuning and reinforcement learning training method based on dynamic weight fusion
By employing a unified supervised fine-tuning and reinforcement learning method with dynamic weight fusion in the training of large language models, the hard switching and overfitting problems in the SFT and RL stages are solved, thereby improving the stability and consistency of the training process and enhancing the model's generative capabilities.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 青岛蚂蚁机器人有限责任公司
- Filing Date
- 2025-09-03
- Publication Date
- 2026-06-23
Smart Images

Figure CN121145972B_ABST
Abstract
Description
Technical Field
[0001] This application proposes a method for optimizing the training of large language models (LMMs).
[0002] The method, specifically, unifies Supervised Fine-Tuning (SFT) and Reinforcement Learning (RL) within the same training framework, and belongs to the field of artificial intelligence. Background Technology
[0003] As AI technology is increasingly applied to various innovative fields both domestically and internationally, numerous training and optimization methods for large language models are emerging.
[0004] Currently, large language model training commonly employs a two-stage "SFT-then-RL" approach, which has become a mainstream training method recognized and practiced by teams in both industry and academia. Implementation methods include...
[0005] Phase 1: Supervised Fine-Tuning (SFT): This involves collecting high-quality expert data, typically containing thousands to millions of (Prompt, Response) pairs, where the Prompt represents user input and the Response represents the standard answer written by the expert. By mimicking the expert data (Prompt-Response pairs), the model learns to imitate the expert's output style, knowledge representation, and reasoning ability, thus establishing basic task capabilities.
[0006] The second stage: Reinforcement Learning (RL): In the reinforcement learning stage, the large model is guided by reward signals to generate answers that are more in line with human preferences, optimize its generation strategy, and improve the usefulness, harmlessness and authenticity of the answers.
[0007] Although the "SFT-then-RL" paradigm has been widely adopted, it still suffers from the following technical drawbacks: 1) Hard switching problem: There is a sudden change in the objective function between the SFT and RL stages, switching directly from minimizing the negative log-likelihood of the response data to policy gradient optimization. This forces the model to readjust to the new optimization objective in the RL stage, causing performance fluctuations; 2) Overfitting risk: The RL stage may overfit the reward signal, ignoring the general knowledge learned in the SFT stage; 3) Training instability: The objectives of SFT and RL conflict, leading to an imbalance between imitation and exploration in the model. That is, SFT encourages imitation of expert behavior, while RL encourages exploration of new policies.
[0008] In view of the above, this patent application is hereby filed. Summary of the Invention
[0009] This application aims to address the problems existing in the prior art by proposing a unified monitoring method based on dynamic weight fusion.
[0010] The supervised fine-tuning and reinforcement learning training method is based on unified SFT and RL training objectives to balance knowledge imitation and strategy exploration, thereby improving training stability.
[0011] To achieve the above design objectives, the unified supervised fine-tuning and reinforcement learning training method based on dynamic weight fusion is based on a dual-path parallel architecture of SFT and RL, and implements the unified integration and smooth transition of supervised fine-tuning and reinforcement learning through a dynamic weight fusion mechanism.
[0012] The implementation steps include the following:
[0013] Step (1), Data preparation;
[0014] This includes SFT data preparation and RL data preparation, each involving sampling several question-answer pairs from the dataset;
[0015] Step (2): Parallel processing along two paths;
[0016] Step (2.1), SFT path;
[0017] The process includes inputting data to process SFT data. The process involves inputting the SFT data into a pre-trained large language model and calculating the SFT loss of the model's generated response based on minimizing the negative log-likelihood of the response data.
[0018] The expression for calculating SFT_loss is as follows:
[0019]
[0020] Among them, the weighting function It is based on the model's current confidence level in the token. ; The parameter is Large language models For conditional probability, given the cue word x and all previous real tokens, the large language model predicts the probability of the next real token to dynamically adjust the weight of the loss for each token; its purpose is to adjust the weight of the loss for tokens that the model is already confident about. Close to 0 or 1, A small value means it's okay if it doesn't learn, preventing model overfitting; for tokens with uncertain models, Close to 0.5 A large value means that the model should focus on learning it; The parameter is Large language models Let be the conditional probability, given the cue x and all previous real tokens, the probability that the large language model predicts the next real token; log is the natural logarithm of the probability. For each token position t in the standard answer of a data set, calculate its log probability, and then sum them to obtain the total loss of the data set; To perform the above operation on each data i in a batch and sum up the losses, we obtain the total loss of a batch, where B is the number of batches; "-" is a negative sign, representing minimizing the loss function; This represents a normalization operation, which divides the total loss of the batch by the total number of tokens for all standard answers in the batch.
[0021] Step (2.2) RL path;
[0022] The process includes inputting data to process RL data. The processing flow is as follows: for each input prompt, the large language model generates a total of K candidate responses; each candidate response is evaluated using rule-based rewards to calculate a reward value; and reinforcement learning loss is calculated based on the GRPO algorithm.
[0023] The reinforcement learning loss is calculated using the following formula:
[0024]
[0025] Where B represents the quantity indicated in a batch; The advantage of each candidate response is calculated using the following expression: , The original reward obtained for a candidate response. , The mean and standard deviation of the group rewards. It is a small constant added to ensure numerical stability; token-level importance sampling ratio. This is used to compare the preference of the new strategy and the old strategy for generating the next token; given the prompt word x and the historical tokens that have already been generated. Under the given conditions, the old strategy generates the next token. The probability is The clip mechanism restricts the importance sampling rate to a reliable region near the old strategy, i.e. Inside, among them, It is a hyperparameter representing the maximum allowable change in a single update; min is the minimum value of the regular reward and the clip reward. Used for summation and normalization operations, it represents averaging the data in the entire batch, where B is the number of prompts in a batch, K is the number of responses generated for each prompt, and t is the number of tokens in each response;
[0026] Step (3), dynamic weight fusion mechanism;
[0027] By dynamically adjusting the loss weights of the SFT and RL paths using global coefficients μ, a gradual transition from imitation learning to exploratory learning can be achieved.
[0028] In step (2.2), the input data only contains the data of the question, and the standard answer is only used to calculate the rule-based reward.
[0029] The reward value in step (2.2) is evaluated based on the following rules:
[0030] A positive reward of 1.1 will be given for demonstrating the thought process and providing a correct answer;
[0031] For answers that only provide the correct answer without any thought process, a positive reward of 0.1 will be given.
[0032] A neutral reward of 0.0 will be given for answers that include a thought process but are incorrect.
[0033] Those who neither demonstrate a thought process nor provide an correct answer will be penalized with -1.
[0034] Step (3) includes the following steps:
[0035] Step (3.1), calculation of dynamic weight fusion loss;
[0036] The total loss calculation formula is as follows:
[0037]
[0038] in, These are global coefficients in the training framework, used to guide the model's transition from supervised learning to reinforcement learning at a macro level; To enhance the learning loss function, The loss function for supervised learning;
[0039] Step (3.2): Execute the dynamic decay strategy for μ value;
[0040] The μ value gradually decreases from a high value of 0.5 to 1 during training to a low value of 0.5 to 0, thus shifting the training focus from imitation learning to exploratory learning.
[0041] In summary, the unified supervised fine-tuning and reinforcement learning training method based on dynamic weight fusion proposed in this application has the following advantages:
[0042] The advantages and beneficial effects are as follows:
[0043] 1. This application unifies the training paradigm by integrating SFT and RL into a unified training framework, thus solving the hard switching problem in the prior art. Specifically, it adopts smooth transition training to eliminate the hard switching between the SFT and RL stages through dynamic decay of the μ value, thereby achieving a natural transition from imitation learning to exploratory learning.
[0044] 2. This application adopts a fine-grained weight control method and introduces a dynamic token-wise weighting function to finely control the influence of SFT data at the token level, thereby achieving the focus of learning "uncertain tokens".
[0045] 3. This application adopts a balanced approach of imitation learning and exploratory learning. In the early stage, the μ value is increased to imitate expert knowledge learning, and in the later stage, the μ value is decreased to enhance exploratory ability, thereby avoiding the risk of overfitting rewards.
[0046] 4. This application significantly improves training stability. The unified training framework can reduce target conflicts, and the token-wise weighting mechanism further suppresses interference from supervised fine-tuning data. Attached Figure Description
[0047] The present invention will now be further described with reference to the following figures.
[0048] Figure 1 This is a schematic diagram of a unified supervised fine-tuning and reinforcement learning training framework based on dynamic weight fusion;
[0049] Figure 2 This is a schematic diagram of the dynamic decay of the μ value; Detailed Implementation
[0050] Example 1: This application proposes a unified supervised fine-tuning and reinforcement learning training method based on dynamic weight fusion. This method is based on a dual-path parallel architecture and a dynamic weight fusion mechanism to achieve unified integration and smooth transition of supervised fine-tuning (SFT) and reinforcement learning (RL).
[0051] Taking the OpenR1-Math-220k dataset as an example, the following methods are adopted: Figure 1 The unified supervised fine-tuning and reinforcement learning training framework shown includes the following implementation steps:
[0052] Step (1), Data preparation;
[0053] This includes SFT data preparation, which involves sampling 5,000 question-answer pairs (including thought processes and standard answers) from the dataset; and RL data preparation, which involves sampling 20,000 question-answer pairs (including thought processes and standard answers) from the dataset.
[0054] Step (2): Parallel processing along two paths;
[0055] Step (2.1), SFT path; see details. Figure 1 The lower half of the image is shown.
[0056] The SFT path is used to process SFT data question-answer pairs and calculate weighted supervised loss. It includes data input, which processes SFT data containing complete question-answer pairs (Prompt-Response) data.
[0057] In this context, Prompt represents the question or instruction entered by the user, and Response represents the standard answer.
[0058] The processing flow is as follows: input the SFT data into a pre-trained large language model, and calculate the SFT_loss of the model's generated response based on minimizing the negative log-likelihood of the response data.
[0059]
[0060] Among them, the weighting function It is based on the model's current confidence level in the token. ; The parameter is Large language models For conditional probability, given the cue word x and all previous real tokens, the large language model predicts the probability of the next real token to dynamically adjust the weight of the loss for each token; its purpose is to adjust the weight of the loss for tokens that the model is already confident about ( (close to 0 or 1) A small value means it's okay if it doesn't learn, preventing model overfitting; for tokens with uncertain models ( (close to 0.5) A large value means that the model should focus on learning it; The parameter is Large language models Let be the conditional probability, given the cue x and all previous real tokens, the probability that the large language model predicts the next real token; log is the natural logarithm of the probability. For each token position t in the standard answer of a data set, calculate its log probability, and then sum them to obtain the total loss of the data set; To perform the above operation on each data i in a batch and sum up the losses, we obtain the total loss of a batch, where B is the number of batches; "-" is a negative sign, representing minimizing the loss function; This represents a normalization operation, which divides the total loss of the batch by the total number of tokens for all standard answers in the batch.
[0061] Step (2.2) RL path, see details. Figure 1 The upper part is shown in the image;
[0062] The RL path is used to generate multiple candidate responses and compute reinforcement learning loss for RL data. It includes data input, which processes RL data containing only the question (Prompt), and the standard answer is only used to compute rule-based rewards. The processing flow is as follows: for each input Prompt, the large language model generates a total of K candidate responses; each candidate response is evaluated using rule-based rewards to compute a reward value.
[0063] The reward value is evaluated based on the following rules:
[0064] 1) Those who demonstrate a thought process and provide a correct answer will receive a positive reward of 1.1.
[0065] 2) For answers that only provide the correct answer without any thought process, a positive reward of 0.1 will be given;
[0066] 3) A neutral reward of 0.0 will be given for answers that include a thought process but are incorrect.
[0067] 4) If there is no thought process and the answer is incorrect, a penalty of -1 will be given.
[0068] The reinforcement learning loss is calculated based on the GRPO algorithm as follows:
[0069]
[0070] Where B represents the quantity indicated in a batch; The advantage of each candidate response is calculated using the following expression: , The original reward obtained for a candidate response. , The mean and standard deviation of the group rewards. It is a small constant added to ensure numerical stability; token-level importance sampling ratio. This is used to compare the preference of the new strategy and the old strategy for generating the next token; given the prompt word x and the historical tokens that have already been generated. Under the given conditions, the old strategy generates the next token. The probability is The clip mechanism limits the importance sampling rate to a reliable region near the old strategy (i.e., Inside, among which It is a hyperparameter representing the maximum allowable change in a single update; min is the minimum value of the regular reward and the clip reward. Used for summation and normalization operations, it represents the average of the data in the entire batch, where B is the number of prompts in a batch, K is the number of responses generated for each prompt, and t is the number of tokens in each response;
[0071] Step (3), dynamic weight fusion mechanism;
[0072] By dynamically adjusting the loss weights of the SFT and RL paths using global coefficients μ, a gradual transition from imitation learning to exploratory learning is achieved; including,
[0073] Step (3.1), calculation of dynamic weight fusion loss;
[0074] The total loss calculation formula is as follows:
[0075]
[0076] in, These are global coefficients in the training framework, used to guide the model's transition from supervised learning to reinforcement learning at a macro level; To reinforce the learning loss function, the specific calculation process is performed according to step (2.2); To supervise the learning loss function, the specific calculation process is performed according to step (2.1);
[0077] Step (3.2): Execute the dynamic decay strategy for μ value;
[0078] The decay principle is that the μ value gradually decreases from a high value (e.g., 0.9) to a low value (e.g., 0.05) during training, causing the training focus to gradually shift from the SFT path (imitation learning) to the RL path (exploratory learning). The dynamic decay process of the μ value is as follows: Figure 2 As shown.
[0079] As described above, the embodiments given in conjunction with the accompanying drawings are merely preferred solutions for achieving the objectives of this invention. Those skilled in the art can draw inspiration from this and directly derive other alternative structures that conform to the design concept of this invention. Other structural features derived therefrom should also fall within the scope of the solutions described in this invention.
Claims
1. A unified supervised fine-tuning and reinforcement learning training method based on dynamic weight fusion, characterized in that: Based on a dual-path parallel architecture of SFT and RL, a dynamic weight fusion mechanism is used to implement the unified integration and smooth transition of supervised fine-tuning and reinforcement learning. The implementation steps include the following: Step (1), Data preparation; This includes SFT data preparation and RL data preparation, each involving sampling several question-answer pairs from the dataset; Step (2): Parallel processing along two paths; Step (2.1), SFT path; The process includes inputting data to process SFT data. The process involves inputting the SFT data into a pre-trained large language model and calculating the SFT loss of the model's generated response based on minimizing the negative log-likelihood of the response data. The expression for calculating SFT_loss is: Among them, the weighting function It is based on the model's current confidence level in the token. ; The parameter is Large language models For conditional probability, given the cue word x and all previous real tokens, the large language model predicts the probability of the next real token to dynamically adjust the weight of the loss for each token; its purpose is to adjust the weight of the loss for tokens that the model is already confident about. Close to 0 or 1, A small value means it's okay if it doesn't learn, preventing model overfitting; for tokens with uncertain models, Close to 0.5 A large value means that the model should focus on learning it; The parameter is Large language models Let be the conditional probability, given the cue x and all previous real tokens, the probability that the large language model predicts the next real token; log is the natural logarithm of the probability. For each token position t in the standard answer of a data set, calculate its log probability, and then sum them to obtain the total loss of the data set; To perform the above operation on each data i in a batch and sum up the losses, we obtain the total loss of a batch, where B is the number of batches; "-" is a negative sign, representing minimizing the loss function; This represents a normalization operation, which divides the total loss of the batch by the total number of tokens for all standard answers in the batch. Step (2.2) RL path; The process includes inputting data to process RL data. The processing flow is as follows: for each input prompt, the large language model generates a total of K candidate responses; each candidate response is evaluated using rule-based rewards to calculate a reward value; and reinforcement learning loss is calculated based on the GRPO algorithm. The reinforcement learning loss is calculated using the following formula: Where B represents the quantity indicated in a batch; The advantage of each candidate response is calculated using the following expression: , The original reward obtained for a candidate response. , The mean and standard deviation of the group rewards. It is a small constant added to ensure numerical stability; token-level importance sampling ratio. This is used to compare the preference of the new strategy and the old strategy for generating the next token; given the prompt word x and the historical tokens that have already been generated. Under the given conditions, the old strategy generates the next token. The probability is The clip mechanism restricts the importance sampling rate to a reliable region near the old strategy, i.e. Inside, among them, It is a hyperparameter representing the maximum allowable change in a single update; min is the minimum value of the regular reward and the clip reward. Used for summation and normalization operations, it represents the average of the data in the entire batch, where B is the number of prompts in a batch, K is the number of responses generated for each prompt, and t is the number of tokens in each response; Step (3), dynamic weight fusion mechanism; By dynamically adjusting the loss weights of the SFT and RL paths using global coefficients μ, a gradual transition from imitation learning to exploratory learning can be achieved.
2. The unified supervised fine-tuning and reinforcement learning training method based on dynamic weight fusion according to claim 1, characterized in that: In step (2.2), the input data only contains the data of the question, and the standard answer is only used to calculate the rule-based reward.
3. The unified supervised fine-tuning and reinforcement learning training method based on dynamic weight fusion according to claim 1, characterized in that: The reward value in step (2.2) is evaluated based on the following rules: A positive reward of 1.1 will be given for demonstrating the thought process and providing a correct answer; For answers that only provide the correct answer without any thought process, a positive reward of 0.1 will be given. A neutral reward of 0.0 will be given for answers that include a thought process but are incorrect. Those who neither demonstrate a thought process nor provide an correct answer will be penalized with -1.
4. The unified supervised fine-tuning and reinforcement learning training method based on dynamic weight fusion according to claim 1, characterized in that: Step (3) includes the following steps: Step (3.1), calculation of dynamic weight fusion loss; The total loss calculation formula is as follows: in, These are global coefficients in the training framework, used to guide the model's transition from supervised learning to reinforcement learning at a macro level; To enhance the learning loss function, The loss function for supervised learning; Step (3.2): Execute the dynamic decay strategy for μ value; The μ value gradually decreases from a high value of 0.5 to 1 during training to a low value of 0.5 to 0, thus shifting the training focus from imitation learning to exploratory learning.