Building Math Agents with Multi-Turn Iterative Preference Learning

## Abstract

Abstract Recent studies have shown that large language models’ (LLMs) mathematical problem-solving capabilities can be enhanced by integrating external tools, such as code interpreters, and employing multi-turn Chain-of-Thought (CoT) reasoning. While current methods focus on synthetic data generation and Supervised Fine-Tuning (SFT), this paper studies the complementary direct preference learning approach to further improve model performance. However, existing direct preference learning algorithms are originally designed for the single-turn chat task, and do not fully address the complexities of multi-turn reasoning and external tool integration required for tool-integrated mathematical reasoning tasks. To fill in this gap, we introduce a multi-turn direct preference learning framework, tailored for this context, that leverages feedback from code interpreters and optimizes trajectory-level preferences. This framework includes multi-turn DPO and multi-turn KTO as specific implementations. The effectiveness of our framework is validated through training of various language models using an augmented prompt set from the GSM8K and MATH datasets. Our results demonstrate substantial improvements: a supervised fine-tuned Gemma-1.1-it-7B model’s performance increased from 77.5% to 83.9% on GSM8K and from 46.1% to 51.2% on MATH.
Similarly, a Gemma-2-it-9B model improved from 84.1% to 86.3% on GSM8K and from 51.0% to 54.5% on MATH.

###### keywords:

## 1 Introduction

Large language models (LLMs) have demonstrated remarkable capacities across a variety of language tasks, showcasing their broad-ranging capabilities in natural language processing. Notable models include ChatGPT (OpenAI, ), Claude (Anthropic, ), and Gemini (Team et al., ). However, despite these advances, even the most advanced closed-source LLMs still struggle with complex reasoning tasks that require multi-rounds of decision making. In particular, for the representative task of mathematical problem solving, LLMs often fail with basic arithmetic and symbolic computations (Hendrycks et al., ; Cobbe et al., ; Zheng et al., ). To address this issue, recent studies recommend the integration of external tools (e.g., calculators, computational Python libraries and symbolic solvers) to augment the LLMs’ mathematical problem-solving capabilities (Cobbe et al., ; Shao et al., ; Mishra et al., ; Zhang et al., ). Specifically, by integrating natural language reasoning with the use of these external tools, these enhanced LLMs can receive external messages from tool interactions and reason based on both previously generated tokens and external messages, which significantly improves their performance in mathematical tasks (Gou et al., ; Toshniwal et al., ; Shao et al., ).

These successes of tool-integrated LLMs lead to a natural research question: how can we better train LLMs to combine tool usage with intrinsic reasoning to tackle complex reasoning tasks? For the mathematical problem solving task, existing works primarily focus on synthetic data generation (by a strong teacher model) and supervised fine-tuning (SFT), as seen in ToRA (Gou et al., ), MetaMathQA (Yu et al., ), MAmmoTH (Yue et al., , ), and Open-MathInstruct (Toshniwal et al., ). These methods and synthetic datasets have yielded significant improvements in test accuracy on standard benchmarks like MATH (Hendrycks et al., ) and GSM8K (Cobbe et al., ).

Built on strong SFT models, Reinforcement Learning from Human Feedback (RLHF) has proven to be a key technique to elicit LLMs’ knowledge during the post-training stage and has become a standard practice in the LLM training pipeline (Bai et al., ; Ouyang et al., ; Touvron et al., ; Team et al., ). Broadly speaking, the RLHF learning paradigm, which was originally designed for aligning large language models (LLMs) with human values and preferences (Bai et al., ; Ouyang et al., ), is distinct from SFT as it learns from relative feedback (Christiano et al., ; Ziegler et al., ). It has notably enhanced the capabilities of models like ChatGPT, Claude, and Gemini, enabling them to generate responses that are more helpful, harmless, and honest (Bai et al., ). Inspired by RLHF’s success in general chat applications, in this paper, we explore RLHF for improving LLMs’ mathematical problem-solving abilities when equipped with external tools. In particular, since deep RL methods (e.g., the proximal policy optimization, PPO algorithm (Schulman et al., )) are often sample inefficient and unstable (Choshen et al., ), our goal is to derive direct preference learning algorithms that directly learn from the preference dataset (Zhao et al., ; Rafailov et al., ; Azar et al., ).

#### Contribution.

We begin by formulating the learning process as a Markov decision process (MDP), distinct from the contextual bandit approach typically used in RLHF for making general chatbots without external environment interactions (; Rafailov et al., ). Then, we derive the optimality condition of the optimization problem and develop multi-turn direct alignment algorithms (M-DPO and M-KTO) that incorporate external messages, where the primary modification is to mask out irrelevant tokens during training. Furthermore, we extend our approach to its online iterative variants, which recent works demonstrated to be promising (; Guo et al., ). Finally, we evaluate our approach through case studies using augmented training sets from MATH and GSM8K benchmarks, employing various base models such as Gemma (Team et al., ), CodeGemma (Team, ), and Mistral (Jiang et al., ). For instance, the performance of a supervised fine-tuned Gemma-1.1-it-7B model increased from 77.5% to 83.9% on GSM8K and from 46.1% to 51.2% on MATH. Similarly, a Gemma-2-it-9B model improved from 84.1% to 86.3% on GSM8K and from 51.0% to 54.5% on MATH. These empirical results indicate a significant improvement in performance over standard SFT models, demonstrating the potential of RLHF in complex reasoning task. We also provide a comprehensive recipe for the practical implementation of our online iterative multi-turn methods, and make our models, datasets, and code publicly available for further research and development.

### 1.1 Problem Formulation

We denote prompt as $x\in\mathcal{X}$ and assume that the interactions run for up to $H$ rounds. At the first step, a prompt $x$ is sampled from some distribution $d_{0}$ as the initial state $s_{1}=x$ (We use the terminology “state” instead of “context” because we are concerning about an MDP instead of a contextual bandit here). Then, at each step $h\in[H]$,

- •
Action: the agent observes the current state $s_{h}$, which is the history of the first $h-1$ interactions with the external environment, and takes an action $a_{h}$ according to some policy $\pi_{h}(\cdot|s_{h})\in\Delta(\mathcal{A})$. Typically, the action is in the ReAct manner, which consist of a reasoning step $f_{h}$ and an execution step $e_{h}$ (e.g., writing python code) (Yao et al., ).
- •
Observation: in response to the agent’s action, the environment then returns an observation $o_{h}$ based on the history $s_{h}$ and current action $a_{h}$.

Then, we transit to a new state, which is the history up to the step $h+1$:

$$ $s_{h+1}=(s_{h},a_{h},o_{h})=(x,a_{1},o_{1},\cdots,a_{h},o_{h}),$ $$

and a new step begins. This process repeats for $H$ rounds in total and eventually, we collect a trajectory:

$$ $\tau=(x,a_{1},o_{1},\cdots,o_{H-1},a_{H}).$ $$

See Figure 1 for an example. The framework presented here is a Markov decision process (MDP), which offers a distinct approach from the contextual bandit model discussed in . Formally, we define the following MDP.

###### Definition 1 .

An MDP is specified by a tuple $({\mathcal{S}},\mathcal{A},H,\mathbb{P}^{*},d_{0})$, where $\mathcal{A}$ is the action space, $H$ is the episode length(^1^11In practice, the episode length can vary across the trajectories. We may additionally define that the shorter trajectories that output the final answer are in an absorbing state. We consider the fixed episode length to simplify the subsequent mathematical analysis.), $\mathbb{P}^{*}=\{\mathbb{P}^{*}_{h}\}_{h=1}^{H}$ are the state transition kernels, and $d_{0}$ denotes the distribution of prompt $s_{1}=x$. For each $h\in[H]$, $\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})$ is the distribution of the next state given the state-action pair $(s_{h},a_{h})$ at step $h$. In our setup, a trajectory $\tau=(x,a_{1},o_{1},\cdots,o_{H-1},a_{H})$ is generated by: $s_{1}=x\sim d_{0}$ and for all $h\in[H],a_{h}\sim\pi_{h}(\cdot|s_{h}),o_{h}\sim\mathbb{P}^{*}_{h}(\cdot|s_{h},
a_{h})$ where $s_{h+1}=(s_{h},a_{h},o_{h})$. When there is no ambiguity, the abbreviation $s_{h+1}\sim\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})$ is also adopted.

Figure: Figure 1: An example of multi-turn mathematical reasoning with Python interpreter. The action is in a ReAct style (Yao et al., ) where it consists of a reasoning step $f_{h}$ and an executation step $e_{h}$.
Refer to caption: extracted/5831478/figs/tora_example.png

The MDP formulation of preference learning was recently studied in Zhong et al. (); Rafailov et al. (); Xie et al. () but with a focus on the single-turn chat task and without explicitly considering the external messages. A unique feature of RLHF, as opposed to traditional RL studies, is the relative feedback obtained through comparisons between two trajectories that share the same initial state (prompt). We follow Ziegler et al. (); Ouyang et al. (); Bai et al. () to assume that the preference signal is generated by the so-called Bradley-Terry model.

###### Definition 2 (Bradley-Terry model) .

We denote $\tau/x=y$, where the prompt is excluded from the trajectory. We assume that there exists a utility function of the trajectory $u^{*}$ such that given $(x,y^{1},y^{2})$, one response $y^{1}$ is preferred over another response $y^{2}$, denoted as $y^{1}\succ y^{2}$, with probability

$$ $\textup{Prob}\big{(}y^{1}\succ y^{2}\mid x,y^{1},y^{2}\big{)}=\sigma\big{(}u^{ *}(x,y^{1})-u^{*}(x,y^{2})\big{)},$ (1) $$

where $\sigma$ is the sigmoid function $\sigma(z)=1/(1+\exp(-z))$. Also, given $(x,y^{1},y^{2})$ we denote the sampled preference signal as $z$ with $z=1$ indicating $y^{1}\succ y^{2}$ while $z=0$ indicating $y^{2}\succ y^{1}$.

Under this definition, we only assume access to the trajectory-level preference, but not an action-level one. This should distinguish our approach from a straightforward extension of the single-turn RLHF (Christiano et al., ; Ziegler et al., ), which fixes a prompt that may include mid-trajectory steps such as $(x,a_{1},o_{1},a_{2},o_{2})$ and look into the next single step $a_{3}$. However, we remark that the utility function itself, can be defined in a step-wise manner. To further illustrate the notion of the BT model in trajectory-level comparisons, we provide some examples of the utility function here.

###### Example 1 (Result Checking in Math) .

Since the math reasoning datasets GSM8K (Cobbe et al., ) and MATH (Hendrycks et al., ) have the gold answer, we can check the final answer to determine the reward. In this case, $u^{*}(x,y)=\mathbb{I}(a_{H}=\text{gold answer})$.

###### Example 2 (Outcome-supervised Reward Models (ORMs)) .

Final result checking is not perfectly reliable because we can encounter false positive solutions that have the correct answer but incorrect reasoning trajectory. Instead, as shown in Cobbe et al. (); Lightman et al. (), we can uniformly sample $n$ trajectories per prompt and train an ORM to predict whether each solution is correct or not. Then, we can take the ORM prediction at the final token as the utility function.

###### Example 3 (Process-supervised Reward Model (PRM) and PRM without Human Annotation.) .

Lightman et al. () argues that if we can provide step-by-step supervision signal, the utility function is more effective. However, this requires more fine-grained human labels to give rating for each step of the trajectory. Wang et al. () studies how to automatically construct the process-labeled data for math problems with gold answers. Specifically, for $s_{h},a_{h}$, we generate $N$ trajectories with final answers $[a_{H}^{j}]_{j=1}^{N}$. We can define the proxy reward value:

$$ $\displaystyle r(s_{h},a_{h}):=\frac{\sum_{j=1}^{N}\mathbb{I}(a_{H}^{j}=\text{ gold answer})}{N}.$ (2) $$

We may also use a hard version

$$ $\displaystyle r(s_{h},a_{h}):=\mathbb{I}(\text{There exists a }j_{0}:a_{H}^{j_ {0}}=\text{gold answer}).$ (3) $$

Then, we can train the PRM by

$$ $\mathcal{L}_{PRM}(\theta)=\mathbb{E}_{\tau\sim\mathcal{D}}\Big{[}\sum\nolimits _{h=1}^{H}r(s_{h},a_{h})\log r_{\theta}+(1-r(s_{h},a_{h}))\log(1-r_{\theta}) \Big{]}.$ (4) $$

In this case, we can use $u^{*}(x,y)=\min_{h\in[H]}r_{\theta}(s_{h},a_{h})$ (Lightman et al., ), where $r_{\theta}$ is the constructed step-wise reward function.

Notations. To improve the readability of this work, we provide a notable table in Table 6.

###### Definition 1 .

###### Definition 2 (Bradley-Terry model) .

###### Example 1 (Result Checking in Math) .

###### Example 2 (Outcome-supervised Reward Models (ORMs)) .

###### Example 3 (Process-supervised Reward Model (PRM) and PRM without Human Annotation.) .

### 1.2 Related Work

#### LLMs for Mathematical Problem Solving.

A line of works proposes to prompt LLMs to solve the complex reasoning task in a step-by-step manner, known as the Chain-of-Thought (CoT) prompting (Wei et al., ; Zhou et al., ; Zhu et al., ; Tong et al., ), which has been a standard practice in reasoning task. However, LLMs often struggle with basic arithmetic and symbolic manipulations when relying solely on internal knowledge and natural language reasoning, as measured by standard benchmarks (Cobbe et al., ; Hendrycks et al., ). To overcome these limitations, several studies have explored the use of external tools to enhance the LLMs’ problem-solving abilities. This includes calculators (Cobbe et al., ; Shao et al., ), symbolic solvers (Zhang, ), and code interpreters (Mishra et al., ; OpenAI, ). A particularly effective approach is the Program-based method (PoT), which performs CoT reasoning by writing code and using the output of the written code as the final answer (Gao et al., ; Chen et al., ). This method significantly outperforms traditional CoT-based techniques in mathematical problem solving. However, PoT also faces challenges in planning and error handling, where natural language reasoning is more suitable (Gou et al., ). In view of this, tool-integrated reasoning is proposed to combine the natural-language-based intrinsic reasoning with the external tools (Gou et al., ) and has achieved great progresses in recent studies (Gou et al., ; Yue et al., ; Yu et al., ; Shao et al., ; Toshniwal et al., ). While these efforts have primarily focused on synthetic data generation for tool-integrated reasoning, our work aims to further boost the performance of tool-integrated LLMs by RLHF.

#### RLHF and RLHF Algorithms.

The predominant approach in RLHF is the deep RL method, Proximal Policy Optimization Algorithms (PPO) (Schulman et al., ), which leads to the great successes in Chat-GPT (OpenAI, ), Gemini (Team et al., ), and Claude (Anthropic, ). However, applying PPO requires extensive efforts and resources (Choshen et al., ; Engstrom et al., ), often beyond the scope of open-source capabilities. In view of this, alternative approaches have been developed. The rejection sampling fine-tuning was first proposed with the name RAFT (reward ranked fine-tuning) in RLHF (Dong et al., ) and was later extended to machine translation (Gulcehre et al., ) and mathematical problem solving (Yuan et al., ). Its theoretical advantage was explored in Gui et al. (). Subsequently, another long line of works proposes direct preference learning algorithms, including SLiC (Zhao et al., ), DPO (Rafailov et al., ), IPO (Azar et al., ), KTO (Ethayarajh et al., ), and GPO (Tang et al., ). These algorithms bypass the reward modeling step and optimize carefully designed loss objectives directly on the preference dataset, hence the name direct preference learning. There are also some works focusing on more general preference structure Munos et al. (); Swamy et al. (); Ye et al. (); Rosset et al. () beyond the reward-based framework or post-processing of the model (Lin et al., ; Zheng et al., ).

The newly proposed direct preference learning algorithms have largely advanced the RLHF area, particularly the post-training of open-source models, with the Zephyr project as a notable example (Tunstall et al., ). After this, a long line of work (e.g., Liu et al., ; ; Guo et al., ; Xu et al., ; Tajwar et al., ; Xie et al., ; Zhang et al., ; Liu et al., , ; Meng et al., ) demonstrates the effectiveness of on-policy sampling (the samples are generated by the policy to be trained) and online exploration in enhancing direct preference learning. In particular, the online iterative DPO (; Xu et al., ; Hoang Tran, ) and its variants (e.g., Chen et al., ; Rosset et al., ; Cen et al., ; Zhang et al., ) have made state-of-the-art open-source models (Dong et al., ), or even the industry models (qwe, ; Meta, ). Despite these advancements, most algorithms are proposed and designed for single-turn interactions and chat. The scenarios beyond single-turn chat remain largely unexplored in the existing literature. One exception is the very recent work by Shani et al. (), which studies multi-turn chat task under general preferences. In contrast, in this paper, we aim to explore the use of RLHF in multi-turn tasks that incorporate interactions with external tools. Meanwhile, they derive a mirror-descent-based policy optimization algorithm, which is also different from ours.

#### RLHF for Math Problem Solving.

Algorithms traditionally used in general chatbot applications have been adapted to enhance the reasoning capabilities of LLMs in mathematical contexts. For instance, RAFT (Reward-rAnked Fine-Tuning) (Dong et al., ; Yuan et al., ; Touvron et al., ) is extensively employed for synthetic data generation, whether through on-policy (self-improving) (Yuan et al., ) or off-policy (knowledge distillation) methods (Gou et al., ; Yu et al., ; Toshniwal et al., ; Singh et al., ; Tong et al., ). The reward signal in these scenarios is typically derived from either final result checking or Outcome-supervised Reward Models (ORMs) (Uesato et al., ; Zelikman et al., ). A novel approach by Lightman et al. () introduces Process-supervised Reward Models (PRMs), which provide feedback at each step of the Chain-of-Thought, demonstrating significant improvements over ORMs when combined with rejection sampling (Lightman et al., ; Wang et al., ).

In addition to the RAFT, the GRPO algorithm proposed in Shao et al. () studies multi-turn math problem solving but focuses on the CoT format without external inputs and the resulting model achieves the state-of-the-art performance in its class. The GRPO is a variant of Reinforce (Williams, ) thus falling into the scope of deep RL methods.

Further advancements include adapting direct preference learning algorithms to mathematical problem solving. For instance, Jiao et al. (); Yuan et al. () have applied the original DPO or KTO by taking the trajectory completion as a “meta” action. Xie et al. (); Pang et al. () further adapt the online iterative DPO originally designed for chat (; Xu et al., ; Hoang Tran, ) and achieve better performance for CoT reasoning. Inspired by the success of PRMs, recent studies have explored generating proxy step-wise labels for the intermediate steps of the reasoning trajectories. For instance, Xie et al. (); Chen et al. (); Lai et al. () leverage Monte Carlo Tree Search (MCTS) and use the estimated Q value to generate the proxy labels for the intermediate steps. Lai et al. () proposes to use AI feedback like GPT-4 (Lai et al., ) to find the first error step in the trajectory. Meanwhile, Lu et al. () identifies a trajectory with the correct final answer and no errors as preferable, and prompts the SFT model with a high temperature, starting from some intermediate step to collect a rejected trajectory with errors (Pi et al., ). Finally, a very recent study by Chen et al. () proposes to use MCTS with a backward iteration from the final leaf node to compute the proxy unregularized value of each node. Preference pairs are then extracted from the tree by fixing the prefix and comparing the next single reasoning step. Then, they run the original DPO on these intermediate actions with the proxy labels from MCTS. To summarize, these works present different ways of preference data collection and apply the original DPO algorithm (with some additional marginal loss and regularization adapted from the literature), thereby differing from our work in both algorithmic concepts and application scope. In contrast, we study preference learning in the context of trajectory-level comparison, where we derive the optimality condition and introduce a multi-turn DPO within an online iterative framework, specifically for tool-integrated mathematical problem solving. However, we remark that while we focus on the trajectory-level comparison, the preference signal itself can be generated in a step-by-step supervision (see Section 1.1 for the detailed examples). When preference signals for partial trajectories with shared prefixes are available, our method can also adapt to learn these step-level signals (see the optimality condition in (11)). In particular, the algorithmic design presented in this paper can be readily combined with the MCTS-based data collection strategy outlined in recent literature, which we leave for future work.

## 2 Algorithms Development

We develop the main algorithms of this paper in this section. We proceed to handle the general MDP formulation presented in Section 1.1, which subsumes the tool-integrated mathematical reasoning problem as a special example. Therefore, the algorithms may also be applied to more general scenarios with external messages..

### 2.1 Planning with a Fixed Model: Optimality Condition

Following Rafailov et al. (), we first establish the connection between any model $\mathcal{M}=({\mathcal{S}},\mathcal{A},H,\mathbb{P},d_{0},u)$ and its associated optimal policy. In particular, we are interested in the following KL-regularized planning problem with respect to a reference policy $\pi_{\mathrm{ref}}$:

$$ $\mathop{\mathrm{argmax}}_{\pi}J(\pi;\mathcal{M},\pi_{\mathrm{ref}})=\mathbb{E} _{x\sim d_{0}}\mathbb{E}_{a_{h}\sim\pi_{h}(\cdot|s_{h}),o_{h}\sim\mathbb{P}_{h }(\cdot|s_{h},a_{h})}\left[u(x,y)-\eta\sum_{h=1}^{H}D_{\mathrm{KL}}\big{(}\pi_ {h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{h})\big{)}\right].$ (5) $$

In the single-turn case (i.e., $H=1$ and without transitions $\mathbb{P}$), Rafailov et al. (); Azar et al. () show that the optimal solution with respect to a utility function $u$ admits a closed-form solution, which is the Gibbs distribution (see Lemma 3):

$$ $\pi_{\mathcal{M}}(a_{1}|x)\propto\pi_{\mathrm{ref}}(a_{1}|x)\exp\left(\frac{u( x,a_{1})}{\eta}\right).$ $$

Moving from the single-step to multi-turn scenario, we first show that we are still concerning about the Gibbs distribution, but in a dynamic programming manner. The results are essentially from the study of entropy-regularized MDPs (Williams and Peng, ; Ziebart, ).

To illustrate the idea, we first consider the simplest case of $H=2$, where the model is allowed to call the tool only once. Then, our goal is to maximize the following target:

$$ $\displaystyle\mathbb{E}_{x\sim d_{0}}\Big{[}\mathbb{E}_{a_{1}\sim\pi_{1}(\cdot |x)}\Big{[}\mathbb{E}_{o_{1}\sim\mathbb{P}_{1}(\cdot|x,a_{1})}\underbrace{ \mathbb{E}_{a_{2}\sim\pi_{2}(\cdot|s_{2})}u(s_{2},a_{2})-\eta D_{\mathrm{KL}} \big{(}\pi_{2}(\cdot|s_{2}),\pi_{\mathrm{ref},2}(\cdot|s_{2})\big{)}}_{ \displaystyle\text{Inner Loop}}\Big{]}-\eta D_{\mathrm{KL}}\big{(}\pi_{1}( \cdot|s_{1}),\pi_{\mathrm{ref},1}(\cdot|s_{1})\big{)}\Big{]}.$ $$

The idea is to take a backward iteration from $h=H=2$ to $h=1$. Specifically, when we fix $s_{2}$ and consider the inner loop, we can leverage Lemma 3 to solve

$$ $\pi_{\mathcal{M},2}(\cdot|s_{2})=\mathop{\mathrm{argmax}}_{\pi_{2}}\mathbb{E}_ {a_{2}\sim\pi_{2}(\cdot|s_{2})}\Big{(}u(s_{2},a_{2})-\eta\cdot D_{\mathrm{KL}} \big{(}\pi_{2}(\cdot|s_{2}),\pi_{\mathrm{ref},2}(\cdot|s_{2})\big{)}\Big{)} \propto\pi_{\mathrm{ref},2}(\cdot|s_{2})\cdot\exp\left(\frac{u(s_{2},\cdot)}{ \eta}\right).$ $$

Then, we can define the value of the inner loop associated with $\pi_{\mathcal{M},2}$ as

$$ $\displaystyle V_{\mathcal{M},2}(s_{2})$ $\displaystyle:=\mathbb{E}_{a_{2}\sim\pi_{\mathcal{M},2}(\cdot|s_{2})}\left[u(s _{2},a_{2})-\eta D_{\mathrm{KL}}\big{(}\pi_{\mathcal{M},2}(\cdot|s_{2}),\pi_{ \mathrm{ref},2}(\cdot|s_{2})\big{)}\right]$ $\displaystyle Q_{\mathcal{M},1}(s_{1},a_{1})$ $\displaystyle:=\mathbb{E}_{o_{1}\sim\mathbb{P}_{1}(\cdot|s_{1},a_{1})}\left[V_ {\mathcal{M},2}(s_{2})\right].$ $$

Then, for step $h=H-1=1$, we are concerning the following KL-regularized optimization problem:

$$ $\displaystyle\pi_{\mathcal{M},1}(\cdot|s_{1})=\mathop{\mathrm{argmax}}_{\pi_{1 }}\mathbb{E}_{a_{1}\sim\pi_{1}(\cdot|x)}\Big{[}Q_{\mathcal{M},1}(s_{1},a_{1})- \eta D_{\mathrm{KL}}\big{(}\pi_{1}(\cdot|s_{1}),\pi_{\mathrm{ref},1}(\cdot|s_{ 1})\big{)}\Big{]}\propto\pi_{\mathrm{ref},1}(\cdot|s_{1})\cdot\exp\Big{(}\frac {Q_{\mathcal{M},1}(s_{1},\cdot)}{\eta}\Big{)}.$ $$

By construction, it can be observed that $\{\pi_{\mathcal{M},h}\}_{h=1}^{2}$ is optimal as it maximizes the KL-regularized target.

For general $H$-step MDP, we can repeat the above process for $H$ times starting with $V_{\mathcal{M},H+1}=0$ where we recursively define

$$ $Q_{\mathcal{M},h}(s_{h},a_{h})=\begin{cases}&u(s_{H},a_{H}),\qquad\text{ if }h =H,\\ &\mathbb{E}_{o_{h}\sim\mathbb{P}_{h}(\cdot|s_{h},a_{h})}[V_{\mathcal{M},h+1}(s _{h+1})],\qquad\text{ if }h\leq H-1,\end{cases}$ (6) $$

Here the optimal policy and the $V$-values are given by

$$ $\displaystyle\pi_{\mathcal{M},h}(a_{h}|s_{h})$ $\displaystyle:=\frac{1}{Z_{h}(s_{h})}\pi_{\mathrm{ref},h}(a_{h}|s_{h})\cdot \exp\Big{(}\frac{Q_{\mathcal{M},h}(s_{h},a_{h})}{\eta}\Big{)}\qquad\text{( Gibbs distribution of $Q_{\mathcal{M},h}$)}$ (7) $\displaystyle V_{\mathcal{M},h}(s_{h})$ $\displaystyle:=\mathbb{E}_{a_{h}\sim\pi_{\mathcal{M},h}(\cdot|s_{h})}\big{[}Q_ {\mathcal{M},h}(s_{h},a_{h})-\eta\cdot D_{\mathrm{KL}}\big{(}\pi_{\mathcal{M}, h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{h})\big{)}\big{]}$ $\displaystyle=\eta\log\mathbb{E}_{\pi_{\mathrm{ref},h}(a^{\prime}_{h}|s_{h})} \exp\Big{(}\frac{Q_{\mathcal{M},h}(s_{h},a_{h}^{\prime})}{\eta}\Big{)},$ $$

where $Z_{h}(s_{h})=\sum_{a_{h}\in\mathcal{A}}\pi_{\mathrm{ref},h}(a_{h}|s_{h})\cdot
\exp\big{(}\frac{Q_{\mathcal{M},h}(s_{h},a_{h})}{\eta}\big{)}$ is the normalization constant. The second equality in the definition of the $V$-value is from Lemma 3. Then, by definition, $[\pi_{\mathcal{M},h}]_{h=1}^{H}$ is the optimal policy. Essentially, we solve $H$ Gibbs distributions in terms of the $Q$-values(^2^22The definitions of $Q$-values are different from that of Ziebart () so that the optimal policy can be interpreted as the Gibbs distribution of $Q$-values.).

### 2.2 Planning with a Fixed Model: Practical Algorithm

While (7) can be approximately solved with standard deep RL methods, here we are interested in the implementation in a direct preference learning manner like SLiC (Zhao et al., ), DPO (Rafailov et al., ) or IPO (Azar et al., ). The existing attempts (e.g., Yuan et al., ) take the completion $y$ as a “meta action” and plug it into the single-step DPO loss. In other words, they treat the external messages as the regular texts generated by the model itself. Another natural idea is to plug the probability of the trajectory into the single-step DPO loss. To be specific, for a pair $(x,\tau^{w},\tau^{l})$, where $\tau^{w}$ refers to the preferred (i.e., winning) trajectory, we have

$$ $\displaystyle-\log\sigma\Big{(}\eta\Big{[}\log\frac{\textup{Prob}_{\pi}(\tau^{ l}|x)}{\textup{Prob}_{\pi_{\mathrm{ref}}}(\tau^{l}|x)}-\log\frac{\textup{Prob} _{\pi}(\tau^{w}|x)}{\textup{Prob}_{\pi_{\mathrm{ref}}}(\tau^{w}|x)}\Big{]}\Big {)}$ (8) $\displaystyle=-\log\sigma\Big{(}\eta\Big{[}\log\prod_{h=1}^{H}\frac{\pi_{h}(a^ {l}_{h}|s^{l}_{h})\cancel{\mathbb{P}_{h}(o^{l}_{h}|s^{l}_{h},a^{l}_{h})}}{\pi_ {\mathrm{ref},h}(a^{l}_{h}|s_{h}^{l})\cancel{\mathbb{P}_{h}(o^{l}_{h}|s^{l}_{h },a^{l}_{h})}}-\log\prod_{h=1}^{H}\frac{\pi_{h}(a^{w}_{h}|s^{w}_{h})\cancel{ \mathbb{P}_{h}(o^{w}_{h}|s^{w}_{h},a^{w}_{h})}}{\pi_{\mathrm{ref},h}(a^{w}_{h} |s_{h}^{w})\cancel{\mathbb{P}_{h}(o^{w}_{h}|s^{w}_{h},a^{w}_{h})}}\Big{]}\Big{)}$ $\displaystyle=-\log\sigma\Big{(}\eta\sum_{h=1}^{H}\Big{[}\log\frac{\pi_{h}(a^{ l}_{h}|s_{h}^{l})}{\pi_{\mathrm{ref},h}(a^{l}_{h}|s_{h}^{l})}-\log\frac{\pi_{h }(a^{w}_{h}|s_{h}^{w})}{\pi_{\mathrm{ref},h}(a^{w}_{h}|s_{h}^{w})}\Big{]}\Big{ )}.$ $$

Unfortunately, the resulting algorithm does not always lead to the optimal policy as we explain next. In particular, we can solve the $Q$-values as

$$ $\displaystyle Q_{\mathcal{M},h}(s_{h},a_{h})$ $\displaystyle=\log\frac{\pi_{\mathcal{M},h}(a_{h}|s_{h})}{\pi_{\mathrm{ref},h} (a_{h}|s_{h})}+\eta\log\mathbb{E}_{\pi_{\mathrm{ref},h}(a^{\prime}_{h}|s_{h})} \exp\Big{(}\frac{Q_{\mathcal{M},h}(s_{h},a_{h}^{\prime})}{\eta}\Big{)}$ (9) $\displaystyle=\log\frac{\pi_{\mathcal{M},h}(a_{h}|s_{h})}{\pi_{\mathrm{ref},h} (a_{h}|s_{h})}+V_{\mathcal{M},h}(s_{h}),$ $$

where two equalities uses the definition of the optimal policy $\pi_{\mathcal{M},h}$ and $V$-value $V_{\mathcal{M},h}$ in (7), respectively. Furthermore, by the definition of $Q$-values $Q_{\mathcal{M},h}$ in (6), we have

$$ $\displaystyle\mathbb{E}_{o_{h}\sim\mathbb{P}_{h}(\cdot|s_{h},a_{h})}V_{ \mathcal{M},h+1}(s_{h+1})$ $\displaystyle=\log\frac{\pi_{\mathcal{M},h}(a_{h}|s_{h})}{\pi_{\mathrm{ref},h} (a_{h}|s_{h})}+V_{\mathcal{M},h}(s_{h}),\qquad\text{if }h\leq H-1$ (10) $\displaystyle u(s_{H},a_{H})$ $\displaystyle=\log\frac{\pi_{\mathcal{M},H}(a_{H}|s_{H})}{\pi_{\mathrm{ref},H} (a_{H}|s_{H})}+V_{\mathcal{M},H}(s_{H}).$ $$

Summing over $h\in[H]$, we have

$$ $\displaystyle u(s_{H},a_{H})$ $\displaystyle=\eta\sum_{h=1}^{H}\log\frac{\pi_{\mathcal{M},h}(a_{h}|s_{h})}{ \pi_{\mathrm{ref},h}(a_{h}|s_{h})}+\sum_{h=1}^{H}\Big{[}V_{\mathcal{M},h}(s_{h })-\mathbb{E}_{o_{h}\sim\mathbb{P}_{h}(\cdot|s_{h},a_{h})}V_{\mathcal{M},h+1}( s_{h+1})\Big{]}$ (11) $\displaystyle=\underbrace{\eta\sum_{h=1}^{H}\log\frac{\pi_{\mathcal{M},h}(a_{h }|s_{h})}{\pi_{\mathrm{ref},h}(a_{h}|s_{h})}}_{\text{term $(A)$}}+\underbrace{ V_{\mathcal{M},1}(s_{1})}_{\text{term $(B)$}}+\underbrace{\sum_{h=1}^{H-1}\Big {[}V_{\mathcal{M},h+1}(s_{h+1})-\mathbb{E}_{o_{h}\sim\mathbb{P}_{h}(\cdot|s_{h },a_{h})}V_{\mathcal{M},h+1}(s_{h+1})\Big{]}}_{\text{term $(C)$}}.$ $$

Here, term $(A)$ is the counterpart of $\eta\log\frac{\pi(a_{1}|s_{1})}{\pi_{\mathrm{ref}}(a_{1}|s_{1})}$ in the single-step DPO derivation and term $(B)$ will be cancelled if we consider the reward difference of two trajectories with the same prompt $s_{1}=x$. Unfortunately, in practice, term $(C)$ is typically not feasible to directly compute. Especially, some simple math with the Chebyshev’s Inequality leads to that with probability at least $0.9$,

$$ $|C|\leq 4\left[\sum_{h=1}^{H-1}\sigma_{h}^{2}\right]^{1/2},$ $$

where $\sigma_{h}^{2}$ is the conditional variance of $V_{\mathcal{M},h+1}(s_{h+1})-\mathbb{E}_{o_{h}\sim\mathbb{P}_{h}(\cdot|s_{h},a
_{h})}V_{\mathcal{M},h+1}(s_{h+1})$. Therefore, the bias term $(C)$ is related to the randomness of the external environment.

For most cases of tool-integrated LLMs for mathematical reasoning, i.e., the focus of this work, luckily the code execution result is determined by the history (the codes written by the LLMs). In other words, given the history $s_{h}$, the external observation is deterministic, which leads to $\text{term }(C)=0$. Thus, with a dataset $\mathcal{D}$ consisting of $(x,\tau^{w},\tau^{l})$, the following multi-turn DPO (M-DPO) loss can be adopted:

$$ $\mathcal{L}_{\textup{M-DPO}}(\theta)=-\sum_{(x,\tau^{w},\tau^{l})\in\mathcal{D }}\log\sigma\Big{(}\eta\sum_{h=1}^{H}\Big{[}\log\frac{\pi_{\theta,h}(a^{l}_{h} |s_{h}^{l})}{\pi_{\mathrm{ref},h}(a^{l}_{h}|s_{h}^{l})}-\log\frac{\pi_{\theta, h}(a^{w}_{h}|s_{h}^{w})}{\pi_{\mathrm{ref},h}(a^{w}_{h}|s_{h}^{w})}\Big{]}\Big {)},$ (12) $$

We emphasize again that although the loss presented in (12) is identical to the one in (8), a rigorous derivation procedure (rather than a direct plug-in) is provided. To the best of our knowledge, (12) is new in the context of multi-turn reasoning task with external messages. In particular, it is noted that such a M-DPO loss is only valid upon deterministic transitions, i.e., term $(C)=0$.

Moreover, with (11) implying that with term $(C)=0$, the implicit reward is given by $A=\eta\sum_{h=1}^{H}\log\frac{\pi^{*}_{h}(a_{h}|s_{h})}{\pi_{\mathrm{ref},h}(a
_{h}|s_{h})}$, a multi-turn version of KTO (Ethayarajh et al., ), denoted as M-KTO, can also be naturally derived:

$$ $\mathcal{L}_{\textup{M-KTO}}(\theta)=\mathbb{E}_{x,y\sim\mathcal{D}}\big{[} \lambda_{y}-v(x,y)\big{]},$ (13) $$

where

$$ $\displaystyle u_{\theta}(x,y)$ $\displaystyle=\eta\sum_{h=1}^{H}\log\frac{\pi_{u,h}(a_{h}|s_{h})}{\pi_{\mathrm {ref},h}(a_{h}|s_{h})},$ $\displaystyle z_{0}$ $\displaystyle=\mathbb{E}_{x^{\prime}\sim\mathcal{D},\tau^{\prime}\sim\pi_{ \theta}(\cdot|x^{\prime})}\sum_{h=1}^{H}D_{\mathrm{KL}}\big{(}\pi_{\theta}( \cdot|s_{h}),\pi_{\mathrm{ref}}(\cdot|s_{h})\big{)},$ $$

and

$$ $v(x,y)=\left\{\begin{aligned} \lambda_{+}\sigma\big{(}\eta(u_{\theta}(x,y)-z_{ 0})\big{)}&\qquad\text{if }y\sim y_{desirable}|x\\ \lambda_{-}\sigma\big{(}\eta(z_{0}-u_{\theta}(x,y))\big{)}&\qquad\text{if }y \sim y_{undesirable}|x\end{aligned}\right..$ $$

Here $\lambda_{+}$ and $\lambda_{-}$ are two hyper-parameters. We notice that Mitra et al. () developed an online iterative version of KTO for the CoT format reasoning task. Here we extend it to build the tool-integrated reasoning agent.

The above discussions, in particular, M-DPO and M-KTO losses provided in (12) and (13), are focused on deterministic observations due to the deterministic nature of tool-integrated LLMs for mathematical reasoning. In contrast, some other applications may encounter stochastic observations, e.g., multi-turn chats with the external message provided by a human or another LLM (Shani et al., ). In these scenarios, (12) is biased and cannot lead to the optimal policy since $\text{term }(C)\neq 0$. Instead, one should first construct a value network based on the Bellman equations provided in (6) and (7), similar to the approach in Richemond et al. (). Subsequently, $\text{term }(C)$ can be estimated using Monte-Carlo methods and serve as an adaptive margin in the preference training. Particularly, the distinctions between direct preference learning algorithms and classical deep RL methods become less clear. The exploration of this more complex algorithm and its application to general multi-turn learning scenarios is left for future research.

We note that the MDP formulation above and related discussions have been previously derived by Zhong et al. (); Rafailov et al. (); Xie et al. () in the context of either token-wise MDP or more general MDP with deterministic transition but their focuses are all on the single-turn chat tasks. Although the mathematical formulations appear similar, our primary focus lies on tool-integrated reasoning tasks that incorporate additional external messages $\{o_{h}\}_{h=1}^{H-1}$.

### 2.3 Learning with Online Iterative Training

In the literature of direct preference learning, a long line of work shows that the online single-turn RLHF significantly outperforms their offline counterpart, both in the literature of direct preference learning (; Ye et al., ; Guo et al., ; Rosset et al., ; Dong et al., ; Tajwar et al., ) and DRL-based approach or rejection sampling fine-tuning (Bai et al., ; Ouyang et al., ; Touvron et al., ). Motivated by these successes, we propose to further incorporate online interactive learning to the multi-turn RLHF studied in this work. In the following, we illustrate the proposed ideas from mainly two aspects: two learning objectives and one unified algorithmic framework.

#### Learning objective.

We consider two different learning objectives. The first one is the KL-regularized target:

$$ $\max_{\pi}\mathbb{E}_{x\sim d_{0}}\mathbb{E}_{a_{h}\sim\pi(\cdot|s_{h}),o_{h} \sim\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})}\Big{[}u^{*}(x,y)-\eta\sum_{h=1}^{H} D_{\mathrm{KL}}\big{(}\pi(\cdot|s_{h}),\pi_{0}(\cdot|s_{h})\big{)}\Big{]},$ (14) $$

i.e., $\max_{\pi}J(\pi;\mathcal{M}^{*},\pi_{0})$ where $\mathcal{M}^{*}=({\mathcal{S}},\mathcal{A},H,\mathbb{P}^{*},d_{0},u^{*})$ is the groundtruth environment and $\pi_{0}$ is the initial policy (e.g., from SFT) that RLHF starts from.
This target is widely adopted in practice (Christiano et al., ; Ouyang et al., ; Bai et al., ; Rafailov et al., ; Dong et al., ) and requires us to search for the optimal policy only at a fixed KL ball centered at the SFT policy $\pi_{0}$ (; Ye et al., ; Xie et al., ).

In contrast, the second one is the non-regularized target, i.e., directly optimizing the reward:

$$ $\max_{\pi}\mathbb{E}_{x\sim d_{0}}\mathbb{E}_{a_{h}\sim\pi(\cdot|s_{h}),o_{h} \sim\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})}\big{[}u^{*}(x,y)\big{]}.$ (15) $$

This target is the standard one in canonical RL studies (Sutton and Barto, ). One motivation for this target is that in the reasoning task, the reward function is more interpretable (e.g. final result checking) compared to the chat task.

Additionally, we note that a stronger KL regularization in the target (14) is known to be beneficial for mitigating over-fitting issue and forgetting on the out-of-domain tasks (Gao et al., ; Lin et al., ; Coste et al., ). On the other hand, (15) allows the model to move more far away, thus achieving a better in-domain performance. Thus, from one perspective, the choice between the above two targets can be viewed as a tradeoff between out-of-domain and in-domain performances. This intuition is also verified by later experiments, where optimizing the second target in (15) leads to better performance on in-domain test sets. In the rest of this section, we discuss two learning objectives to fully develop the multi-turn preference learning framework. We also conduct an ablation study on these objectives in the experimental section.

#### Algorithmic framework.

We present a general online iterative algorithmic framework in Algorithm 1. This framework is termed as Online Iterative Multi-turn Gibbs Sampling
from Human Feedback (M-GSHF) to highlight the online iterative training process and the optimal condition derived in (7) that the optimal policy is a layer-wise Gibbs distribution, which generalizes the bandit formulation in . Specifically, starting from $\pi_{0}$, at each iteration, we first collect a pair of trajectories by the current policy pair, where the preference signal is also revealed according to Definition 1. Then, we update our policy pair given the data collected so far and the next iteration begins. We now discuss some features of the framework as follows.

Policy choice for exploration-exploitation trade-off. We update our behavior policies in a non-symmetric way. The first agent, which aims to extract the historical information we have gathered so far, planning with respect to the empirically best model on the historical dataset $\mathcal{D}$ to get $\pi_{t}^{1}$, where the planning algorithms have been discussed in Section 2.2, e.g., optimizing the M-DPO or M-KTO loss in (12) or (13). However, it is widely recognized in RL studies (Sutton and Barto, ; Auer et al., ) that simply exploiting the historical data via following the empirically best model is not sufficient to obtain a good final policy, while it is also required to explore the environment so that new information can be collected to facilitate subsequent learning, i.e., the exploration-exploitation tradeoff. While the main agent targeting exploitation, we design the second agent, in contrast, to strategically incorporate the uncertainty of the future relative to $\pi_{t}^{1}$ given the historical information we collect so far into its policy choice. We call the policy of the second agent $\pi_{t}^{2}$ as an exploration policy because it serves to explore the underlying environment and facilitate the first agent’s learning. In practice, this principle of exploration is generally interpreted as maximizing the difference between the two behavior policies or increasing the diversity of the collected data. We summarize some popular heuristic exploration policy adopted in the online iterative RLHF practice:

- •
Mixture sampling: in the Claude project (Anthropic, ), the authors choose to use the checkpoints from different training steps to collect data;
- •
Inference parameters tuning: in the LLaMA project (Touvron et al., ), the authors carefully tune the sampling temperature to balance data diversity and data quality;
- •
West-of-n sampling: Xu et al. (); Hoang Tran (); Pace et al. (); Dong et al. () samples n responses per prompt and extract the best one and the worst one (based on some ranking criteria) to construct a preference pair.

We will explore the mixture sampling in the experimental section and also provide a theoretical justification in the next subsection.

Reference model choice for controlling regularization level. Despite two different learning targets are discussed in (14) and (15) seperately, we note that one general algorithmic framework can be adopted with the reference model choice taking as a hyper-parameter to control the regularization level and account for the two targets:

- •
KL-regularized target in (14): if we fix the reference model as the initial policy, i.e., $\pi_{t,\mathrm{ref}}=\pi_{0},\forall t\in[T]$, we always search the optimal policy within the KL ball centered at $\pi_{0}$, and thus optimize the KL-regularized target.
- •
Non-regularized target in (15): in contrast, inspired by the mirror descent (Nemirovskij and Yudin, ), if we update the reference policy every iteration to be the policy learned in the last iteration, i.e., $\pi_{t,\mathrm{ref}}=\pi^{1}_{t-1},\forall t\in[T]$, the cumulative update can make the model to move away from the original $\pi_{0}$ (while a constraint is made on the per-iteration update magnitude) and we thus optimize the non-regularized target.

A graphical illustration is provided in Figure 2 to facilitate the understanding.

Figure: Figure 2: Illustration of the difference between the two learning objectives. The left-hand figure corresponds to the KL-regularized target where we do not update the reference model. The right-hand figure corresponds to the non-regularized target where we always update the reference model as the last-iteration one.
Refer to caption: extracted/5831478/figs/kl_ball.png

Figure: Algorithm 1 Online Iterative M-GSHF

### 2.4 Theoretical Results

In this section, we show that the multi-turn RLHF problem can be solved in a statistically efficient manner under standard assumptions in learning theory literature. In particular, for generality, we target the most challenging scenario with stochastic and unknown transitions, while as aforementioned, multi-turn mathematical reasoning with external tools falls into an relatively easier regime with deterministic transitions. Here we mostly studies the KL-regularized target due to the lack of theoretical research on it. The other target of optimizing the rewards has been theoretically studied in Wang et al. () while the techniques of analyzing mirror-descent-style algorithm and corresponding guarantees have also be developed in Cai et al. (), which can be migrated to considering preference feedbacks. Also, to ease the presentation, we consider the scenario with batch size $m=1$, while the results can be easily generalized to large batches.

First, to measure the online learning process, we define the optimal policy as

$$ $\pi^{*}:=\mathop{\mathrm{argmax}}_{\pi}J(\pi):=J(\pi;\mathcal{M}^{*},\pi_{0}),$ (16) $$

and introduce the standard notion of regret as

$$ $\text{Reg}(T):=\sum_{t\in[T]}J(\pi^{*})-J(\pi^{1}_{t}),$ (17) $$

which represents the cumulative performance loss over $T$ steps comparing the learned policies $[\pi_{t}^{1}]_{t=1}^{T}$ against the optimal policy $\pi^{*}$. In addition, we consider that a bounded $u^{*}(x,y)\in[0,B]$ for all $(x,y)$ to maintain a reasonable utillity regime. Also, it is assumed that we have accesses to the following policy improvement oracle, that is analogue to the one considered in .

###### Definition 3 (Policy Improvement Oracle) .

For any model $\mathcal{M}=({\mathcal{S}},\mathcal{A},H,\mathbb{P},d_{0},u)$ and a reference function $\pi_{\mathrm{ref}}$, we can compute the optimal policy associated with the model $[\pi_{\mathcal{M},h}]_{h=1}^{H}$ iteratively as in (7).

The overall algorithm, i.e., the theoretical version of online iterative M-GSHF, is also summarized in Algorithm 1. At each round $t$, with $\mathcal{D}=\cup_{i=1}^{t-1}\mathcal{D}_{i}$ as the aggregated dataset, it starts with performing a maximum likelihood estimation (MLE) of the reward function $u^{*}$ over a set $\mathcal{U}$, whose elements are bounded in $[0,B]$, as

$$ $\hat{u}_{t}=\mathop{\mathrm{argmax}}_{\hat{u}\in\mathcal{U}}L_{t}(\hat{u}):= \sum_{(x,\tau^{1},\tau^{2},z)\in\cup_{i=1}^{t-1}\mathcal{D}_{i}}\Big{[}z\log( \sigma(\hat{u}(\tau^{1})-\hat{u}(\tau^{2})))+(1-z)\log(\sigma(\hat{u}(\tau^{2} )-\hat{u}(\tau^{1})))\Big{]},$ (18) $$

and also an MLE of the transition kernel $\mathbb{P}^{*}$ over a set $\mathcal{P}$ as

$$ $\hat{\mathbb{P}}_{t}=\mathop{\mathrm{argmax}}_{\hat{\mathbb{P}}\in\mathcal{P}} L_{t}(\hat{\mathbb{P}}):=\sum_{(\pi,\tau)\in\cup_{i=1}^{t-1}\mathcal{D}_{i}} \log\hat{\mathbb{P}}^{\pi}(\tau),$ (19) $$

where $\mathbb{P}^{\pi}(\tau)$ denotes the probability of trajectory $\tau$ under policy $\pi$ and transition kernel $\mathbb{P}$. With the obtained model $\hat{\mathcal{M}}_{t}=(\hat{u}_{t},\hat{\mathbb{P}}_{t})$, the Oracle defined in Definition 3 is called with the reference policy $\pi_{\mathrm{ref}}$ set as the initial policy $\pi_{0}$, whose output is adopted as the main policy $\pi^{1}_{t}$.

Then, we specify how to choose a theoretically sound exploration policy $\pi_{t}^{2}$. The previous work of on single-turn RLHF has demonstrated the intuition that the exploration policy should be in charge of collecting information of the uncertain parts of the environment $\mathcal{M}$, which is thus often selected to maximize one uncertainty measurement. In the multi-turn RLHF setup considered in this work, the following proposition serves as the cornerstone to find a suitable uncertainty measurement to decide the exploration policy. In particular, we can observe that the optimal policy is parameterized by the optimal $Q$-function. If a different set of $Q$-function is adopted for policy parameterization, we can bound its performance as follows.

###### Proposition 1 (Value Decomposition Lemma for KL-regularized MDP) .

If considering a set of $Q$-functions $[\hat{Q}_{h}]_{h=1}^{H}$ and a reference policy $\pi_{\mathrm{ref}}$ with the induced policy $\hat{\pi}$ as

$$ $\displaystyle\hat{\pi}_{h}(a_{h}|s_{h})\propto\pi_{\mathrm{ref},h}(a_{h}|s_{h} )\cdot\exp\left(\hat{Q}_{h}(s_{h},a_{h})/\eta\right),$ $$

and the corresponding set of $V$-functions $[\hat{V}_{h}]_{h=1}^{H}$ as

$$ $\displaystyle\hat{V}_{h}(s_{h})=\mathbb{E}_{a_{h}\sim\hat{\pi}_{h}(\cdot|s_{h} )}\left[\hat{Q}_{h}(s_{h},a_{h})\right]-\eta D_{\mathrm{KL}}(\hat{\pi}_{h}( \cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{h})),\qquad\hat{V}_{H+1}(s_{H+1})=0,$ $$

for any comparator policy $\pi$, it holds that

$$ $\displaystyle J(\pi)-J(\hat{\pi})$ $\displaystyle=\mathbb{E}_{d_{0},\pi,\mathbb{P}^{*}}[u^{*}(s_{H},a_{H})]- \mathbb{E}_{d_{0},\hat{\pi},\mathbb{P}^{*}}[u^{*}(s_{H},a_{H})]$ $\displaystyle+\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi,\mathbb{P}^{*}}\left[\hat{V} _{h+1}(s_{h+1})-\hat{Q}_{h}(s_{h},a_{h})\right]-\sum_{h\in[H]}\mathbb{E}_{d_{0 },\hat{\pi},\mathbb{P}^{*}}\left[\hat{V}_{h+1}(s_{h+1})-\hat{Q}_{h}(s_{h},a_{h })\right]$ $\displaystyle-\eta\cdot\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi,\mathbb{P}^{*}} \left[D_{\mathrm{KL}}(\pi_{h}(\cdot|s_{h}),\hat{\pi}_{h}(\cdot|s_{h}))\right],$ $$

where the expectation $\mathbb{E}_{d_{0},\pi,\mathbb{P}^{*}}$ is with respect to the prompt and response (i.e., the trajectory) generated following $d_{0},\mathbb{P}^{*}$ and $\pi$.

Based on Proposition 1, the exploration policy $\pi_{t}^{2}$ is selected as

$$ $\displaystyle\pi_{t}^{2}=\mathop{\mathrm{argmax}}_{\pi}\max_{\widetilde{u}\in \widetilde{\mathcal{U}}_{t},\widetilde{\mathbb{P}}\in\widetilde{\mathcal{P}}_{ t}}$ $\displaystyle\underbrace{\mathbb{E}_{d_{0},\pi,\widetilde{\mathbb{P}}}\left[ \widetilde{u}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\widetilde{ \mathbb{P}}}\left[\widetilde{u}(s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0}, \pi,\widetilde{\mathbb{P}}}\left[\hat{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d _{0},\pi^{1}_{t},\widetilde{\mathbb{P}}}\left[\hat{u}_{t}(s_{H},a_{H})\right] \right)}_{\text{uncertainty measurement of reward estimation}}$ $\displaystyle+\underbrace{\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi,\widetilde{ \mathbb{P}}}\left[\hat{V}_{t,h+1}(s_{h+1})-\left[\hat{\mathbb{P}}_{t,h}\hat{V} _{t,h+1}\right](s_{h},a_{h})\right]}_{\text{uncertainty measurement of transition estimation}},$ (20) $$

where $\widetilde{\mathcal{U}}_{t}$ and $\widetilde{\mathcal{P}}_{t}$ are two confidence sets defined as

$$ $\displaystyle\widetilde{\mathcal{U}}_{t}$ $\displaystyle=\{u\in\mathcal{U}:L_{t}(u)\geq L_{t}(\hat{u}_{t})-c_{1}\log(| \mathcal{U}|T/\delta)\},$ (21) $\displaystyle\widetilde{\mathcal{P}}_{t}$ $\displaystyle=\{\mathbb{P}\in\mathcal{P}:L_{t}(\mathbb{P})\geq L_{t}(\hat{ \mathbb{P}}_{t})-c_{1}\log(|\mathcal{P}|T/\delta)\}$ $$

with $c_{1}$ denoting an absolute constant here. Note that for the theoretical convenience, we have assumed $\mathcal{U}$ and $\mathcal{P}$ are finite here, which can be extended to the infinite case using standard discretization techniques.
It can be observed that $\pi_{t}^{2}$ is selected to maximize a combination of uncertainty from estimations of both rewards and transitions. If considering known transitions (i.e., without the need to estimate $\mathbb{P}$), the uncertainty from the estimation of transitions dimimishes, which leads to a similar uncertainty measurement adopted in .

The following theorem establishes a rigorous guarantee for the regret incurred.

###### Theorem 1 .

Assuming $u^{*}\in\mathcal{U}$ and $\mathbb{P}^{*}\in\mathcal{P}$, with probability at least $1-\delta$, we have that

$$ $\displaystyle\textup{Reg}(T)\lesssim$ $\displaystyle\kappa^{-1}B\sqrt{d_{\mathcal{U}}T\log(|\mathcal{U}|T/\delta)}+B^ {2}H\xi(d_{\mathcal{P}},T,c_{2}\log(|\mathcal{P}|HT/\delta))$ $\displaystyle-\eta\cdot\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{*},\mathbb{P}^{*}} \left[D_{\mathrm{KL}}(\pi^{*}_{h}(\cdot|s_{h}),\pi^{1}_{t,h}(\cdot|s_{h})) \right],$ $$

where $\kappa:=1/(2+\exp(-B)+\exp(B))$, $c_{2}$ is an absolute constant, $d_{\mathcal{U}}$ is the Eluder coefficient defined in Definition 4 while $d_{\mathcal{P}}$ and $\xi(\cdot)$ are from the generalized Eluder-type condition defined in Definition 5.

We note that the Eluder coefficient and the generalized Eluder-type condition are standard and well-adopted conditions in the theoretical studies on RL (Zhang, ; Zhong et al., ; Liu et al., ; Xie et al., ; Agarwal et al., ) and also RLHF (Zhan et al., ; Wang et al., ; Ye et al., ). Moreover, for a board class of RL problems (see Zhang (); Liu et al. () for more details), the Eluder coefficient $d_{\mathcal{U}}$ is small and the condition is satisfied with $\xi(d_{\mathcal{P}},T,c_{2}\log(|\mathcal{P}|HT/\delta))\lesssim\sqrt{d_{
\mathcal{P}}T\log(|\mathcal{P}|HT/\delta)}$, which implies that the regret of theoretical version of Algorithm 1 is sublinear in $T$, further evidencing its statistical efficiency.

###### Definition 3 (Policy Improvement Oracle) .

###### Proposition 1 (Value Decomposition Lemma for KL-regularized MDP) .

###### Theorem 1 .

## 3 Experiments

### 3.1 Experiment Setup

#### Task, and datasets.

We use the test sets of MATH (Hendrycks et al., ) and GSM8K (Cobbe et al., ) to measure the model’s ability to solve the mathematical problems. The MATH dataset includes 5K problems across diverse mathematical fields such as algebra, geometry, probability, number theory, and calculus. The GSM8K test set consists of 1319 grade-school math word problems, which are generally simpler than those in the MATH dataset. Examples from each dataset are as follows:

- •
GSM8K: 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?
- •
MATH: Find the center of the circle with equation $x^{2}-6x+y^{2}+2y=9$.

To effectively solve these problems, the model needs to perform multi-turn reasoning and arithmetic operations before getting the final answer. To construct the training prompt set, we follow Gou et al. (); Yu et al. (); Yue et al. (); Liu and Yao (); Toshniwal et al. () to use an augmented prompt set from the 7.5K training problems of MATH and 7.47K training problems of GSM8K. In particular, we use the prompts from MetaMathQA (Yu et al., ) and MMIQC (Liu and Yao, ). The new questions include rephrasing question, backward question (starting with the final answer and thinking backward to determine an unknown variable in the original question), and bootstrapping questions by in-context learning and iterative question composing (Liu and Yao, ). We delete the duplicate questions and also ensure that none from the test sets of MATH and GSM8K were used. Eventually, we have 60K training prompts in total for training and randomly split them into three disjoint sets for iterative training. We also reserve a set of 1K prompts for model selection during the training.

#### Base models.

We train with a range of base models, including Gemma-1.1-it-7B (Team et al., ), CodeGemma-1.1-it-7B (Team, ), Mistral-7B-v0.3 (Jiang et al., ), and Gemma2-it-9B. We use the pre-trained version of Mistral instead of the instruction version because the chat template of its huggingface checkpoint and that of their own code base are not consistent so we start from the pre-trained model and fine-tune it by ourselves.

#### Data format and generation.

We format the data into a multi-turn chat where the user initially ask the LLMs a question, and provide the messages returned by the Python interpreter in the subsequent user rounds of chat. In each model turn, the model reasons based the history gathered so far and can output a final answer enclosed in $\backslash$boxed, or call the Python interpreter by writing a code wrapped in ```python and ```. After receiving the response of the model, we return the execution result of the code if the model calls the tool, and stop if the model outputs the final answer or reaches the maximal number of rounds H (6 in our setting). See Figure 1 for an illustration. We generated N=30 samples per prompt for each iteration using a temperature setting of 1.0, without employing top-K or top-p sampling. We employ a mixture sampling strategy, where the up-to-date model generates only 20 trajectories, and the remainder (10 trajectories) are collected using the model from the last iteration. For the initial iteration, we employed models fine-tuned for 3 epochs and 1 epoch, respectively, to conduct mixture sampling. Intuitively, the mixture sampling helps to improve the diversity of the collected samples, and have been employed in previous RLHF practices (Bai et al., ; Dong et al., ). For all the data generation process, we adopt the following constraints: (1) for each turn, the model can generate up to 512 tokens; (2) the maximal number of steps is H=6; (3) the maximal number of token for each trajectory is 2048.

#### Supervised fine-tuning (SFT).

We first fine-tune the model for the tool-integrated reasoning task (Gou et al., ), using a subset of the Open-MathInstruct dataset, which was generated by the permissively licensed Mixtral-8x7B model through in-context learning. The problems are from the training sets of MATH and GSM8K datasets. We restrict the number of samples for each question to be $50$ and remove the nearly duplicate responses. Eventually we get 510K samples in the SFT dataset. We train the models for 4 epochs at most with a learning rate of 5e-6 for Gemma instruct models (Team et al., ) and a learning rate of 1e-5 for Mistral-v0.3 model (Jiang et al., ). The learning rates are determined by searching {2e-6, 5e-6, 1e-5}. We use the pretrained model of Mistral because the chat template of Mistral instruct models are not consistent in different code bases (huggingface and the official one) at the time of our experiments. We use a cosine learning rate scheduler and set the warm-up steps as 100. The samples are packed into blocks with length 4096 to accelerate training and a global batch size of 64 is used. We also mask all the user messages (i.e., the prompt and the messages returned by the Python interpreter) in the training. It takes roughly 10-15 hours when training with 8xA100 80G GPUs. The checkpoint at the end of the third epoch is used for Gemma and the checkpoint of the end of the second epoch is used for Mistral as the starting point for RLHF. This is because these models outperform the last-iteration one with considerable margin and is very close to the next one. An ablation study on the SFT epochs is also included.

#### Data Annotation.

For each prompt, we first divide the responses into the winning set $G^{w}$ and the losing set $G^{l}$ by checking the final answer. In practice, we observe that the model can memorize the final answer and output it even though the reasoning path itself is incorrect. To mitigate this issue, we include some heuristic filtering process. First, we delete all the trajectories in the winning set where the returned messages in the second last round indicate the code is with some bugs, but the models just ignore it and predict the ground-truth answer. Then, we delete the responses in both the winning set $G^{w}$ and losing set $G^{l}$ if they are longer than 2048 tokens. Finally, we randomly sample a trajectory from the $G^{w}$ and a trajectory from $G^{l}$ to construct a pair or to add them into the training set of KTO algorithm. For each iteration, we typically get 15K-20K samples because some of the prompts may not have any correct answer. We notice that it is possible to leverage AI feedback like Gemini (Team et al., ) or GPT4 (OpenAI, ) to further verify the correctness of the trajectory step by step or construct a PRM (Lightman et al., ; Wang et al., ) to rank the trajectories, which we leave for future work.

#### Implementation of M-DPO and M-KTO.

To implement the M-DPO, we simply set the labels of all the user-turn tokens to be -100 and mask the log-probability in the subsequent loss computation. We train the model for 1 epoch at most and tune the learning rate in {2e-7, 4e-7, 7e-7, 1e-6} with the first iteration of iterative training. Eventually, the learning rate of 4e-7 is used for Gemma-1.1 models and 2e-7 is used for Gemma-2 model and Mistral model. The global batch size is 32 with a warm-up step of 40. We evaluate the model every 50 training steps by the split prompt set and the best model is typically obtained between 150 steps to 600 steps, which is expected because the prompts for SFT and prompts for RLHF are overlapped. This has also been observed in previous work of RLHF for making general chatbot (Lin et al., ). Further exploration of prompt scaling is also left for future work. The hyper-parameters are of M-KTO are mostly the same as the M-DPO. We also set the $\lambda_{+}=\lambda_{-}=1$ following the original KTO paper (Ethayarajh et al., ). The RLHF experiments of this paper are run with 8xA100 80G GPUs, where an additional machine with 8xA100 40G GPUs is also used for data collection and model evaluation. The main experiment of this paper can be reproduced by 24 - 48 hours with this setup. We defer some other implementation details to Appendix B due to space constraint.

### 3.2 Main Results

We evaluate the models in the zero-shot setting and report the main results in Table 1.

#### Baselines.

The existing literature mainly focuses on the synthetic data generation and teach the models to use the external tool by supervised fine-tuning on the collected data. We use the results from Toshniwal et al. () as baselines because we use the same SFT dataset so the results are generally comparable. For the CoT baselines, we use the Wizardmath models from Luo et al. (). We also include the reward ranked fine-tuning (RAFT) as a baseline (Dong et al., ), which is also known as rejection sampling fine-tuning in the literature (Touvron et al., ). RAFT first collects N trajectories per prompt, filters the low-quality data (by reward function), and fine-tune on the selected trajectories. Another baseline is the single-turn online iterative DPO and KTO (Rafailov et al., ; Ethayarajh et al., ), which ignores the problem structure (i.e., the external messages) and treats the trajectory as a whole. In implementation, it means that we do not mask the user turn and the tokens of external messages also contribute to the loss.

**Table 1: Main results of different methods on the test sets of GSM8K and MATH. The SFT training with external tool is based on (a subset of) Open-MathInstruct so the results are generally comparable to the previous SFT models. $\dagger$: the model also serves as the starting checkpoint of other methods except for prompting and CoT without tool use. All the models are allowed to use code interpreter except for the CoT without tool use. The results of the CoT methods are borrowed from the technical reports (Toshniwal et al., ; Gou et al., ). The gains relative to the SFT starting checkpoint is marked by $\uparrow$.**
| Base Model | Method | with Tool | GSM8K | MATH | AVG |
| --- | --- | --- | --- | --- | --- |
| WizardMath-7B | SFT for CoT | ✗ | 54.9 | 10.7 | 32.8 |
| WizardMath-13B | SFT for CoT | ✗ | 63.9 | 14.0 | 39.0 |
| WizardMath-70B | SFT for CoT | ✗ | 81.6 | 22.7 | 52.2 |
| CodeLLaMA-2-7B | SFT | ✓ | 75.9 | 43.6 | 59.8 |
| CodeLLaMA-2-13B | SFT | ✓ | 78.8 | 45.5 | 62.2 |
| CodeLLaMA-2-34B | SFT | ✓ | 80.7 | 48.3 | 64.5 |
| LLaMA-2-70B | SFT | ✓ | 84.7 | 46.3 | 65.5 |
| CodeLLaMA-2-70B | SFT | ✓ | 84.6 | 50.7 | 67.7 |
| Gemma-1.1-it-7B | SFT^† | ✓ | 77.5 | 46.1 | 61.8 |
| Gemma-1.1-it-7B | RAFT | ✓ | 79.2 | 47.3 | 63.3 |
| Gemma-1.1-it-7B | Iterative Single-turn DPO | ✓ | 81.7 | 48.9 | 65.3 |
| Gemma-1.1-it-7B | Iterative Single-turn KTO | ✓ | 80.6 | 49.0 | 64.8 |
| Gemma-1.1-it-7B | Iterative M-DPO + fixed reference | ✓ | 79.9 | 48.0 | 64.0 |
| Gemma-1.1-it-7B | M-DPO Iteration 1 | ✓ | 81.5 | 49.1 | 65.3 |
| Gemma-1.1-it-7B | M-DPO Iteration 2 | ✓ | 82.5 | 49.7 | 66.1 |
| Gemma-1.1-it-7B | M-DPO Iteration 3 | ✓ | 83.9  $\uparrow$6.4 | 51.2  $\uparrow$5.1 | 67.6  $\uparrow$5.8 |
| Gemma-1.1-it-7B | Iterative M-KTO | ✓ | 82.1  $\uparrow$4.6 | 49.5  $\uparrow$3.4 | 65.8  $\uparrow$4.0 |
| CodeGemma-1.1-it-7B | SFT^† | ✓ | 77.3 | 46.4 | 61.9 |
| CodeGemma-1.1-it-7B | RAFT | ✓ | 78.8 | 48.4 | 63.6 |
| CodeGemma-1.1-it-7B | Iterative Single-turn DPO | ✓ | 79.1 | 48.9 | 64.0 |
| CodeGemma-1.1-it-7B | Iterative Single-turn KTO | ✓ | 80.2 | 48.6 | 64.4 |
| CodeGemma-1.1-it-7B | Iterative M-DPO | ✓ | 81.5  $\uparrow$4.2 | 50.1  $\uparrow$3.7 | 65.8  $\uparrow$4.0 |
| CodeGemma-1.1-it-7B | Iterative M-KTO | ✓ | 81.6  $\uparrow$4.3 | 49.6  $\uparrow$3.2 | 65.6  $\uparrow$3.8 |
| Mistral-7B-v0.3 | SFT^† | ✓ | 77.8 | 42.7 | 60.3 |
| Mistral-7B-v0.3 | RAFT | ✓ | 79.8 | 43.7 | 61.8 |
| Mistral-7B-v0.3 | Iterative Single-turn DPO | ✓ | 79.8 | 45.1 | 62.5 |
| Mistral-7B-v0.3 | Iterative Single-turn KTO | ✓ | 81.3 | 46.3 | 63.8 |
| Mistral-7B-v0.3 | Iterative M-DPO | ✓ | 82.3  $\uparrow$4.5 | 47.5  $\uparrow$4.8 | 64.9  $\uparrow$4.7 |
| Mistral-7B-v0.3 | Iterative M-KTO | ✓ | 81.7  $\uparrow$3.9 | 46.7  $\uparrow$4.0 | 64.2  $\uparrow$4.0 |
| Gemma-2-it-9B | SFT^† | ✓ | 84.1 | 51.0 | 67.6 |
| Gemma-2-it-9B | RAFT | ✓ | 84.2 | 52.6 | 68.4 |
| Gemma-2-it-9B | Iterative Single-turn DPO | ✓ | 85.2 | 53.1 | 69.2 |
| Gemma-2-it-9B | Iterative Single-turn KTO | ✓ | 85.4 | 52.9 | 69.2 |
| Gemma-2-it-9B | Iterative M-DPO | ✓ | 86.3  $\uparrow$2.2 | 54.5  $\uparrow$3.5 | 70.4  $\uparrow$2.9 |
| Gemma-2-it-9B | Iterative M-KTO | ✓ | 86.1  $\uparrow$2.0 | 54.5  $\uparrow$3.5 | 70.3  $\uparrow$2.8 |

From the first two sections in Table 1, we first observe that the tool-integrated LLMs significantly outperform their CoT counterparts with only SFT, demonstrating the benefits of leveraging external tools. In the subsequent discussions, we focus on the comparison within the scope of tool-integrated LLMs.

#### Iterative M-DPO and M-KTO considerably improve the SFT models.

We observe that for all the four base models, after the iterative training with M-DPO or M-KTO, the resulting model outperforms their starting SFT checkpoint with considerable margins on both GSM8K and MATH. In particular, with M-DPO, the aligned Gemma-1.1-it-7B model attains accuracies of 83.9% and 51.2% on GSM8K and MATH, respectively, and is comparable to the open-source Open-MathInstruct-finetuned CodeLLaMA-2-70B (slightly worse on GSM8K but also slightly better on MATH). Moreover, the aligned Gemma-2-it-9B model achieves accuracies of 86.3% and 54.5% on GSM8K and MATH, surpassing all of the open-source models trained with Open-MathInstruct in the 7B to 70B range. Overall, our framework can robustly further boost the tool-integrated models’ ability on the top of supervised fine-tuning.

#### Iterative M-DPO and M-KTO surpass existing RLHF baselines.

We also observe that the iterative M-DPO and M-KTO surpass other existing RLHF baselines. First, they consistently and significantly outperform the RAFT algorithm across all four base models, which is known to be a robust and competitive baseline in the literature (Dong et al., ; Yuan et al., ). This is because the RAFT algorithm only utilizes the positive signal by imitating the correct trajectories, while the DPO-based and KTO-based algorithms further leverage the negative signal from those incorrect trajectories. We note that the SFT stage in our pipeline can also be viewed as an application of RAFT, an idea that further dates back to expert iteration (Anthony et al., ). Consequently, our results should be interpreted to be that on the top of the first stage of SFT, algorithms with negative signal are more sample efficient. Moreover, while the online iterative single-turn DPO (KTO) (; Xu et al., ) also gives a boost performance, it is generally worse than the multi-turn version. This suggests that learning to predict the off-policy external messages returned by the code interpreter usually has a negative impact on the reasoning ability improvement. Essentially, this corresponds to the fact that when deriving the optimality condition of the KL-regularized optimization problem, we are not allowed to optimize the external messages. Meanwhile, we present a representative example we encounter in Figure 3, where LLMs generate poorly constructed code resulting in anomalous and lengthy external messages. Forcing LLMs to learn to predict these messages can significantly hurt the model’s reasoning abilities.

Figure: Figure 3: An example of external messages returned by the Python interpreter. The model writes down a bad python code leading to an anomalous and lengthy error message.
Refer to caption: extracted/5831478/figs/observation.png

#### Iterative training and reference update lead to better performance.

We use the Gemma-1.1-it-7B and M-DPO as a representative example and observe that the model benefits from online iterative training, where the test accuracy of GSM8K improves from 77.5% (SFT) to 81.5% (iter 1) to 82.5% (iter2) to 83.9% (iter3), and the test accuracy of MATH improves from 46.1% (SFT) to 49.1% (iter 1) to 49.7% (iter2) to 51.2% (iter3). This is consistent with our theoretical insight that iterative training allows the models to explore the underlying space and learn the optimal policy progressively. Moreover, we observe that if we fix the reference model as the SFT policy, the final model performance is much worse compared to the case where we update the reference model as the current model at every iteration. We suspect that this is because this version of algorithm essentially optimizes the non-regularized reward and the reward in the mathematical reasoning task is more accurate than those in the general chat task, leading to the superior in-domain performance. We defer a more detailed ablation study on the impact of KL regularization to next subsection.

Figure: Figure 4: The pass@n rate with respect to the number of candidates n. We evaluate the models using temperature 0.7 following the previous works Shao et al. (); Toshniwal et al. (). We notice that preference learning only improves the metric pass@n when n is relatively small.
Refer to caption: x1.png

#### Preference learning improves pass@n only when n is relatively small.

We plot the pass@n accuracy in terms of the number of candidate trajectories n in Figure 4. To evaluate the pass@n, for each question, we independently sample n trajectories, and the question is considered to be solved if there exists at least one trajectory with the correct final answer. We observe that the preference learning only improves the pass@n when n is relatively small. In particular, when $n>16$, all the models perform similarly on both GSM8K and MATH. In other words, the iterative M-DPO does not inject new knowledge but elicits the models’ knowledge acquired in pre-training and SFT stages by boosting the quality of Top n responses. The observation is consistent with that of Shao et al. (), which studies the DRL-based GRPO method for the CoT mathematical reasoning task. Therefore, the success of preference learning is on top of a well-trained SFT model. We expect that the final model performance can be further improved with more high-quality SFT data.

### 3.3 Ablation Study and Discussion

We conduct ablation studies in this subsection for a more comprehensive understanding of the proposed algorithm.

#### A moderate level of KL regularization balances the per-iteration improvement and exploration efficiency.

The effectiveness of (iterative) DPO is significantly influenced by the choice of reference model and the KL coefficient. Previous research by Tunstall et al. () on offline DPO for general chatbot applications suggests that a lower KL coefficient, specifically 0.01, yields superior performance by allowing the resulting model to move more far away from the SFT model $\pi_{0}$. Meanwhile, for online iterative training, ; Dong et al. () adopt a fixed reference model of $\pi_{0}$, and achieves continuous improvements as the training iterates. In our ablation study, we consider two different choices: (1) using the fixed reference model $\pi_{0}$; (2) updating the reference model to the last iteration’s model at each round. Moreover, we search the KL coefficient $\eta\in\{0.01,0.1,0.5\}$. The results are summarized in Table 2. First, we notice that if we update the reference model at each iteration, the final model outperforms the one with a fixed reference model $\pi_{0}$ with a large margin. Essentially, this dynamic approach optimizes the non-regularized reward, while the one with a fixed reference model $\pi_{0}$ aims to maximize the KL-regularized reward. This can be viewed as a trade-off between the generation diversity and reward optimization. We suspect this performance difference is because for reasoning task, the correct reasoning paths are highly concentrated on a small subset of the generation space, and the diversity is less important in this case.

We also find that the strongest model is obtained by a moderate KL coefficient of $0.1$, outperforming both 0.01 and 0.5. To understand this phenomena, we plot the test accuracy of GSM8K in Figure 5 along the way of iterative training. As we can see, for the first iteration, the results align with Tunstall et al. ()’s findings, where a smaller KL coefficient leads to a larger model improvement. However, the resulting intermediate model is further used to collect trajectories for subsequent iterative training. The models trained with very low KL coefficients tend to lose diversity rapidly, potentially reducing their capacity to collect diverse trajectories for subsequent training, leading to diminishing gains in the second and third iterations. In contrast, a higher KL coefficient of 0.5 imposes strong regularization between the resulting model and the reference model, and the model improvement is less compared to that of $0.1$ for each iteration. To summarize, for online iterative training, we need to strike a balance between the per-iteration improvement and exploration efficiency to optimize the overall performance. We will see that such an intuition also extends to the choices of sampling strategy choice and other experimental tricks.

**Table 2: Ablation study of the impact of KL regularization. The SFT policy is the starting checkpoint for all other experiments.**
| Model | Method | GSM8K | MATH |
| --- | --- | --- | --- |
| Gemma-1.1-it-7B | SFT 3 epoch | 77.5 | 46.1 |
| Gemma-1.1-it-7B | Iterative M-DPO + $\eta=0.01$ | 81.7 | 50.1 |
| Gemma-1.1-it-7B | Iterative M-DPO + $\eta=0.1$ | 83.9 | 51.2 |
| Gemma-1.1-it-7B | Iterative M-DPO + $\eta=0.5$ | 82.8 | 49.7 |
| Gemma-1.1-it-7B | Iterative M-DPO + fixed reference + $\eta=0.1$ | 79.9 | 48.0 |

Figure: Figure 5: The plot of test accuracy on GSM8K dataset and iterations with different levels of KL regularization.
Refer to caption: x3.png

#### The impact of sampling strategy: data diversity and coverage are crucial.

Throughout our iterative training process of the Gemma-1.1-it-7B, we observed a steady increase in the percentage of correct trajectories—from 47% in the first iteration to 76% in last iteration. Moreover, since we update the reference model at each iteration, the diversity of the generated trajectories also decrease rapidly. However, the diversity of the collected data is critical for DPO/KTO training due to their contrastive nature. Prior studies in online iterative DPO for general chatbots (Dong et al., ) recommend employing model variants with different sampling temperatures or training steps to enhance trajectory diversity. Motivated by this, we explored two data collection strategies: (1) on-policy sampling, where all trajectories are sampled using the current policy, and (2) mixture sampling, where 20 trajectories are collected using the current model and 10 from the last iteration’s model. We report the results in Table 5, where with mixture sampling, the final model performance considerably outperform the one with only on-policy sampling. To understand this phenomena, we plot the MATH test accuracy in terms of the iteration in Figure 6. We observe that on-policy sampling fails to improve MATH test accuracy in the third iteration, while we achieve considerable gain with the mixture sampling. This again demonstrates the importance of the diversity of the collected responses in the iterative training and also aligns with previous findings that advanced exploration strategies, which prevent diversity collapse, provide more meaningful signals for iterative preference learning (Bai et al., ; Touvron et al., ; ; Pace et al., ; Dong et al., ). It would be interested to explore more advanced exploration strategy like Monte Carlo tree search (MCTS) in the future study.

In our experiments, we collected N trajectories per prompt to ensure the presence of both correct and incorrect reasoning paths for constructing the comparison pair. A larger N generally leads to a better coverage of the prompt set because for some difficult problem, we need to sample more responses to find a correct reasoning path. For instance, in iteration 1, with N=30, 92.5% of the prompts are covered, compared to 83.0% for N=12 and 60% for N=6. See Figure 4 for an illustration of the relationship between pass@1 and N. However, increasing N also incurs higher computational costs. To understand the impact of the parameter N, we conduct an ablation study with $N\in\{6,12,30\}$ and summarize the results in Table 3. We observe a substantial performance boost when increasing N from 6 to 12, reflecting a better coverage of the complex problems that require more attempts to find a correct path. In contrast, from N=12 to N=30, we only get very minor improvement in the test accuracy, suggesting that the incremental benefits of increasing N in best-of-N sampling diminish rapidly.

**Table 3: Ablation study of the impact of sampling strategy. The SFT policy is the starting checkpoint for all other experiments. Mixture sampling is adopted for the iterative M-DPO training by default and we run for three iterations in total.**
| Model | Method | GSM8K | MATH |
| --- | --- | --- | --- |
| Gemma-1.1-it-7B | SFT 3 epoch | 77.5 | 46.1 |
| Gemma-1.1-it-7B | Iterative M-DPO with N=30 | 83.9 | 51.2 |
| Gemma-1.1-it-7B | Iterative M-DPO with N=12 | 83.5 | 51.2 |
| Gemma-1.1-it-7B | Iterative M-DPO with N=6 | 82.0 | 49.2 |
| Gemma-1.1-it-7B | Iterative M-DPO with N=30 + On-policy sampling | 83.1 | 49.5 |

Figure: Figure 6: The plot of test accuracy on MATH dataset in terms of training iterations with different sampling strategies.
Refer to caption: x4.png

#### The best model is obtained with starting checkpoint fine-tuned with more than 1 epochs.

Tunstall et al. () finds that if the SFT model is trained for more than one epoch, the subsequent DPO training will lead to performance regression with longer training in terms of instruction-following ability and benchmark for a general chatbot. In other words, there exists a trade-off between the SFT training epochs and the DPO training steps. Moreover, the best model is obtained by SFT for one epoch in their practice. We also conduct an ablation study on the impact of the SFT epoch and summarize the results in Table 4. Consistently across all tested scenarios, the subsequent iterative M-DPO training leads to considerable model improvement compared to the SFT model. Meanwhile, we also observe a similar trade-off between SFT and RLHF training because with more SFT epochs, the gains from the RLHF stage decrease. However, in our case, the strongest model is obtained with three epochs of SFT, followed by fine-tuning through iterative M-DPO, which is different from the offline DPO training (Tunstall et al., ) or the iterative DPO for general chatbot (Dong et al., ) with only one epoch of SFT.

**Table 4: Ablation study of the impact of SFT epoch. Mixture sampling is adopted for the iterative M-DPO training and we run for three iterations in total. The gains relative to their starting SFT checkpoints are marked by $\uparrow$.**
| Model | Method | GSM8K | MATH |
| --- | --- | --- | --- |
| Gemma-1.1-it-7B | SFT 1 epoch | 75.1 | 41.1 |
| Gemma-1.1-it-7B | SFT 1 epoch + Iterative M-DPO | 80.6  $\uparrow$5.5 | 46.7  $\uparrow$5.6 |
| Gemma-1.1-it-7B | SFT 2 epoch | 75.3 | 44.0 |
| Gemma-1.1-it-7B | SFT 2 epoch + Iterative M-DPO | 82.4  $\uparrow$7.1 | 49.8  $\uparrow$5.8 |
| Gemma-1.1-it-7B | SFT 3 epoch | 77.5 | 46.1 |
| Gemma-1.1-it-7B | SFT 3 epoch + Iterative M-DPO | 83.9  $\uparrow$6.4 | 51.2  $\uparrow$5.1 |

#### NLL loss helps when the SFT model is substantially underfitting.

The recent work Pang et al. () has introduced iterative RPO, specifically aimed at enhancing Chain of Thought (CoT) capabilities for solving mathematical problems. A key feature of this approach is the inclusion of an additional negative log-likelihood (NLL) loss for the preferred response. The main intuition for adding the NLL loss is that the original DPO algorithm (Rafailov et al., ) tends to reduce the likelihood of the preferred responses, and this is believed to hurt the reasoning ability (Wang et al., ). Motivated by their results, we explored the applicability of this idea to our setup. We conduct an ablation study by adding the NLL loss into the iterative M-DPO training and observe performance regression as reported in Table 5. We observe that the best model is obtained in the second iteration if we add the additional NLL loss even though we use the mixture sampling to increase the diversity of the collected data. With time-weighted exponential moving average for smoothing training record, we observe that the log probability of the chosen responses and rejected responses are (-126, -222) at the 200th step of the third iteration training when we add the NLL loss, as compared to (-166, -350) in the case without the NLL loss. This is consistent with the result of Pang et al. () where with the additional NLL loss, both the log probability of chosen responses and that of rejected responses increase. These evidences indicate that the NLL loss further contributes to the model distribution collapse and eventually hurt the overall performance of online iterative learning. Finally, we notice that the additional NLL loss can be viewed as an implementation of the pessimistic principle (Liu et al., ). This also explains its inferior in-domain performance though it may be helpful to stable the training, which requires more in-depth studies.

However, one distinct feature between our setup and Pang et al. () is whether we first fine-tune the initialized SFT model with in-domain data. To further understand the phenomena, we fine-tune the Gemma-1.1-it-7B with only 100 steps (so that the model knows to leverage Python code to solve the problem) as the starting checkpoint of preference learning and conduct an ablation study with the NLL loss using this model. We observe when the SFT model is substantially underfitting, the addition of NLL loss actually enhances performance. This scenario mirrors the findings of Pang et al. (), who utilized a general LLaMA2-70B-chat model (Touvron et al., ) without firstly fine-tuning on the in-domain data. Our observations align with prior research in the context of developing general chatbots (Lin et al., ), which suggests that RLHF is less effective without preliminary SFT.

**Table 5: Other ablation studies. Mixture sampling is adopted for the iterative M-DPO training and we run for three iterations in total. The gains relative to the iterative M-DPO are marked by $\uparrow$.**
| Model | Method | GSM8K | MATH |
| --- | --- | --- | --- |
| Gemma-1.1-it-7B | SFT 3 epoch | 77.5 | 46.1 |
| Gemma-1.1-it-7B | SFT 3 epoch + Iterative M-DPO | 83.9 | 51.2 |
| Gemma-1.1-it-7B | Iterative M-DPO with NLL loss | 81.7  $\downarrow$2.2 | 49.5  $\downarrow$1.7 |
| Gemma-1.1-it-7B | SFT 100 steps | 50.8 | 23.7 |
| Gemma-1.1-it-7B | + M-DPO Iteration 1 | 57.8 | 27.9 |
| Gemma-1.1-it-7B | + M-DPO and NLL loss Iteration 1 | 61.0  $\uparrow$3.2 | 30.1  $\uparrow$2.2 |

#### On-policy sampling and small learning rate mitigate the probability drops in preferred responses.

In the literature, the Direct Preference Optimization (DPO) algorithm is often reported to diminish reasoning capabilities by reducing the likelihood of preferred responses (Yuan et al., ; Hong et al., ; Meng et al., ). In our preliminary experiments, we also observe similar phenomena with a large learning rate (1e-6), where the model’s reasoning ability collapses after only a few training steps, preventing convergence to good reasoning performance. In contrast, we find that using on-policy sampling within our online iterative training framework, coupled with a smaller learning rate (2e-7 or 4e-7), the DPO algorithm enhances the model’s reasoning abilities. To interpret our observation, we can first write down the gradient of the DPO as follows:

$$ $\displaystyle\nabla_{\theta}\mathcal{L}_{DPO}(\pi_{\theta},\pi_{\mathrm{ref}}) =-\eta\cdot\sigma\Big{(}r_{\theta}(x,y^{l})-r_{\theta}(x,y^{w})\Big{)}\Big{[} \frac{1}{\pi_{\theta}(y^{w}|x)}\nabla_{\theta}\pi_{\theta}(y^{w}|x)-\frac{1}{ \pi_{\theta}(y^{l}|x)}\nabla_{\theta}\pi_{\theta}(y^{l}|x)\Big{]},$ $$

where $r_{\theta}(x,y)=\eta\log\frac{\pi_{\theta}(x,y)}{\pi_{\mathrm{ref}}(x,y)}$ is the implicit reward and we use the single-turn one for simplicity. In practice, the probability of the rejected responses typically decrease, and their gradient quickly dominates when $\pi_{\theta}(y^{l}|x)<<\pi_{\theta}(y^{w}|x)$ and the optimization becomes unlearning of the rejected responses. In this case, the probability of the chosen responses cannot increase. This phenomenon was also discussed in the blog Guo et al. (). When we adopt on-policy sampling, it leads to a relatively large probability for both rejected and chosen responses at the initial stage, ensuring that both gradients remain valid and effective. Moreover, a small learning rate prevents the model from deviating too significantly, maintaining the effectiveness of both gradients. We also notice that for the KTO algorithm, the preferred responses and the rejected responses do not appear in pairs. We suspect that the probability of the preferred response increases because the gradients of the rejected response do not dominate in every mini-batch of data. A more comprehensive understanding of the training dynamic of the direct preference learning algorithms remains largely open and we leave a more detailed study of this phenomena to future study.

## 4 Conclusion, Limitation, and Future Research Direction

We demonstrate that preference learning, as an alternative learning paradigm to supervised fine-tuning, can further boost the performance of the tool-integrated reasoning LLMs on top of iterative best-of-n fine-tuning. We introduce an online iterative multi-turn direct preference optimization algorithm and validate its effectiveness through extensive experimentation across various base models. Our results indicate substantial improvements in the pass@1 metric over the SFT policy, as evidenced by performance gains on standard benchmarks such as GSM8K (Cobbe et al., ) and MATH (Hendrycks et al., ). Additionally, we also conduct various ablation studies to show that achieving optimal performance requires a careful balance between per-iteration improvement and exploration, facilitated by moderate levels of KL regularization and strategic exploration choices.

There are also several potential directions to further improve the model performance that we have not explored in this paper. Currently, our experiments only use final result check as the preference signal, so we cannot effectively compare trajectories that both end with correct or incorrect answers. Although our algorithm is designed for trajectory-level preference learning, the reward signal in the Bradley-Terry model could be adapted to a step-wise level. In particular, we may leverage AI feedback to verify trajectories step by step or train a process-supervised reward model (Lightman et al., ) to provide learning signals. Additionally, with more fine-grained reward signals, it is also possible to adopt more advanced heuristic exploration policy like west-of-n sampling, which prove to be effective in the practice of making general chatbot (Pace et al., ; Dong et al., ; Xu et al., ; Hoang Tran, ) and Monte Carlo tree search (MCTS) (Xie et al., ). Furthermore, it is also possible to leverage some well-established tricks like adaptive margin and length regularization for DPO training (Hong et al., ; Meng et al., ). These techniques have proven to be effective for achieving a better in-domain performance for the chat task. We expect that these more fine-grained preference signals and algorithmic designs can largely improve the models’ performance.

Finally, while the direct preference learning algorithms show promising gains for the mathematical reasoning tasks with code interpreter, it is not directly applicable to the general agent learning with more complex and stochastic external environments or against dynamic opponents. In particular, it requires to construct a value network for involving an adaptive margin in the optimization target and take the randomness of the external environment into consideration. We leave the study of this more involved algorithm to the future work. Moving beyond the framework presented this paper, it is also possible to explore more general preference structures beyond the BT model (Munos et al., ; Ye et al., ). We hope that the insights from this paper will inspire further research in this direction, extending the utility of preference learning beyond the general structured chat tasks.

*

## Appendix A Notation Table

**Table 6: The table of notations used in this paper.**
| Notation | Description |
| --- | --- |
| $x,\mathcal{X}$ | The prompt and the prompt space. |
| $d_{0}$ | The distribution of initial state (prompt). |
| $s_{h}\in{\mathcal{S}},a_{h}\in\mathcal{A},o_{h}$ | The state, action, and observation. |
| $H$ | Episode length, e.g., the maximal number of tool calls. |
| $\mathbb{P}^{*}=[\mathbb{P}^{*}_{h}]_{h=1}^{H}$ | The true observation kernel. |
| $\tau=(x,y)$ | $\tau$ is a trajectory and $y$ is the completion part, i.e., we exclude $x$ from $\tau$. |
| $u^{*}$ | The true utility function associated with the BT model defined in Definition 1. |
| $\mathcal{M}^{*}=({\mathcal{S}},\mathcal{A},H,\mathbb{P}^{*},d_{0},u^{*})$ | The true model with observation kernel $\mathbb{P}^{*}$ and utility function $u^{*}$ |
| $\sigma(\cdot)$ | $\sigma(z)=1/(1+\exp(-z))$ is the sigmoid function. |
| $z\in\{0,1\}$ | Preference signal. |
| $\pi=[\pi_{h}]_{h=1}^{H}$ | The policy, which is parameterized by the LLM. |
| $\mathcal{M}=({\mathcal{S}},\mathcal{A},H,\mathbb{P},d_{0},u)$ | One arbitrary environment with observation kernel $\mathbb{P}$ and utility function $u$. |
| $\pi_{\mathrm{ref}}=[\pi_{\mathrm{ref},h}]_{h=1}^{H}$ | One arbitrary reference policy. |
| $J(\pi;\mathcal{M},\pi_{\mathrm{ref}})$ | The KL-regularized target ((5)) with environment $\mathcal{M}$ and reference $\pi_{\mathrm{ref}}$. |
| $\eta$ | The coefficient of KL penalty, defined in (5). |
| $Q_{\mathcal{M}}=[Q_{\mathcal{M},h}]_{h=1}^{H}$ | The optimal $Q$-values associated with $J(\pi;\mathcal{M},\pi_{\mathrm{ref}})$, defined in (6). |
| $V_{\mathcal{M}}=[V_{\mathcal{M},h}]_{h=1}^{H}$ | The optimal $V$-values associated with $J(\pi;\mathcal{M},\pi_{\mathrm{ref}})$, defined in (7). |
| $\pi_{\mathcal{M}}=[\pi_{\mathcal{M},h}]_{h=1}^{H}$ | The optimal policy associated with $J(\pi;\mathcal{M},\pi_{\mathrm{ref}})$, defined in (7). |
| $\mathcal{L}_{\textup{M-DPO}}(\cdot)$ | M-DPO loss, defined in (12). |
| $\mathcal{L}_{\textup{M-KTO}}(\cdot)$ | M-KTO loss, defined in (13). |
| $J(\pi)$ | The abbreviation of $J(\pi;\mathcal{M}^{*},\pi_{0})$, defined in (16). |
| $\pi^{*}=[\pi^{*}_{h}]_{h=1}^{H}$ | The optimal policy associated with $J(\pi)$. |
| $\pi^{1}_{t},\pi^{2}_{t}$ | The main and exploration policy at round $t$ |
| $\text{Reg}(T)$ | Regret over horizon $T$, defined in (17). |
| $\mathcal{U},\mathcal{P}$ | Known sets such that $u^{*}\in\mathcal{U}$ and $\mathbb{P}^{*}\in\mathcal{P}$ |
| $B$ | Assuming $u^{*}(x,y)\in[0,B],\forall(x,y)$. |
| $\hat{u}_{t},\hat{\mathbb{P}}_{t}$ | MLE of $u^{*}$ and $\mathbb{P}^{*}$ at round $t$, defined in (18) and (19). |
| $\widetilde{\mathcal{U}}_{t},\widetilde{\mathcal{P}}_{t}$ | Confidences sets of $u^{*}$ and $\mathbb{P}^{*}$ at round $t$, defined in (21). |
| $c_{1},c_{2},c$ | Absolute constants. |
| $\kappa$ | $1/(2+\exp(-B)+\exp(B))$. |
| $d_{\mathcal{U}}$ | Eluder coefficient from Definition 4. |
| $d_{\mathcal{P}},\xi(\cdot)$ | Generalized Eluder-type condition from Definition 5. |
| $\mathrm{TV}(\cdot,\cdot)$ | Total variation distance between two distributions. |

## Appendix B Implementation Detail

#### Tools in Math Problem Solving.

Following Gou et al. (); Toshniwal et al. (), the LLM agent is allowed to call the python interpreter when it decodes a python code starting with ```python and ending with ```. For each step $h$, to generate the observation $o_{h}$, we leverage the python package IPython, and run all the codes in the history one by one and treat each code snippet as a Jupyter cell. We only return the standard output or the error message from the last snippet. When there exists some bug in the code, we only return the error message which is typically less than 20 tokens as in Toshniwal et al. (). We notice that some works (e.g. Shao et al. ()) also returns the first and the last 50 tokens of the trackback information.

#### Data Generation.

All the models are evaluated in the zero-shot setting. For all the data generation process, we adopt the following constraints: (1) for each turn, the model can generate up to 512 tokens; (2) the maximal number of steps is H=6; (3) the maximal number of generated token for each trajectory is 2048. When collecting new data for online iterative M-DPO, we set temperature to be 1.0 and decode without top-K or top-p sampling. For evaluation, greedy decoding is employed so that the results are generally comparable with previous works Gou et al. (); Toshniwal et al. (). For evaluating the models with pass@n rate, we follow Toshniwal et al. () to adopt a temperature of $0.7$.

#### Python Experiment Environment.

We find that the evaluation can be influenced by the python environment, the precision (especially for the Gemma-1.1 models), and even the virtual machine we use. This does not affect the overall trend and conclusion because the magnitude of oscillation is relatively small compared to the overall improvement. For completeness, however, we specify some of the key package versions here. We use transformers 4.42.4, torch 2.3.0, sympy 1.2, antlr4-python3-runtime 4.11.0, IPython 8.26.0 for all models. We evaluate the models using torch.float and use vllm 0.5.0.post1 for most the experiments except for Gemma-2 where vllm 0.5.1 is required. The inconsistency of vllm version is because Gemma-2 model was not released when we performed the main experiments of this project. We fix the python environment and machine for our evaluation throughout the experiment. For SFT, we use the open-source axolotl project with version 0.4.1 and for online iterative preference learning and RAFT, we use the code base from RLHF Workflow (Dong et al., ).

#### RAFT implementation.

The data generation step is similar to the online iterative M-DPO training, except that we only keep the trajectories with correct final answer. For each prompt, we sample at most $k$ trajectories where we search $k\in\{1,3,8\}$ and use $k=1$ eventually because we do not see improvement by leveraging more data. We run the algorithm for three iterations in total. The training parameters are similar to the SFT stage, but we use a smaller batch size of 32 so that there are enough optimization steps. For Gemma models, we use a learning rate of 5e-6. For each training stage, we train the models for two epochs in total according to our parameter search. For Mistral model, we find that a smaller learning rate of 1e-6 and training for 1 epoch give us much better performance.

#### Prompt template.

We do not tune the prompt though we do observe that the prompt engineering can further improve the performance. For all the experiments, we simply adopt the chat template of the models as in Figure 1.

## Appendix C Omitted Theoretical Proofs

### C.1 Proof of Proposition 1

###### Proof of Proposition 1 .

For one policy $\pi$, starting with $V^{\pi}_{\mathcal{M},H+1}=0$, we recursively define its $V$-value and $Q$-value functions on one model $\mathcal{M}=({\mathcal{S}},\mathcal{A},H,\mathbb{P},d_{0},u)$ and the reference policy $\pi_{\mathrm{ref}}$ as

$$ $\displaystyle Q^{\pi}_{\mathcal{M},h}(s_{h},a_{h})$ $\displaystyle:=\begin{cases}&u(s_{H},a_{H}),\qquad\text{ if }h=H,\\ &\mathbb{E}_{o_{h}\sim\mathbb{P}_{h}(\cdot|s_{h},a_{h})}[V^{\pi}_{\mathcal{M}, h+1}(s_{h+1})],\qquad\text{ if }h\leq H-1,\end{cases}$ $\displaystyle V^{\pi}_{\mathcal{M},h}(s_{h})$ $\displaystyle:=\mathbb{E}_{a_{h}\sim\pi_{h}(\cdot|s_{h})}\big{[}Q^{\pi}_{ \mathcal{M},h}(s_{h},a_{h})-\eta\cdot D_{\mathrm{KL}}\big{(}\pi_{h}(\cdot|s_{h }),\pi_{\mathrm{ref},h}(\cdot|s_{h})\big{)}\big{]}.$ $$

It is noted that with the optimal policy $\pi_{\mathcal{M}}$, $Q_{\mathcal{M},h}=Q^{\pi_{\mathcal{M}}}_{\mathcal{M},h}$ and $V_{\mathcal{M},h}=V^{\pi_{\mathcal{M}}}_{\mathcal{M},h}$. In the following discussions, we exclusively focus on the model $\mathcal{M}^{*}=({\mathcal{S}},\mathcal{A},H,\mathbb{P}^{*},d_{0},u^{*})$ with abbreviations $Q^{\pi}_{h}=Q^{\pi}_{\mathcal{M}^{*},h}$ and $V^{\pi}_{h}=V^{\pi}_{\mathcal{M}^{*},h}$.

For any comparator policy $\pi$, it holds that

$$ $\displaystyle J(\pi)-J(\hat{\pi})=\mathbb{E}_{d_{0}}\left[V_{1}^{\pi}(s_{1})- \hat{V}_{1}(s_{1})\right]-\mathbb{E}_{d_{0}}\left[V_{1}^{\hat{\pi}}(s_{1})- \hat{V}_{1}(s_{1})\right],$ $$

For any $h\in[H]$, we can obtain that

$$ $\displaystyle\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1}}\left[V_{h}^ {\pi}(s_{h})-\hat{V}_{h}(s_{h})\right]-\mathbb{E}_{d_{0},\hat{\pi}_{1:h-1}, \mathbb{P}^{*}_{1:h-1}}\left[V_{h}^{\hat{\pi}}(s_{h})-\hat{V}_{h}(s_{h})\right]$ $\displaystyle\overset{(a)}{=}\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h -1}}\left[\mathbb{E}_{\pi_{h}}\left[Q_{h}^{\pi}(s_{h},a_{h})\right]-\eta D_{ \mathrm{KL}}\left(\pi_{h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{h})\right )\right]$ $\displaystyle-\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1}}\left[ \mathbb{E}_{\hat{\pi}_{h}}\left[\hat{Q}_{h}(s_{h},a_{h})\right]-\eta D_{ \mathrm{KL}}\left(\hat{\pi}_{h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{h}) \right)\right]$ $\displaystyle-\mathbb{E}_{d_{0},\hat{\pi}_{1:h-1},\mathbb{P}^{*}_{1:h-1}}\left [\mathbb{E}_{\hat{\pi}_{h}}\left[Q_{h}^{\hat{\pi}}(s_{h},a_{h})\right]-\eta D_ {\mathrm{KL}}(\hat{\pi}_{h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{h}))\right]$ $\displaystyle+\mathbb{E}_{d_{0},\hat{\pi}_{1:h-1},\mathbb{P}^{*}_{1:h-1}}\left [\mathbb{E}_{\hat{\pi}_{h}}\left[\hat{Q}_{h}(s_{h},a_{h})\right]-\eta D_{ \mathrm{KL}}(\hat{\pi}_{h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{h}))\right]$ $\displaystyle=\mathbb{E}_{d_{0},\pi_{1:h},\mathbb{P}^{*}_{1:h-1}}\left[Q_{h}^{ \pi}(s_{h},a_{h})-\hat{Q}_{h}(s_{h},a_{h})\right]-\mathbb{E}_{d_{0},\hat{\pi}_ {1:h},\mathbb{P}^{*}_{1:h-1}}\left[Q_{h}^{\hat{\pi}}(s_{h},a_{h})-\hat{Q}_{h}( s_{h},a_{h})\right]$ $\displaystyle+\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1}}\underbrace {\left[\mathbb{E}_{\pi_{h}}\left[\hat{Q}_{h}(s_{h},a_{h})\right]-\mathbb{E}_{ \hat{\pi}_{h}}\left[\hat{Q}_{h}(s_{h},a_{h})\right]\right]}_{\text{term (I)}}$ $\displaystyle-\eta\cdot\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1}} \left[D_{\mathrm{KL}}\left(\pi_{h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{ h})\right)\right]+\eta\cdot\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1 }}\left[D_{\mathrm{KL}}\left(\hat{\pi}_{h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}( \cdot|s_{h})\right)\right]$ $\displaystyle\overset{(b)}{=}\mathbb{E}_{d_{0},\pi_{1:h},\mathbb{P}^{*}_{1:h-1 }}\left[Q_{h}^{\pi}(s_{h},a_{h})-\hat{Q}_{h}(s_{h},a_{h})\right]-\mathbb{E}_{d _{0},\hat{\pi}_{1:h},\mathbb{P}^{*}_{1:h-1}}\left[Q_{h}^{\hat{\pi}}(s_{h},a_{h })-\hat{Q}_{h}(s_{h},a_{h})\right]$ $\displaystyle-\eta\cdot\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1}} \left[D_{\mathrm{KL}}\left(\pi_{h}(\cdot|s_{h}),\hat{\pi}_{h}(\cdot|s_{h}) \right)\right].$ $$

In the above derivation, equation (a) is from the definitions of $Q^{\pi}$ and $V^{\pi}$, and the relationship between $\hat{Q}$ and $\hat{V}$. The equation (b) is because

$$ (term I) $\displaystyle:=\mathbb{E}_{\pi_{h}}\left[\hat{Q}_{h}(s_{h},a_{h})\right]- \mathbb{E}_{\hat{\pi}_{h}}\left[\hat{Q}_{h}(s_{h},a_{h})\right]$ $\displaystyle=\eta\cdot\mathbb{E}_{\pi_{h}}\left[\log\frac{\hat{\pi}_{h}(a_{h} |s_{h})}{\pi_{\mathrm{ref},h}(a_{h}|s_{h})}\right]-\eta\cdot\mathbb{E}_{\hat{ \pi}_{h}}\left[\log\frac{\hat{\pi}_{h}(a_{h}|s_{h})}{\pi_{\mathrm{ref},h}(a_{h }|s_{h})}\right]$ $\displaystyle=\eta\cdot D_{\mathrm{KL}}\left(\pi_{h}(\cdot|s_{h}),\pi_{\mathrm {ref},h}(\cdot|s_{h})\right)-\eta\cdot D_{\mathrm{KL}}\left(\pi_{h}(\cdot|s_{h }),\hat{\pi}_{h}(\cdot|s_{h})\right)-\eta\cdot D_{\mathrm{KL}}\left(\hat{\pi}_ {h}(\cdot|s_{h}),\pi_{\mathrm{ref},h}(\cdot|s_{h})\right).$ $$

where the second equation is from the relationship that

$$ $\displaystyle\hat{Q}_{h}(s_{h},a_{h})=\eta\cdot\log\frac{\hat{\pi}_{h}(a_{h}|s _{h})}{\pi_{\mathrm{ref},h}(a_{h}|s_{h})}-\eta\cdot\log\hat{Z}_{h}(s_{h}).$ $$

Furthermore, if $h=H$, we can obtain that

$$ $\displaystyle\mathbb{E}_{d_{0},\pi_{1:H-1},\mathbb{P}^{*}_{1:H-1}}\left[V_{H}^ {\pi}(s_{H})-\hat{V}_{H}(s_{H})\right]-\mathbb{E}_{d_{0},\hat{\pi}_{1:H-1}, \mathbb{P}^{*}_{1:H-1}}\left[V_{H}^{\hat{\pi}}(s_{H})-\hat{V}_{H}(s_{H})\right]$ $\displaystyle=\mathbb{E}_{d_{0},\pi_{1:H},\mathbb{P}^{*}_{1:H-1}}\left[u^{*}(s _{H},a_{H})-\hat{Q}_{H}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\hat{\pi}_{1:H}, \mathbb{P}^{*}_{1:H-1}}\left[u^{*}(s_{H},a_{H})-\hat{Q}_{H}(s_{H},a_{H})\right]$ $\displaystyle-\eta\cdot\mathbb{E}_{d_{0},\pi_{1:H-1},\mathbb{P}^{*}_{1:H-1}} \left[D_{\mathrm{KL}}\left(\pi_{H}(\cdot|s_{H}),\hat{\pi}_{H}(\cdot|s_{H}) \right)\right]$ $\displaystyle=\mathbb{E}_{d_{0},\pi_{1:H},\mathbb{P}^{*}_{1:H-1}}\left[u^{*}(s _{H},a_{H})\right]-\mathbb{E}_{d_{0},\hat{\pi}_{1:H},\mathbb{P}^{*}_{1:H-1}} \left[u^{*}(s_{H},a_{H})\right]$ $\displaystyle+\mathbb{E}_{d_{0},\pi_{1:H},\mathbb{P}^{*}_{1:H}}\left[\hat{V}_{ H+1}(s_{H+1})-\hat{Q}_{H}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\hat{\pi}_{1:H },\mathbb{P}^{*}_{1:H}}\left[\hat{V}_{H+1}(s_{H+1})-\hat{Q}_{H}(s_{H},a_{H})\right]$ $\displaystyle-\eta\cdot\mathbb{E}_{d_{0},\pi_{1:H-1},\mathbb{P}^{*}_{1:H-1}} \left[D_{\mathrm{KL}}\left(\pi_{H}(\cdot|s_{H})||\hat{\pi}_{H}(\cdot|s_{H}) \right)\right],$ $$

where the second equality leverages that $\hat{V}_{H+1}(s_{H+1})=0$;
otherwise, for all $h\leq H-1$, it holds that

$$ $\displaystyle\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1}}\left[V_{h}^ {\pi}(s_{h})-\hat{V}_{h}(s_{h})\right]-\mathbb{E}_{d_{0},\hat{\pi}_{1:h-1}, \mathbb{P}^{*}_{1:h-1}}\left[V_{h}^{\hat{\pi}}(s_{h})-\hat{V}_{h}(s_{h})\right]$ $\displaystyle=\mathbb{E}_{d_{0},\pi_{1:h},\mathbb{P}^{*}_{1:h-1}}\left[Q^{\pi} _{h}(s_{h},a_{h})-\hat{Q}_{h}(s_{h},a_{h})\right]-\mathbb{E}_{d_{0},\hat{\pi}_ {1:h},\mathbb{P}^{*}_{1:h-1}}\left[Q^{\hat{\pi}}_{h}(s_{h},a_{h})-\hat{Q}_{h}( s_{h},a_{h})\right]$ $\displaystyle-\eta\cdot\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1}} \left[D_{\mathrm{KL}}\left(\pi_{h}(\cdot|s_{h})||\hat{\pi}_{h}(\cdot|s_{h}) \right)\right]$ $\displaystyle=\mathbb{E}_{d_{0},\pi_{1:h},\mathbb{P}^{*}_{1:h}}\left[\hat{V}_{ h+1}(s_{h+1})-\hat{Q}_{h}(s_{h},a_{h})\right]-\mathbb{E}_{d_{0},\hat{\pi}_{1:h },\mathbb{P}^{*}_{1:h}}\left[\hat{V}_{h+1}(s_{h+1})-\hat{Q}_{h}(s_{h},a_{h})\right]$ $\displaystyle-\eta\cdot\mathbb{E}_{d_{0},\pi_{1:h-1},\mathbb{P}^{*}_{1:h-1}} \left[D_{\mathrm{KL}}\left(\pi_{h}(\cdot|s_{h})||\hat{\pi}_{h}(\cdot|s_{h}) \right)\right]$ $\displaystyle+\mathbb{E}_{d_{0},\pi_{1:h},\mathbb{P}^{*}_{1:h}}\left[V^{\pi}_{ h+1}(s_{h+1})-\hat{V}_{h+1}(s_{h+1})\right]-\mathbb{E}_{d_{0},\pi_{1:h}, \mathbb{P}^{*}_{1:h}}\left[V^{\hat{\pi}}_{h+1}(s_{h+1})-\hat{V}_{h+1}(s_{h+1}) \right].$ $$

The proposition can be obtained by iteratively using the above relationship for $h\in[H]$.
∎

###### Proof of Proposition 1 .

### C.2 Proof of Theorem 1

First, with the assumption $u^{*}\in\mathcal{U}$ and $\mathbb{P}^{*}\in\mathcal{P}$, the following lemma demonstrates that $\widetilde{\mathcal{U}}_{t}$ and $\widetilde{\mathcal{P}}_{t}$ are valid confidence sets.

###### Lemma 1 (Proposition B.1 from Liu et al. ( 2023a ) ) .

There exists an absolute constant $c_{1}$ such that for any $\delta\in(0,1]$, with probability at least $1-\delta$, for all $t\in[T]$, $\hat{u}\in\mathcal{U}$, and $\hat{\mathbb{P}}\in\mathcal{P}$, it holds that

$$ $\displaystyle L_{t}(\hat{u})-L_{t}(u^{*})\leq c_{1}\log(|\mathcal{U}|T/\delta) ,\qquad L_{t}(\hat{\mathbb{P}})-L_{t}(\mathbb{P}^{*})\leq c_{1}\log(|\mathcal{ P}|T/\delta),$ $$

which implies that $u^{*}\in\widetilde{\mathcal{U}}_{t}$ and $\mathbb{P}^{*}\in\widetilde{\mathcal{P}}_{t}$.

Then, we provide an additional lemma demonstrating the in-sample error of the MLE and optimistic estimators.

###### Lemma 2 .

There exists an absolute constant $c_{2}$ such that for any $\delta\in(0,1]$, with probability at least $1-\delta$, for all $t\in[T]$, we have

$$ $\displaystyle\sum_{i<t}\left|\sigma\left(\hat{u}_{t}(s^{2}_{i,H},a^{2}_{i,H})- \hat{u}_{t}(s^{1}_{i,H},a^{1}_{i,H})\right)-\sigma\left(u^{*}(s^{2}_{i,H},a^{2 }_{i,H})-u^{*}(s^{1}_{i,H},a^{1}_{i,H})\right)\right|^{2}\leq c_{2}\log(| \mathcal{U}|T/\delta);$ $\displaystyle\sum_{i<t}\left|\sigma\left(\widetilde{u}_{t}(s^{2}_{i,H},a^{2}_{ i,H})-\widetilde{u}_{t}(s^{1}_{i,H},a^{1}_{i,H})\right)-\sigma\left(u^{*}(s^{2 }_{i,H},a^{2}_{i,H})-u^{*}(s^{1}_{i,H},a^{1}_{i,H})\right)\right|^{2}\leq c_{2 }\log(|\mathcal{U}|T/\delta),$ $$

and for all $t\in[T]$, $h\in[H]$, we have

$$ $\displaystyle\sum_{j\in\{1,2\}}\sum_{h\in[H]}\sum_{i<t}\mathrm{TV}\left(\{d_{0 },\pi^{j}_{i},[\mathbb{P}^{*}_{1:h-1},\hat{\mathbb{P}}_{t,h},\mathbb{P}^{*}_{h +1:H}]\},\{d_{0},\pi^{j}_{i},\mathbb{P}^{*}_{1:H}\}\right)^{2}\leq c_{2}\log(| \mathcal{P}|HT/\delta);$ $\displaystyle\sum_{j\in\{1,2\}}\sum_{h\in[H]}\sum_{i<t}\mathrm{TV}\left(\{d_{0 },\pi^{j}_{i},[\mathbb{P}^{*}_{1:h-1},\widetilde{\mathbb{P}}_{t,h},\mathbb{P}^ {*}_{h+1:H}]\},\{d_{0},\pi^{j}_{i},\mathbb{P}^{*}_{1:H}\}\right)^{2}\leq c_{2} \log(|\mathcal{P}|HT/\delta),$ $$

where $\mathrm{TV}(\{d_{0},\pi,\mathbb{P}\},\{d_{0},\pi^{\prime},\mathbb{P}^{\prime}\})$ denotes the TV distance between the probability distributions over the trajectories induced by $d_{0},\pi,\mathbb{P}$ and $d_{0},\pi^{\prime},\mathbb{P}^{\prime}$.

###### Proof of Lemma 2 .

First, for $\widetilde{u}_{t}$, we can obtain that with probability at least $1-\delta$, there exists an absolute constant $c$ such that for all $t\in[T]$,

$$ $\displaystyle\sum_{i<t}\left|\sigma\left(\widetilde{u}_{t}(s^{2}_{i,H},a^{2}_{ i,H})-\widetilde{u}_{t}(s^{1}_{i,H},a^{1}_{i,H})\right)-\sigma\left(u^{*}(s^{2 }_{i,H},a^{2}_{i,H})-u^{*}(s^{1}_{i,H},a^{1}_{i,H})\right)\right|^{2}$ $\displaystyle\leq c\left(\sum_{i<t}\log\frac{z_{i}\cdot\sigma\left(u^{*}(s^{1} _{i,H},a^{1}_{i,H})-u^{*}(s^{2}_{i,H},a^{2}_{i,H})\right)+(1-z_{i})\cdot\sigma \left(u^{*}(s^{2}_{i,H},a^{2}_{i,H})-u^{*}(s^{1}_{i,H},a^{1}_{i,H})\right)}{z_ {i}\cdot\sigma\left(\widetilde{u}_{t}(s^{1}_{i,H},a^{1}_{i,H})-\widetilde{u}_{ t}(s^{2}_{i,H},a^{2}_{i,H})\right)+(1-z_{i})\cdot\sigma\left(\widetilde{u}_{t} (s^{2}_{i,H},a^{2}_{i,H})-\widetilde{u}_{t}(s^{1}_{i,H},a^{1}_{i,H})\right)}+ \log(|\mathcal{U}|T/\delta)\right)$ $\displaystyle=c\left(L_{t}(u^{*})-L_{t}(\widetilde{u}_{t})+\log(|\mathcal{U}|T /\delta)\right)$ $\displaystyle\leq c\left(L_{t}(u^{*})-L_{t}(\hat{u}_{t})+c_{1}\log(|\mathcal{U }|T/\delta)+\log(|\mathcal{U}|T/\delta)\right)$ $\displaystyle\leq c_{2}\log(|\mathcal{U}|T/\delta).$ $$

where the first inequality is from Proposition B.2 from Liu et al. () and the second inequality uses Lemma 1. The result for $\hat{u}_{t}$ can be similarly established.

Then, following similar steps, for $\widetilde{\mathbb{P}}_{t}$, we can obtain that with probability at least $1-\delta$, there exists an absolute constant $c$ such that for all $t\in[T]$,

$$ $\displaystyle\sum_{j\in\{1,2\}}\sum_{h\in[H]}\sum_{i<t}\mathrm{TV}\left(\{d_{0 },\pi^{j}_{i},[\mathbb{P}^{*}_{1:h-1},\widetilde{\mathbb{P}}_{t,h},\mathbb{P}^ {*}_{h+1:H}]\},\{d_{0},\pi^{j}_{i},\mathbb{P}^{*}_{1:H}\}\right)^{2}$ $\displaystyle\leq\sum_{j\in\{1,2\}}\sum_{h\in[H]}c\cdot\left(\sum_{i<t}\log \frac{\mathbb{P}^{*}_{h}(s^{j}_{i,h+1}|s^{j}_{i,h},a^{j}_{i,h})}{\widetilde{ \mathbb{P}}_{t,h}(s^{j}_{i,h+1}|s^{j}_{i,h},a^{j}_{i,h})}+\log(|\mathcal{P}_{h }|HT/\delta)\right)$ $\displaystyle=c\cdot\left(\sum_{j\in\{1,2\}}\sum_{i<t}\log\frac{\mathbb{P}^{*, \pi^{j}_{i}}(\tau^{j}_{i})}{\widetilde{\mathbb{P}}^{\pi^{j}_{i}}_{t}(\tau^{j}_ {i})}+2\log(|\mathcal{P}|HT/\delta)\right)$ $\displaystyle=c\cdot\left(L_{t}(\mathbb{P}^{*})-L_{t}(\widetilde{\mathbb{P}}_{ t})+2\log(|\mathcal{P}|HT/\delta)\right)$ $\displaystyle\leq c\cdot\left(L_{t}(\mathbb{P}^{*})-L_{t}(\hat{\mathbb{P}}_{t} )+c_{1}\log(|\mathcal{P}|T/\delta)+2\log(|\mathcal{P}|HT/\delta)\right)$ $\displaystyle\leq c_{2}\log(|\mathcal{P}|HT/\delta).$ $$

The result for $\hat{\mathbb{P}}_{t}$ can also be similarly established.
∎

###### Proof of Theorem 1 .

In the following proofs, we omit the KL term in the decomposition to ease the presentation. Then, with probability at least $1-\delta$, for all $t\in[T]$, we can obtain that

$$ $\displaystyle J(\pi^{*})-J(\pi^{1}_{t})$ $\displaystyle=\mathbb{E}_{d_{0},\pi^{*},\mathbb{P}^{*}}\left[u^{*}(s_{H},a_{H} )\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}}\left[u^{*}(s_{H},a_{H}) \right]-\left(\mathbb{E}_{d_{0},\pi^{*},\mathbb{P}^{*}}\left[\hat{u}_{t}(s_{H} ,a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}}\left[\hat{u}_{t}( s_{H},a_{H})\right]\right)$ $\displaystyle+\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{*},\mathbb{P}^{*}}\left[ \hat{V}_{t,h+1}(s_{h+1})-\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h+1}\right](s_ {h},a_{h})\right]-\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}} \left[\hat{V}_{t,h+1}(s_{h+1})-\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h+1} \right](s_{h},a_{h})\right]$ $\displaystyle\leq\underbrace{\mathbb{E}_{d_{0},\pi_{t}^{2},\widetilde{\mathbb{ P}}_{t}}\left[\widetilde{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_ {t},\widetilde{\mathbb{P}}_{t}}\left[\widetilde{u}_{t}(s_{H},a_{H})\right]- \left(\mathbb{E}_{d_{0},\pi_{t}^{2},\widetilde{\mathbb{P}}_{t}}\left[\hat{u}_{ t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\widetilde{\mathbb{P}}_{t }}\left[\hat{u}_{t}(s_{H},a_{H})\right]\right)}_{\text{term (I)}_{t}}$ $\displaystyle+\underbrace{\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi_{t}^{2}, \widetilde{\mathbb{P}}_{t}}\left[\hat{V}_{t,h+1}(s_{h+1})-\left[\hat{\mathbb{P }}_{t,h}\hat{V}_{t,h+1}\right](s_{h},a_{h})\right]+\sum_{h\in[H]}\mathbb{E}_{d _{0},\pi^{1}_{t},\mathbb{P}^{*}}\left[\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h +1}\right](s_{h},a_{h})-\hat{V}_{t,h+1}(s_{h+1})\right]}_{\text{term (II)}_{t}},$ $$

where the inequality is from the definition of $\pi^{2}_{t}$ and the fact that $(u^{*},\mathbb{P}^{*})\in\widetilde{\mathcal{U}}_{t}\times\widetilde{\mathcal{
P}}_{t}$ from Lemma 1.

We define the following terms:

$$ $\displaystyle\text{term (A)}_{t}$ $\displaystyle:=\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[\widetilde{u }_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}}\left[ \widetilde{u}_{t}(s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0},\pi_{t}^{2}, \mathbb{P}^{*}}\left[u^{*}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t}, \mathbb{P}^{*}}\left[u^{*}(s_{H},a_{H})\right]\right),$ $\displaystyle\text{term (B)}_{t}$ $\displaystyle:=\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[u^{*}(s_{H}, a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}}\left[u^{*}(s_{H},a _{H})\right]-\left(\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[\hat{u}_ {t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}}\left[ \hat{u}_{t}(s_{H},a_{H})\right]\right),$ $\displaystyle\text{term (C)}_{t}$ $\displaystyle:=\sum_{j\in\{1,2\}}\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{j}_{t}, \mathbb{P}^{*}}\left[\mathrm{TV}\left(\widetilde{\mathbb{P}}_{t,h}(\cdot|s_{h} ,a_{h}),\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})\right)\right],$ $\displaystyle\text{term (D)}_{t}$ $\displaystyle:=\sum_{j\in\{1,2\}}\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{j}_{t}, \mathbb{P}^{*}}\left[\mathrm{TV}\left(\hat{\mathbb{P}}_{t,h}(\cdot|s_{h},a_{h} ),\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})\right)\right].$ $$

For $\text{term (I)}_{t}$, we have that

$$ $\displaystyle\text{term (I)}_{t}$ $\displaystyle:=\mathbb{E}_{d_{0},\pi_{t}^{2},\widetilde{\mathbb{P}}_{t}}\left[ \widetilde{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\widetilde {\mathbb{P}}_{t}}\left[\widetilde{u}_{t}(s_{H},a_{H})\right]-\left(\mathbb{E}_ {d_{0},\pi_{t}^{2},\widetilde{\mathbb{P}}_{t}}\left[\hat{u}_{t}(s_{H},a_{H}) \right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\widetilde{\mathbb{P}}_{t}}\left[\hat{u} _{t}(s_{H},a_{H})\right]\right)$ $\displaystyle=\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[\widetilde{u} _{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{1},\mathbb{P}^{*}}\left[ \widetilde{u}_{t}(s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0},\pi_{t}^{2}, \mathbb{P}^{*}}\left[u^{*}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{ 1},\mathbb{P}^{*}}\left[u^{*}_{t}(s_{H},a_{H})\right]\right)$ $\displaystyle+\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[u^{*}_{t}(s_{ H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{1},\mathbb{P}^{*}}\left[u^{*}_{t}( s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[ \hat{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}} \left[\hat{u}_{t}(s_{H},a_{H})\right]\right)$ $\displaystyle+\mathbb{E}_{d_{0},\pi_{t}^{2},\widetilde{\mathbb{P}}_{t}}\left[ \widetilde{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{1},\widetilde {\mathbb{P}}_{t}}\left[\widetilde{u}_{t}(s_{H},a_{H})\right]-\left(\mathbb{E}_ {d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[\widetilde{u}_{t}(s_{H},a_{H})\right]- \mathbb{E}_{d_{0},\pi_{t}^{1},\mathbb{P}^{*}}\left[\widetilde{u}_{t}(s_{H},a_{ H})\right]\right)$ $\displaystyle+\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[\hat{u}_{t}(s _{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}}\left[\hat{u}_ {t}(s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0},\pi_{t}^{2},\widetilde{\mathbb {P}}_{t}}\left[\hat{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t}, \widetilde{\mathbb{P}}_{t}}\left[\hat{u}_{t}(s_{H},a_{H})\right]\right)$ $\displaystyle\leq\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[\widetilde {u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{1},\mathbb{P}^{*}}\left [\widetilde{u}_{t}(s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0},\pi_{t}^{2}, \mathbb{P}^{*}}\left[u^{*}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{ 1},\mathbb{P}^{*}}\left[u^{*}_{t}(s_{H},a_{H})\right]\right)$ $\displaystyle+\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[u^{*}_{t}(s_{ H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{1},\mathbb{P}^{*}}\left[u^{*}_{t}( s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[ \hat{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}} \left[\hat{u}_{t}(s_{H},a_{H})\right]\right)$ $\displaystyle+4B\cdot\mathrm{TV}\left(\{d_{0},\pi^{1}_{t},\widetilde{\mathbb{P }}_{t}\},\{d_{0},\pi^{1}_{t},\mathbb{P}^{*}\}\right)+4B\cdot\mathrm{TV}\left( \{d_{0},\pi^{2}_{t},\widetilde{\mathbb{P}}_{t}\},\{d_{0},\pi^{2}_{t},\mathbb{P }\}\right)$ $\displaystyle\leq\underbrace{\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}} \left[\widetilde{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{1}, \mathbb{P}^{*}}\left[\widetilde{u}_{t}(s_{H},a_{H})\right]-\left(\mathbb{E}_{d _{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[u^{*}_{t}(s_{H},a_{H})\right]-\mathbb{E} _{d_{0},\pi_{t}^{1},\mathbb{P}^{*}}\left[u^{*}_{t}(s_{H},a_{H})\right]\right)} _{\text{term (A)}_{t}}$ $\displaystyle+\underbrace{\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left[u ^{*}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi_{t}^{1},\mathbb{P}^{*}} \left[u^{*}_{t}(s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0},\pi_{t}^{2}, \mathbb{P}^{*}}\left[\hat{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1} _{t},\mathbb{P}^{*}}\left[\hat{u}_{t}(s_{H},a_{H})\right]\right)}_{\text{term (B)}_{t}}$ $\displaystyle+4B\cdot\underbrace{\sum_{j\in\{1,2\}}\sum_{h\in[H]}\mathbb{E}_{d _{0}}\mathbb{E}_{\pi^{j}_{t},\mathbb{P}^{*}}\left[\mathrm{TV}\left(\widetilde{ \mathbb{P}}_{t,h}(\cdot|s_{h},a_{h}),\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h}) \right)\right]}_{\text{term (C)}_{t}}.$ $$

For $\text{term (II)}_{t}$, we have that

$$ $\displaystyle\text{term (II)}_{t}$ $\displaystyle=\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi_{t}^{2},\widetilde{\mathbb{P }}_{t}}\left[\hat{V}_{t,h+1}(s_{h+1})-\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h +1}\right](s_{h},a_{h})\right]$ $\displaystyle+\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}}\left [\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h+1}\right](s_{h},a_{h})-\hat{V}_{t,h+ 1}(s_{h+1})\right]$ $\displaystyle=\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left [\hat{V}_{t,h+1}(s_{h+1})-\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h+1}\right](s _{h},a_{h})\right]$ $\displaystyle+\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi_{t}^{2},\widetilde{\mathbb{P }}_{t}}\left[\hat{V}_{t,h+1}(s_{h+1})-\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h +1}\right](s_{h},a_{h})\right]$ $\displaystyle-\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left [\hat{V}_{t,h+1}(s_{h+1})-\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h+1}\right](s _{h},a_{h})\right]$ $\displaystyle+\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P}^{*}}\left [\left[\hat{\mathbb{P}}_{t,h}\hat{V}_{t,h+1}\right](s_{h},a_{h})-\hat{V}_{t,h+ 1}(s_{h+1})\right]$ $\displaystyle\leq 2B\cdot\sum_{j\in\{1,2\}}\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi _{t}^{j},\mathbb{P}^{*}}\left[\mathrm{TV}(\hat{\mathbb{P}}_{t,h}(\cdot|s_{h},a _{h})),\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})\right]$ $\displaystyle+2BH\cdot\mathrm{TV}(\{d_{0},\pi_{t}^{2},\widetilde{\mathbb{P}}_{ t}\},\{d_{0},\pi_{t}^{2},\mathbb{P}^{*}\})$ $\displaystyle\leq 2B\cdot\underbrace{\sum_{j\in\{1,2\}}\sum_{h\in[H]}\mathbb{E }_{d_{0},\pi_{t}^{j},\mathbb{P}^{*}}\left[\mathrm{TV}(\hat{\mathbb{P}}_{t,h}( \cdot|s_{h},a_{h})),\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})\right]}_{\text{term (D)}_{t}}$ $\displaystyle+2BH\cdot\underbrace{\sum_{j\in\{1,2\}}\sum_{h\in[H]}\mathbb{E}_{ d_{0},\pi_{t}^{j},\mathbb{P}^{*}}\left[\mathrm{TV}(\widetilde{\mathbb{P}}_{t,h }(\cdot|s_{h},a_{h})),\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})\right]}_{\text{ term (C)}_{t}}.$ $$

In the above derivations, we have repeatedly used similar relationships as follows:

$$ $\displaystyle\mathrm{TV}(\{d_{0},\pi^{2}_{t},\widetilde{\mathbb{P}}_{t}\},\{d_ {0},\pi^{2}_{t},\mathbb{P}^{*}\})\leq\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{2}_{ t},\mathbb{P}^{*}}\left[\mathrm{TV}\left(\widetilde{\mathbb{P}}_{t,h}(\cdot|s_ {h},a_{h}),\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})\right)\right],$ $$

which can be derived as

$$ $\displaystyle\mathrm{TV}(\{d_{0},\pi^{2}_{t},\widetilde{\mathbb{P}}_{t}\},\{d_ {0},\pi^{2}_{t},\mathbb{P}^{*}\})$ $\displaystyle\leq\sum_{h\in[H]}\mathrm{TV}\left(\{d_{0},\pi^{2}_{t},\mathbb{P} ^{*}_{1:h-1},\widetilde{\mathbb{P}}_{t,h:H}\},\{d_{0},\pi^{2}_{t},\mathbb{P}^{ *}_{1:h},\widetilde{\mathbb{P}}_{t,h+1:H}\}\right)$ $\displaystyle=\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{2}_{t},\mathbb{P}^{*}}\left [\mathrm{TV}\left(\widetilde{\mathbb{P}}_{t,h}(\cdot|s_{h},a_{h}),\mathbb{P}^{ *}_{h}(\cdot|s_{h},a_{h})\}\right)\right].$ $$

Then, we can obtain that

$$ $\displaystyle\sum_{t\in[T]}J(\pi^{*})-J(\hat{\pi}^{1}_{t})$ $\displaystyle\leq\sum_{t\in[T]}\text{term (A)}_{t}+\sum_{t\in[T]}\text{term (B )}_{t}+(4B+2BH)\sum_{t\in[T]}\text{term (C)}_{t}+2B\sum_{t\in[T]}\text{term (D )}_{t}.$ $$

Then, we control the sum of each individual term in the following. First, for $\text{term (A)}_{t}$, with probability at least $1-\delta$, we have that

$$ $\displaystyle\sum_{t\in[T]}\text{term (A)}_{t}$ $\displaystyle=\sum_{t\in[T]}\mathbb{E}_{d_{0},\pi_{t}^{2},\mathbb{P}^{*}}\left [\widetilde{u}_{t}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{1}_{t},\mathbb{P }^{*}}\left[\widetilde{u}_{t}(s_{H},a_{H})\right]-\left(\mathbb{E}_{d_{0},\pi_ {t}^{2},\mathbb{P}^{*}}\left[u^{*}(s_{H},a_{H})\right]-\mathbb{E}_{d_{0},\pi^{ 1}_{t},\mathbb{P}^{*}}\left[u^{*}(s_{H},a_{H})\right]\right)$ $\displaystyle\leq\sum_{t\in[T]}\widetilde{u}_{t}(s^{2}_{t,H},a^{2}_{t,H})- \widetilde{u}_{t}(s^{1}_{t,H},a^{1}_{t,H})-\left(u^{*}(s^{2}_{t,H},a^{2}_{t,H} )-u^{*}(s^{1}_{t,H},a^{1}_{t,H})\right)+O(B\sqrt{T\log(1/\delta)})$ $\displaystyle\leq\sqrt{d_{\mathcal{U}}\sum_{t=2}^{T}\left(1+\sum_{i=1}^{t-1} \left(\widetilde{u}_{t}(s^{2}_{i,H},a^{2}_{i,H})-\widetilde{u}_{t}(s^{1}_{i,H} ,a^{1}_{i,H})-\left(u^{*}(s^{2}_{i,H},a^{2}_{i,H})-u^{*}(s^{1}_{i,H},a^{1}_{i, H})\right)\right)^{2}\right)}+O(B\sqrt{T\log(1/\delta)})$ $\displaystyle\leq\sqrt{d_{\mathcal{U}}\sum_{t=2}^{T}\left(1+\kappa^{-2}\sum_{i =1}^{t-1}\left(\sigma\left(\widetilde{u}_{t}(s^{2}_{i,H},a^{2}_{i,H})- \widetilde{u}_{t}(s^{1}_{i,H},a^{1}_{i,H})\right)-\sigma\left(u^{*}(s^{2}_{i,H },a^{2}_{i,H})-u^{*}(s^{1}_{i,H},a^{1}_{i,H})\right)\right)^{2}\right)}+O(B \sqrt{T\log(1/\delta)})$ $\displaystyle\lesssim\kappa^{-1}B\sqrt{d_{\mathcal{U}}T\log(|\mathcal{U}|T/ \delta)},$ $$

where the first inequality is from the Hoeffding inequality, the second inequality uses the Eluder coefficient $d_{\mathcal{U}}:=\texttt{EC}(1,\mathcal{U}-\mathcal{U},T)$ from Definition 4, the third inequality leverages the mean value theorem with $\kappa:=1/(2+\exp(-B)+\exp(B))$ representing the minimum derivative of $\sigma(\cdot)$ in the regime of $[0,B]$, and the last inequality incorporates Lemma 2. A similar result can be obtained for $\text{term (B)}_{t}$.

For $\text{term (C)}_{t}$, we have that

$$ $\displaystyle\sum_{t\in[T]}\text{term (C)}_{t}$ $\displaystyle=\sum_{j\in\{1,2\}}\sum_{t\in[T]}\sum_{h\in[H]}\mathbb{E}_{d_{0}, \pi^{j}_{t},\mathbb{P}^{*}}\left[\mathrm{TV}\left(\widetilde{\mathbb{P}}_{t,h} (\cdot|s_{h},a_{h}),\mathbb{P}^{*}_{h}(\cdot|s_{h},a_{h})\right)\right]$ $\displaystyle=\sum_{j\in\{1,2\}}\sum_{t\in[T]}\sum_{h\in[H]}\mathrm{TV}\left( \{d_{0},\pi^{j}_{t},[\mathbb{P}^{*}_{1:h-1},\widetilde{\mathbb{P}}_{t,h}, \mathbb{P}^{*}_{h+1:H}]\},\{d_{0},\pi^{j}_{t},\mathbb{P}^{*}_{1:H}\}\right)$ $\displaystyle\leq 2H\cdot\xi(d_{\mathcal{P}},T,c_{2}\log(|\mathcal{P}|HT/ \delta)),$ $$

where the last step is from the generalized Eluder-type condition in Definition 5 and Lemma 2. A similar result can be obtained for $\text{term (D)}_{t}$.

Finally, we obtain that

$$ $\displaystyle\text{Reg}(T)\lesssim$ $\displaystyle\kappa^{-1}B\sqrt{d_{\mathcal{U}}T\log(|\mathcal{U}|T/\delta)}+B^ {2}H\xi(d_{\mathcal{P}},T,c_{2}\log(|\mathcal{P}|HT/\delta)$ $\displaystyle-\eta\cdot\sum_{h\in[H]}\mathbb{E}_{d_{0},\pi^{*},\mathbb{P}^{*}} \left[D_{\mathrm{KL}}(\pi^{*}_{h}(\cdot|s_{h}),\pi^{1}_{t,h}(\cdot|s_{h})) \right],$ $$

which concludes the proof.
∎

###### Lemma 1 (Proposition B.1 from Liu et al. ( 2023a ) ) .

###### Lemma 2 .

###### Proof of Lemma 2 .

###### Proof of Theorem 1 .

## Appendix D Technical Lemmas

###### Lemma 3 (Solution of KL-regularized Optimization (Proposition 7.16 and Theorem 15.3 of Zhang ( 2023 ) )) .

Given a loss functional with respect to $p(\cdot|x)$, written as

$$ $\mathbb{E}_{w\sim p(\cdot)}\Big{[}-U(w)+\eta D_{\mathrm{KL}}\big{(}p(\cdot),p_ {0}(\cdot)\big{)}\Big{]}=\eta D_{\mathrm{KL}}\Big{(}p(\cdot),p_{0}(\cdot)\exp \Big{(}\frac{1}{\eta}U(\cdot)\Big{)}\Big{)}-\eta\cdot\log\underbrace{\mathbb{E }_{w\sim p_{0}(\cdot)}\exp\big{(}\frac{1}{\eta}U(w)\big{)}}_{C_{r}},$ $$

where the minimizer of the loss functional is
$p^{*}(w)=\frac{1}{C_{r}}p_{0}(w)\exp\Big{(}\frac{1}{\eta}U(w)\Big{)}$, also known as Gibbs distribution.

###### Definition 4 (Eluder Coefficient, Definition 17.17 in Zhang ( 2023 ) ) .

Given a function class $\mathcal{F}$, its Eluder coefficient $\texttt{EC}(\lambda,\mathcal{F},T)$ is defined as the smallest number $d$ so that for any sequence $\{x_{t}:t\in[T]\}$ and $\{f_{t}:t\in[T]\}\in\mathcal{F}$,

$$ $\displaystyle\sum_{t=2}^{T}|f_{t}(x_{t})-f^{*}(x_{t})|\leq\sqrt{d\sum_{t=2}^{T }\left(\lambda+\sum_{i=1}^{t-1}(f_{t}(x_{i})-f^{*}(x_{i}))^{2}\right)}.$ $$

###### Definition 5 (Generalized Eluder-type Condition, Condition 3.1 in Liu et al. ( 2023a ) ) .

There exists a real number $d_{\mathcal{P}}\in\mathbb{R}^{+}$ and a function $\xi$ such that for any $(T,\Delta)\in\mathbb{N}\times\mathbb{R}^{+}$, transitions $\{\mathbb{P}^{\prime}_{t}:t\in[T]\}$ and policies $\{\pi_{t}:t\in[T]\}$, we have

$$ $\displaystyle\forall t\in[T],\quad\sum_{i<t}\mathrm{TV}(\{d_{0},\mathbb{P}^{ \prime}_{i},\pi_{i}\},\{d_{0},\mathbb{P},\pi_{i}\})^{2}\leq\Delta\quad \Rightarrow\sum_{t\in[T]}\mathrm{TV}(\{d_{0},\mathbb{P}^{\prime}_{t},\pi_{t}\} ,\{d_{0},\mathbb{P},\pi_{t}\})\leq\xi(d_{\mathcal{P}},T,\Delta).$ $$

###### Lemma 3 (Solution of KL-regularized Optimization (Proposition 7.16 and Theorem 15.3 of Zhang ( 2023 ) )) .

###### Definition 4 (Eluder Coefficient, Definition 17.17 in Zhang ( 2023 ) ) .

###### Definition 5 (Generalized Eluder-type Condition, Condition 3.1 in Liu et al. ( 2023a ) ) .

## Peer Reviews

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: For the example shown in figure 1, the human inputs (o1 and o2) do not provide additional information, why multi-turn conversation is needed in this case?
soundness: 3
strengths: a.	The paper proposed an iterative multi-turn DPO and KTO training framework, which effectively improves the models ability on multiturn reasoning for math problems.
b.	The experiments are solid, and they conduct experiments with multiple base models.
summary: The paper investigates enhancing mathematical reasoning in large language models (LLMs) through a multi-turn preference learning approach with tool integration. The authors propose a multi-turn direct preference optimization framework that accommodates complex, multi-turn reasoning and external tool integration, crucial for mathematical tasks. By employing two specific implementations—multi-turn Direct Preference Optimization (DPO) and multi-turn Kernelized Trajectory Optimization (KTO)—the framework improves model accuracy on math benchmarks, GSM8K and MATH. Empirical results with multiple base models show notable gains, particularly for models fine-tuned with iterative multi-turn training, outperforming standard SFT and single-turn baselines. The study also highlights the importance of balancing model exploration and accuracy through KL regularization and mixture sampling to maintain performance in iterative training.
weaknesses: a.	Overall, the motivation makes sense, as for some complex math problems that require tool integration, human inputs might be needed. However, only GSM8K and MATH have been used as the benchmarks in this paper, which are relatively easy problems, and may not necessarily need human input as multi-turn conversation. It is more convincing if you can conduct experiments on more complex tasks, like formulating an optimization problem and solving it from a task description. 
b.	The presentation of the results is not clear enough. For example, table 1 is too long, and different models use different settings, e.g. Wizardmath, codellama and Gemma-1.1-it-7B have different settings from other models. It is more readable if the table is splitted, and each sub table has its own conclusion or findings.
c.	Typos, e.g. line 270 DKO, should be KTO.

---

confidence: 4
contribution: 3
initial_rating: 8
presentation: 4
questions: None.
soundness: 3
strengths: 1. This paper proposes a solution to the language model’s multi-turn planning problem involving external environment interaction, offering well-grounded theoretical proofs and a straightforward formulation.

2. The proposed algorithms are empirically validated to be effective in addressing mathematical problem-solving tasks with external tool integration.
summary: This paper addresses the optimization of multi-turn MDP planning under conditions involving interactions with external tool integration. Through rigorous theoretical derivations, it models the optimal conditions for multi-turn MDP planning and demonstrates that when
the external randomness is low, a reward form using DPO can feasibly compute the utility function in multi-turn MDP planning. Furthermore, the authors propose multi-turn DPO and multi-turn KTO algorithms tailored for optimizing multi-turn MDP planning and validate the effectiveness of combining multi-turn MDP planning optimization with an online iterative approach, showing that performance loss relative to the optimal policy is sublinear, thus highlighting the statistical efficiency of the proposed algorithm. Extensive experiments conducted on various model series across GSM8K and MATH datasets affirm the efficacy of these methods in multi-turn MDP planning.
weaknesses: 1. The utility function form in Equation (7) needs a value network and is computable only under the form of DPO rewards and deterministic external conditions, which limits the practical applicability of this theoretical framework. Currently, the theoretic framework cannot utilize methods like PPO to address multi-turn MDP planning problems with external interactions.

2. The experimental section’s baseline explanation for single-turn iterative DPO lacks clarity regarding the KL regularization strategy, especially in terms of whether a fixed reference is employed, which might contribute to the poorer performance observed in single-turn iterative DPO.

---

confidence: 4
contribution: 3
initial_rating: 8
presentation: 4
questions: Please see the weaknesses section. I also hope to see further details on the ORM, such as the base model and training method. 

Overall, the paper does not have any obvious weaknesses, and I personally find it quite impressive. I believe it meets the acceptance criteria for ICLR. If you address my concerns, I would consider raising the score.

**Missing reference:**

[1] DotaMath: Decomposition of Thought with Code Assistance and Self-correction for Mathematical Reasoning
soundness: 4
strengths: 1. The integration of external tool augmented methods and the use of multi-turn preference learning is both interesting and reasonable, effectively addressing the shortcomings of natural language in mathematical reasoning. The exploration of tool-augmented methods in the mathematical domain is well-motivated.

2. The methods presented in the paper are strongly supported by theoretical foundations, which enhances their credibility, and the overall writing is clear and easy to understand.
summary: This paper introduces a multi-turn direct preference learning framework, tailored for this context, that leverages feedback from code interpreters and optimizes trajectory-level preferences. This framework includes multi-turn DPO and multi-turn KTO as specific implementations. The effectiveness of our framework is validated through training of various language models using an augmented
prompt set from the GSM8K and MATH datasets.
weaknesses: 1. WizardMath, being a state-of-the-art math model from a year ago, seems somewhat outdated as a baseline for performance. I hope the authors can include results from recent stronger models in mathematics that incorporate MULTI-TURN ITERATIVE PREFERENCE LEARNING, such as Qwen 2.5 Math and DeepSeek Math.

2. I would indeed like to see results of this method in the context of a process-based reward model (PRM) and combined with MCTS sampling strategies (even preliminary results would be helpful). Although the authors mention this limitation in the limitations section and in line 297, relying solely on ORM for reasoning verification is not sufficiently detailed.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: 1.How is the definition and selection of preference signals specifically designed in this approach? Could different preference signals significantly impact the final optimization results?
2.Is it possible to further test the method in other types of reasoning tasks or application domains to verify its generalizability?
3.In terms of external tool integration, is the current method the optimal solution?
soundness: 2
strengths: This paper improves the performance of large language models (LLMs) in multi-turn complex reasoning tasks. The study effectively validates the proposed approach using two datasets.
summary: This paper proposes a new method to improve the mathematical reasoning abilities of large language models. Existing direct preference learning algorithms are mainly applied to single-turn dialogue tasks and fail to address the complexities of multi-turn reasoning and external tool integration. To tackle this, the paper introduces a multi-turn direct preference learning framework and specifically implements two algorithms (M-DPO and M-KTO). Experiments were conducted by training the model on the GSM8K and MATH datasets, and the results demonstrate that this new framework significantly enhances the model’s performance on multiple benchmark tasks.
weaknesses: Although the proposed method shows outstanding performance, it is relatively focused on specific task types. Currently, the experiments are limited to the GSM8K and MATH datasets, and it would be better to include more datasets in the testing. Additionally, the framework's design is relatively complex, involving multi-turn preference learning and trajectory-level optimization, which may require high computational resources in practical applications. A comparative experiment to demonstrate the time cost and computational consumption compared to previous methods would be helpful here.

Meta-review: The paper introduces a multi-turn direct preference learning framework designed to enhance large language models’ (LLMs) mathematical reasoning by addressing limitations of single-turn preference learning. It focuses on trajectory-level preferences and integrates two specific algorithms: multi-turn Direct Preference Optimization and Kernelized Trajectory Optimization. Experiments on GSM8K and MATH benchmarks demonstrate notable performance improvements across various model sizes. 

Reviewers appreciated the paper’s theoretical framework, practical application, and integration of external tools for tool-based reasoning tasks. The paper validated the method with solid experimental setup, including ablation studies and detailed analyses. While no major weaknesses were identified, reviewers suggested that the benchmarks used may not fully demonstrate generalizability to complex scenarios, and clarity on computational costs and result presentation could be improved. The rebuttal has addressed key concerns, and reviewers agreed the work provides significant theoretical and practical contributions. Incorporating the feedback in revisions would further strengthen this already compelling paper. I recommend it for acceptance.

Decision: Accept (Poster)