Introduction
Modern LLM training generally follows the framework of a large-scale pretraining phase on corpora from the real world [4 , 29 ] , such as internet and human-curated data, followed by a post-training phase, in which a base pretrained LLM is fine-tuned to elicit domain-specific gains in capability, most notably in domains such as mathematical reasoning [43 ] , instruction following [32 ] , and software engineering [54 ] . In particular, reinforcement learning (RL) [8 , 10 ] has recently emerged as a popular paradigm for improving LLM capabilities during post-training. This approach has been well-demonstrated to bring about scalable gains over the initial pre-training phase of LLMs, and has been widely adopted amongst both open- and closed-source models. On-policy distillation [15 , 1 ] has been proposed as a promising alternative. The difference, however, is that the teacher provides dense, token-level feedback to the student rather than in RL where the single reward scalar signal guides the gradient updates. Recently, specialized versions of OPD such as on-policy self-distillation (OPSD) as well as other variants have been proposed [61 , 20 ] . Separately, there have also been works inspired from classical RL literature which train a separate critic model to give an estimate of the process reward [3 , 50 ] .
In this paper, we aim to give a rigorous characterization of what makes a teacher and student compatible for OPD-style training. Informally speaking, the student and teacher should not have too much distributional mismatch [12 , 19 ] ; otherwise, as we prove, the optimization landscape will be very unfavorable. Moreover, the teacher should be somewhat competent, which we will quantify later. Finally, the teacher’s supervision should induce good diversity over good responses for the student. We formalize all of these concepts in a unified manner in Section 4.
Importantly, we make an additional observation that is unique to the on-policy setting: not only can we do teacher selection for a given prompt (i.e. as in MOPD [26 ] where prompts of a given domain are routed to the corresponding domain expert), we can actually also do teacher selection token-wise during a student rollout. The intuition for this is that different teachers may be more suitable for different parts of a student rollout (for instance, in algorithmic coding it may be useful to have a math teacher guide the mathematical reasoning prior to implementation).
Overall, we summarize our contributions as follows.
First, we give a theoretical framework to ground the analysis of token-level teacher selection, in which we can decouple the contribution of teacher competence and of the teacher-student gap.
Then, within this framework, we give a unified mathematical interpretation of the confidence-based routing scheme from Yin et al. [ [59 ] and a newly proposed representation-based routing scheme. In particular, we show in different scenarios one or the other could prove more useful as a routing scheme. Importantly, we also prove that the representation-based routing has the potential to yield more diverse student generations.
We back up our theoretical insights with experiments across many domains, including code, Triton kernel generation, math, and visual reasoning. These demonstrate the clear potential of token-level teacher selection over vanilla OPD via improvements across pass@k k k , indicating student learning of high quality and diverse responses. More importantly, we are able to have principled predictions of when a family of routing schemes is likely to be effective in practical setups.
We discuss related work in Appendix § 8 .
Preliminaries
On-Policy Distillation Formulation
Consider the setup where we have a student policy π θ \pi_\theta π θ parameterized by θ ∈ R d \theta\in\mathbb{R}^d θ ∈ R d . Let x ∼ D x \sim\mathcal{D} x ∼ D , where D \mathcal{D} D is some prompt distribution, y = ( y 1 , … , y ∣ y ∣ ) ∼ π θ ( ⋅ ∣ x ) y = (y_1, \ldots, y_{|y|}) \sim\pi_\theta(\cdot|x) y = ( y 1 , … , y ∣ y ∣ ) ∼ π θ ( ⋅ ∣ x ) be a generation of a student response, and s t = ( x , y < t ) s_t = (x, y_{<t}) s t = ( x , y < t ) be the state that predicts the next token y t y_t y t . Then, vanilla OPD minimizes the following loss:
L O P D ( θ ) : = E x ∼ D [ KL ( π θ ∥ π T ) ] = E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ ∑ t = 1 ∣ y ∣ KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t ) ) ] . \mathcal{L}_{\mathrm{OPD}}(\theta) := \mathbb{E}_{x \sim\mathcal{D}}\left[\operatorname{KL}(\pi_\theta\Vert\pi_T)\right]
= \mathbb{E}_{x \sim\mathcal{D}, y \sim\pi_\theta(\cdot|x)}\left[\sum_{t=1}^{|y|} \operatorname{KL}\left(\pi_\theta(\cdot|s_t)\Vert\pi_T(\cdot|s_t)\right)\right]. L OPD ( θ ) := E x ∼ D [ KL ( π θ ∥ π T ) ] = E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) t = 1 ∑ ∣ y ∣ KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t ) ) .
where π T \pi_T π T defines some teacher policy. In particular, one can calculate the gradient of this as:
∇ L O P D ( θ ) = E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ ∑ t = 1 ∣ y ∣ ∑ t ′ = t ∣ y ∣ log π θ ( y t ′ ∣ s t ′ ) π T ( y t ′ ∣ s t ′ ) ∇ θ log π θ ( y t ∣ s t ) ] . \nabla\mathcal{L}_{\mathrm{OPD}}(\theta)
= \mathbb{E}_{x \sim\mathcal{D}, y \sim\pi_\theta(\cdot|x)}\left[\sum_{t=1}^{|y|}\sum_{t'=t}^{|y|}\log\frac{\pi_\theta(y_{t'}|s_{t'})}{\pi_T(y_{t'}|s_{t'})}\nabla_\theta\log\pi_\theta(y_t|s_t)\right]. ∇ L OPD ( θ ) = E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) t = 1 ∑ ∣ y ∣ t ′ = t ∑ ∣ y ∣ log π T ( y t ′ ∣ s t ′ ) π θ ( y t ′ ∣ s t ′ ) ∇ θ log π θ ( y t ∣ s t ) .
However, in practice, this gradient is approximated as:
E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ ∑ t = 1 ∣ y ∣ log π θ ( y t ∣ s t ) π T ( y t ∣ s t ) ∇ θ log π θ ( y t ∣ s t ) ] . (1) \mathbb{E}_{x \sim\mathcal{D}, y \sim\pi_\theta(\cdot|x)}\left[\sum_{t=1}^{|y|}\log\frac{\pi_\theta(y_t|s_t)}{\pi_T(y_t|s_t)}\nabla_\theta\log\pi_\theta(y_t|s_t)\right]. \tag*{(1)} E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) t = 1 ∑ ∣ y ∣ log π T ( y t ∣ s t ) π θ ( y t ∣ s t ) ∇ θ log π θ ( y t ∣ s t ) . (1)
Observe that this approximation is equivalent to moving the gradient inside of the expectation in the original loss (i.e. E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ ∑ t = 1 ∣ y ∣ ∇ KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t ) ) ] \mathbb{E}_{x \sim\mathcal{D},y \sim\pi_\theta(\cdot|x)}\left[\sum_{t=1}^{|y|}\nabla\operatorname{KL}(\pi_\theta(\cdot|s_t)\Vert\pi_T(\cdot|s_t))\right] E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ ∑ t = 1 ∣ y ∣ ∇ KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t )) ] instead of ∇ E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ ∑ t = 1 ∣ y ∣ KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t ) ) ] \nabla\mathbb{E}_{x \sim\mathcal{D},y \sim\pi_\theta(\cdot|x)}\left[\sum_{t=1}^{|y|}\operatorname{KL}(\pi_\theta(\cdot|s_t)\Vert\pi_T(\cdot|s_t))\right] ∇ E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ ∑ t = 1 ∣ y ∣ KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t )) ] ). Our token-level teacher routing acts directly on the teacher term in (1) . At each sampled prefix s t s_t s t , we plug in our choice of π T ( ⋅ ∣ s t ) \pi_T(\cdot|s_t) π T ( ⋅ ∣ s t ) : either a single teacher selected by hard routing or an arithmetic mixture of teachers under soft routing, as defined in Section 3. This choice determines the sampled-token advantage; the teacher selection and mixture weights are held fixed during the update.
Note that this approximation is equivalent to using log π T ( y t ∣ s t ) − log π θ ( y t ∣ s t ) \log\pi_T(y_t|s_t)-\log\pi_\theta(y_t|s_t) log π T ( y t ∣ s t ) − log π θ ( y t ∣ s t ) as the token-level advantage in OPD. In the rest of our exposition, we will refer to the vanilla OPD above as the sampled-token advantage OPD . This is because we will also consider a variant of the above, which is the Top-KL loss version of OPD; we provide the precise formulation of this in Appendix § 12 .§ 1 .
Token-Level Teacher Selection
Given C C C teachers π T 1 , … , π T C \pi_{T_1},\ldots,\pi_{T_C} π T 1 , … , π T C , we would like to understand which of these teachers best supervises the student rollout at each token. In our context, token-level supervision simply means choosing a teacher for each prefix state s t s_t s t for the gradient update in Equation (1) . Regardless of the way we define success for our training run, we already know a priori that there exists a token-level teacher routing scheme that cannot do worse than vanilla OPD (i.e. fixing a teacher throughout training), as we now have combinatorially more options across the entire axis of rollout horizon; we formalize this fact in § 4.1 and Appendix § 9 .§ 1 , where the notion of success is suboptimality of reward with respect to some golden reference distribution.
We now describe the general framework used for routing, first introduced in Yin et al. [ [59 ] . At iteration j j j of training, generate responses from π θ j \pi_{\theta_j} π θ j and compute scores S i ( s t ; θ j ) S_i(s_t;\theta_j) S i ( s t ; θ j ) for teacher i i i . For a temperature τ > 0 \tau>0 τ > 0 2 , define the weights
w i ( s t ) = exp ( S i ( s t ; θ j ) / τ ) ∑ h = 1 C exp ( S h ( s t ; θ j ) / τ ) . (2) w_i(s_t)=\frac{\exp(S_i(s_t;\theta_j)/\tau)}{\sum_{h=1}^{C}\exp(S_h(s_t;\theta_j)/\tau)}. \tag*{(2)} w i ( s t ) = ∑ h = 1 C exp ( S h ( s t ; θ j ) / τ ) exp ( S i ( s t ; θ j ) / τ ) . (2)
Then, we use the mixture teacher π T , w = ∑ i w i π T i \pi_{T,w}=\sum_i w_i\pi_{T_i} π T , w = ∑ i w i π T i as the supervision target of prefix s t s_t s t . Using this framework, we now give three classes of routing schemes.
Direct section routing. When the required skill is clear from the rollout section, we can directly assign its domain teacher. That is, for a student rollout y = ( y 1 , … , y H ) y=(y_1,\ldots,y_H) y = ( y 1 , … , y H ) , if token t t t corresponds to the domain of teacher i i i , one can consider directly routing the teacher at token t t t to be teacher i i i by taking τ = 0 \tau=0 τ = 0 and S i ( s t ; θ j ) > S i ′ ( s t ; θ j ) S_i(s_t;\theta_j)>S_{i'}(s_t;\theta_j) S i ( s t ; θ j ) > S i ′ ( s t ; θ j ) for i ′ ≠ i i'\ne i i ′ = i in Equation (2) , from which the gradient in Equation (1) will be calculated. For example, in the setting of writing kernel code, a thinking teacher can supervise a reasoning section, while a kernel specialist can supervise the subsequent implementation.
Teacher confidence-based routing. This was first introduced in Yin et al. [ [59 ] through their H-OPD algorithm. In this family of routing scores, S i ( s t ; θ j ) S_i(s_t;\theta_j) S i ( s t ; θ j ) is taken to be the negative entropy of the teacher at that prefix; that is, S i ( s t ; θ j ) = − H ( π T i ( ⋅ ∣ s t ) ) S_i(s_t;\theta_j)=-H(\pi_{T_i}(\cdot|s_t)) S i ( s t ; θ j ) = − H ( π T i ( ⋅ ∣ s t )) . Note that this is independent of the student policy at s t s_t s t and is calculated purely from the teacher’s confidence. In some sense, this can be seen as a proxy estimating which teacher yields more successful rewards on its continuation from a student prefix; this proxy is more accurate of course when the teacher is correctly confident.
Teacher-student representation-based routing. We introduce a new, more general family of routing schemes that captures the state of the student policy at s t s_t s t , by considering the teacher compatibility with the student in the sense of match in representation space or similarity of thinking patterns. Empirically, we implement the following scores3 : 1) the negative Hellinger distance4 between the student and teacher policy at s t s_t s t , and 2) the negative squared Euclidean distance between the teacher and student features at s t s_t s t (that is, the final layer before the unembedding layer, denoted as ϕ ( s t ) \phi(s_t) ϕ ( s t ) on prefix s t s_t s t for the student, and ψ i ( s t ) \psi_i(s_t) ψ i ( s t ) for teacher i i i ). We remark that feature matching is especially natural for shared architectures, such as a teacher post-trained from the student; otherwise, we resort to the Hellinger distance.
Theoretical Analysis of Teacher Routing Schemes
In this section, we provide a theoretical framework to unify the different families of routing schemes described in § 3 , in an aim to understand when these schemes may be useful.
Decoupling Teacher Competence and the Student-Teacher Gap
To begin, we introduce the performance difference lemma [17 , 40 ] , which allows us to roughly decouple the teacher competence (as measured via the reward suboptimality to some target distribution) and the student optimization toward the teacher. Let R ( x , y ) ∈ [ 0 , 1 ] R(x,y) \in[0,1] R ( x , y ) ∈ [ 0 , 1 ] be the relevant task reward, and define the performance of any autoregressive policy π \pi π by
J ( π ) : = E x ∼ D , y ∼ π ( ⋅ ∣ x ) R ( x , y ) . J(\pi) := \mathbb{E}_{x \sim\mathcal{D},\,y \sim\pi(\cdot\mid x)} R(x,y). J ( π ) := E x ∼ D , y ∼ π ( ⋅ ∣ x ) R ( x , y ) .
Let π ⋆ \pi^\star π ⋆ denote a fixed golden reference policy, π θ \pi_\theta π θ the student, and π T \pi_T π T a fixed teacher policy. For a policy π \pi π and prefix s t = ( x , y < t ) s_t=(x,y_{<t}) s t = ( x , y < t ) , let V t π ( s t ) V_t^\pi(s_t) V t π ( s t ) be the expected terminal reward when all remaining tokens are drawn from π \pi π , and let Q t π ( s t , v ) Q_t^\pi(s_t,v) Q t π ( s t , v ) be the expected terminal reward when the next token is fixed to v v v and subsequent tokens follow π \pi π . Observe that V t π ( s t ) = ∑ v π ( v ∣ s t ) Q t π ( s t , v ) V_t^\pi(s_t)=\sum_v \pi(v\mid s_t)Q_t^\pi(s_t,v) V t π ( s t ) = ∑ v π ( v ∣ s t ) Q t π ( s t , v ) , and define the task-reward advantage A t π ( s t , v ) : = Q t π ( s t , v ) − V t π ( s t ) A_t^\pi(s_t,v):=Q_t^\pi(s_t,v)-V_t^\pi(s_t) A t π ( s t , v ) := Q t π ( s t , v ) − V t π ( s t ) . Finally, we denote d t π θ d_t^{\pi_\theta} d t π θ as the distribution of s t s_t s t obtained by sampling x ∼ D x\sim\mathcal{D} x ∼ D and the first t − 1 t-1 t − 1 student tokens.
Performance difference lemma. Let the teacher’s gap to the golden reference policy π ⋆ \pi^\star π ⋆ be Δ T : = J ( π ⋆ ) − J ( π T ) \Delta_T:=J(\pi^\star)-J(\pi_T) Δ T := J ( π ⋆ ) − J ( π T ) . Then, it holds that:
J ( π ⋆ ) − J ( π θ ) = Δ T ⏟ teacher competence gap + J ( π T ) − J ( π θ ) ⏟ student-teacher gap = Δ T − ∑ t = 1 H E s t ∼ d t π θ , v ∼ π θ ( ⋅ ∣ s t ) A t π T ( s t , v ) . \begin{aligned}
J(\pi^\star)-J(\pi_\theta)
&= \underbrace{\Delta_T}_{\text{teacher competence gap}}+\underbrace{J(\pi_T)-J(\pi_\theta)}_{\text{student-teacher gap}}\\
&=\Delta_T-\sum_{t=1}^{H}\mathbb{E}_{s_t\sim d_t^{\pi_\theta},\,v\sim\pi_\theta(\cdot\mid s_t)}A_t^{\pi_T}(s_t,v).
\end{aligned} J ( π ⋆ ) − J ( π θ ) = teacher competence gap Δ T + student-teacher gap J ( π T ) − J ( π θ ) = Δ T − t = 1 ∑ H E s t ∼ d t π θ , v ∼ π θ ( ⋅ ∣ s t ) A t π T ( s t , v ) .
Under this setup, we now illustrate the potential of token-wise teacher selection, using the following intuitive result regarding the sum of the token-level advantages induced by the teacher on the right hand side of the above equality.
Lemma 1. Suppose we have access to two teachers π T 1 , π T 2 \pi_{T_1},\pi_{T_2} π T 1 , π T 2 , and we have a routing scheme p ( ⋅ ) p(\cdot) p ( ⋅ ) that maps prefix states s t s_t s t to { T 1 , T 2 } \{T_1,T_2\} { T 1 , T 2 } . Then, it holds that:
min p { − ∑ t = 1 H E s t ∼ d t π θ , v ∼ π θ ( ⋅ ∣ s t ) A t π p ( s t ) ( s t , v ) } ≤ − ∑ t = 1 H E s t ∼ d t π θ , v ∼ π θ ( ⋅ ∣ s t ) A t π T i ( s t , v ) for i = 1 , 2 \min_p\left\{-\sum_{t=1}^{H}\mathbb{E}_{s_t\sim d_t^{\pi_\theta},\,v\sim\pi_\theta(\cdot\mid s_t)}A_t^{\pi_{p(s_t)}}(s_t,v)\right\}
\leq-\sum_{t=1}^{H}\mathbb{E}_{s_t\sim d_t^{\pi_\theta},\,v\sim\pi_\theta(\cdot\mid s_t)}A_t^{\pi_{T_i}}(s_t,v)\quad\text{for }i=1,2 p min { − t = 1 ∑ H E s t ∼ d t π θ , v ∼ π θ ( ⋅ ∣ s t ) A t π p ( s t ) ( s t , v ) } ≤ − t = 1 ∑ H E s t ∼ d t π θ , v ∼ π θ ( ⋅ ∣ s t ) A t π T i ( s t , v ) for i = 1 , 2
Proof. This follows from the fact that the right hand side is just the routing scheme p ( ⋅ ) = T 1 p(\cdot)=T_1 p ( ⋅ ) = T 1 or p ( ⋅ ) = T 2 p(\cdot)=T_2 p ( ⋅ ) = T 2 .
This token-wise decomposition suggests an entire underexplored axis of teacher selection, and it is perfectly plausible that something as naive as section routing should yield better performance than a fixed teacher (nevertheless, we should generally hope for something more principled to exist). Henceforth, we will try to understand how we should perform this selection at the token-level. To begin, we will make the connection between the above student-teacher gap and the reverse KL loss through the following lemma, whose full proof is in Appendix § 9 .§ 1 .
Lemma 2. For each prefix s t s_t s t , define
L T , t ( θ ; s t ) : = K L ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t ) ) . L_{T,t}(\theta;s_t):=\mathrm{KL}(\pi_\theta(\cdot\mid s_t)\Vert\pi_T(\cdot\mid s_t)). L T , t ( θ ; s t ) := KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t )) .
Then, it holds that
∣ J ( π T ) − J ( π θ ) ∣ ≤ ∑ t = 1 H E s t ∼ d t π θ 1 2 L T , t ( θ ; s t ) . (3) \left|J(\pi_T)-J(\pi_\theta)\right| \le\sum_{t=1}^{H} \mathbb{E}_{s_t\sim d_t^{\pi_\theta}}\sqrt{\frac{1}{2}L_{T,t}(\theta;s_t)}. \tag*{(3)} ∣ J ( π T ) − J ( π θ ) ∣ ≤ t = 1 ∑ H E s t ∼ d t π θ 2 1 L T , t ( θ ; s t ) . (3)
Lemma 2 upper bounds the teacher-student imitation gap in terms of a sum of the different token-level KL terms. While this is not the exact gap term, it is a meaningful surrogate that allows tractable theoretical analysis. Furthermore, this is exactly what OPD optimizes for: minimizing the token-level KL between a student and a given teacher. In the next few sections, we will be concerned with understanding how to choose a teacher that minimizes this student-teacher imitation gap from quantifying the student-teacher compatibility, and using that to demonstrate a separation from the optimization perspective.
Unifying Representation- and Entropy-Based Routing
Setup. Let X \mathcal{X} X denote the set of prompts, V \mathcal{V} V denote the vocabulary, and V ⋆ \mathcal{V}^{\star} V ⋆ denote the set of finite sequences over V \mathcal{V} V . We work in the log-linear model family, which is defined by a fixed feature mapping ϕ : X × V ⋆ → R d \phi:\mathcal{X}\times\mathcal{V}^{\star}\to\mathbb{R}^{d} ϕ : X × V ⋆ → R d . Such a model family is parameterized by θ ∈ R d \theta\in\mathbb{R}^{d} θ ∈ R d , and for a given rollout of length H H H , we define ( π θ ) t = 1 H (\pi_\theta)_{t=1}^{H} ( π θ ) t = 1 H by:
π θ ( y t ∣ s t ) ∝ exp ( ⟨ θ , ϕ ( s t , y t ) ⟩ ) . \pi_\theta(y_t\mid s_t)\propto\exp\left(\left\langle\theta,\phi(s_t,y_t)\right\rangle\right). π θ ( y t ∣ s t ) ∝ exp ( ⟨ θ , ϕ ( s t , y t ) ⟩ ) .
Note that the log-linear setting is an abstraction of real-world autoregressive models such as transformers [49 ] with fixed hidden features. In our setting, we will assume that the student has fixed features ϕ ( ⋅ ) \phi(\cdot) ϕ ( ⋅ ) and trainable linear head θ ∈ R d \theta\in\mathbb{R}^{d} θ ∈ R d , and teacher i i i has fixed features ψ i ( ⋅ ) \psi_i(\cdot) ψ i ( ⋅ ) and linear head ω i ∈ R d \omega_i\in\mathbb{R}^{d} ω i ∈ R d . That is, we have the following:
π θ ( y t ∣ s t ) ∝ exp ( ⟨ θ , ϕ ( s t , y t ) ⟩ ) π T 1 ( y t ∣ s t ) ∝ exp ( ⟨ ω 1 , ψ 1 ( s t , y t ) ⟩ ) π T 2 ( y t ∣ s t ) ∝ exp ( ⟨ ω 2 , ψ 2 ( s t , y t ) ⟩ ) , \begin{aligned}
\pi_\theta(y_t\mid s_t)&\propto\exp\left(\left\langle\theta,\phi(s_t,y_t)\right\rangle\right)\\
\pi_{T_1}(y_t\mid s_t)&\propto\exp\left(\left\langle\omega_1,\psi_1(s_t,y_t)\right\rangle\right)\\
\pi_{T_2}(y_t\mid s_t)&\propto\exp\left(\left\langle\omega_2,\psi_2(s_t,y_t)\right\rangle\right),
\end{aligned} π θ ( y t ∣ s t ) π T 1 ( y t ∣ s t ) π T 2 ( y t ∣ s t ) ∝ exp ( ⟨ θ , ϕ ( s t , y t ) ⟩ ) ∝ exp ( ⟨ ω 1 , ψ 1 ( s t , y t ) ⟩ ) ∝ exp ( ⟨ ω 2 , ψ 2 ( s t , y t ) ⟩ ) ,
where ϕ ( ⋅ ) , ψ 1 ( ⋅ ) , ψ 2 ( ⋅ ) ∈ R d \phi(\cdot),\psi_1(\cdot),\psi_2(\cdot)\in\mathbb{R}^{d} ϕ ( ⋅ ) , ψ 1 ( ⋅ ) , ψ 2 ( ⋅ ) ∈ R d . Note that θ \theta θ is the only trainable parameter here, as we will not be training the teacher. In the exposition that follows, we will hold s t = ( x , y < t ) s_t=(x,y_{<t}) s t = ( x , y < t ) fixed, so that we can localize our analysis to the contribution of a single prefix.6 In addition, we will not consider the additive mixture models as we do in our empirical experiments; in other words, our theory analyzes only hard routing (τ = 0 \tau=0 τ = 0 ).
A unified framework. We briefly lay out some heuristic calculations on when we can expect different routing schemes to be beneficial. First, suppose that ρ i \rho_i ρ i is some scalar quantity that quantifies the alignment between the teacher and student features7 , and let θ 0 \theta_0 θ 0 denote the student head at initialization. Under our setup, the initial gradient can be written as:
− ∇ L T i , t ( θ 0 ; s t ) = ρ i ω i ⏟ accessible teacher signal − θ 0 , ⟹ ∥ ∇ L T i , t ( θ 0 ; s t ) ∥ 2 2 = ρ i 2 ∥ ω i ∥ 2 2 + ∥ θ 0 ∥ 2 2 − 2 ρ i ⟨ ω i , θ 0 ⟩ ≈ ρ i 2 ∥ ω i ∥ 2 2 . (4) \begin{aligned}
-\nabla L_{T_i,t}(\theta_0;s_t)&=\underbrace{\rho_i\omega_i}_{\text{accessible teacher signal}}-\theta_0,\\
\Longrightarrow\quad\left\|\nabla L_{T_i,t}(\theta_0;s_t)\right\|_2^2&=\rho_i^2\left\|\omega_i\right\|_2^2+\left\|\theta_0\right\|_2^2-2\rho_i\left\langle\omega_i,\theta_0\right\rangle\\
&\approx\rho_i^2\left\|\omega_i\right\|_2^2. \tag*{(4)}
\end{aligned} − ∇ L T i , t ( θ 0 ; s t ) ⟹ ∥ ∇ L T i , t ( θ 0 ; s t ) ∥ 2 2 = accessible teacher signal ρ i ω i − θ 0 , = ρ i 2 ∥ ω i ∥ 2 2 + ∥ θ 0 ∥ 2 2 − 2 ρ i ⟨ ω i , θ 0 ⟩ ≈ ρ i 2 ∥ ω i ∥ 2 2 . (4)
In this simplification, we observe that the main (scalar) quantities affecting the accessible teacher signal are the student-teacher representation alignment coefficient ρ i \rho_i ρ i , as well as the magnitude of the teacher head ∥ ω i ∥ 2 \left\|\omega_i\right\|_2 ∥ ω i ∥ 2 . Together, these two factors explain the complementary roles of the routing schemes. For instance, assuming different teacher head magnitudes are equal, choosing the more aligned teacher roughly maximizes the initial gradient norm. On the other hand, assuming that the teacher-student feature alignments are of roughly similar scale, choosing the teacher that has higher norm roughly corresponds to choosing the more confident teacher (and also maximizes the initial gradient norm). In particular, our theoretical analysis demonstrates that the initial gradient norm determines how much movement in parameter space will happen, and hence regulates how low we can get in terms of the reverse KL loss in Equation (3) . Of particular note is that as we have decoupled the contribution of teacher competence in the performance difference lemma, the teacher reward does not generally have an explicit contribution in this gradient. We defer a more detailed discussion of this to Appendix § 11 .
Representation-Based Teacher Routing
In this section, we will show two results about representation-based routing: how it 1) yields more gradient movement, and 2) yields more diversity over the overlapping feature space, which is beneficial when good modes are distributed relatively uniformly.
Our main result here is Theorem 1, which states that under mild conditions on the teacher and student features, the teacher that is more aligned with the student induces a larger gradient norm. For any function f f f of a candidate token, define the shorthand E t [ f ( v ) ] : = ∑ v ∈ V π θ 0 ( v ∣ s t ) f ( v ) \mathbb{E}_t[f(v)] := \sum_{v\in\mathcal{V}} \pi_{\theta_0}(v\mid s_t)f(v) E t [ f ( v )] := ∑ v ∈ V π θ 0 ( v ∣ s t ) f ( v ) where θ 0 \theta_0 θ 0 is the student head’s parameter at initialization. Consider the contribution of the reverse KL loss at token t t t of teacher i i i ,
L i , t ( θ ) : = ∑ v ∈ V π θ ( v ∣ s t ) log π θ ( v ∣ s t ) π T i ( v ∣ s t ) . L_{i,t}(\theta) := \sum_{v\in\mathcal{V}} \pi_\theta(v\mid s_t)\log\frac{\pi_\theta(v\mid s_t)}{\pi_{T_i}(v\mid s_t)}. L i , t ( θ ) := v ∈ V ∑ π θ ( v ∣ s t ) log π T i ( v ∣ s t ) π θ ( v ∣ s t ) .
We now connect this initial update to the time needed to reduce the teacher–student KL. Define the mean squared feature discrepancy and the initial gradient norm by
D i ( t ) : = E t ∥ ϕ ( s t , v ) − ψ i ( s t , v ) ∥ 2 2 , a i : = ∥ ∇ L i , t ( θ 0 ) ∥ 2 . D_i(t) := \mathbb{E}_t\left\lVert\phi(s_t,v)-\psi_i(s_t,v)\right\rVert_2^2,\qquad a_i := \left\lVert\nabla L_{i,t}(\theta_0)\right\rVert_2. D i ( t ) := E t ∥ ϕ ( s t , v ) − ψ i ( s t , v ) ∥ 2 2 , a i := ∥ ∇ L i , t ( θ 0 ) ∥ 2 .
Starting from the same student head θ 0 \theta_0 θ 0 , let θ n ( i ) \theta_n^{(i)} θ n ( i ) be the student head after n n n gradient updates using teacher i i i :
θ 0 ( i ) = θ 0 , θ n + 1 ( i ) = θ n ( i ) − η ∇ L i , t ( θ n ( i ) ) , \theta_0^{(i)}=\theta_0,\qquad\theta_{n+1}^{(i)}=\theta_n^{(i)}-\eta\nabla L_{i,t}\left(\theta_n^{(i)}\right), θ 0 ( i ) = θ 0 , θ n + 1 ( i ) = θ n ( i ) − η ∇ L i , t ( θ n ( i ) ) ,
where η > 0 \eta>0 η > 0 is the learning rate. For a target loss level 0 < ϵ < min i L i , t ( θ 0 ) 0<\epsilon<\min_i L_{i,t}(\theta_0) 0 < ϵ < min i L i , t ( θ 0 ) , define the learning time
N i ( ϵ ) : = inf { n ∈ Z ≥ 0 : L i , t ( θ n ( i ) ) ≤ ϵ } . N_i(\epsilon):=\inf\left\{n\in\mathbb{Z}_{\geq0}:L_{i,t}\left(\theta_n^{(i)}\right)\leq\epsilon\right\}. N i ( ϵ ) := inf { n ∈ Z ≥ 0 : L i , t ( θ n ( i ) ) ≤ ϵ } .
Then, we have the following separation in learning time.
Theorem 1 (Learning time guarantee for feature-based routing, abridged). Suppose that ∥ ω 1 ∥ 2 = ∥ ω 2 ∥ 2 \lVert\omega_1\rVert_2=\lVert\omega_2\rVert_2 ∥ ω 1 ∥ 2 = ∥ ω 2 ∥ 2 . Then, under suitable assumptions, we have that if D 1 ( t ) < D 2 ( t ) D_1(t)<D_2(t) D 1 ( t ) < D 2 ( t ) , then a 1 > a 2 a_1>a_2 a 1 > a 2 . For a sufficiently small learning rate η \eta η ,
N 1 ( ϵ ) = O ( 1 η a 1 2 ) ≲ N 2 ( ϵ ) = Ω ( 1 η a 2 2 ) . N_1(\epsilon)=O\left(\frac{1}{\eta a_1^2}\right)\lesssim N_2(\epsilon)=\Omega\left(\frac{1}{\eta a_2^2}\right). N 1 ( ϵ ) = O ( η a 1 2 1 ) ≲ N 2 ( ϵ ) = Ω ( η a 2 2 1 ) .
Proof sketch. Under mild assumptions, we can directly compute the gradients at initialization, the magnitude of which scales with decreasing D i ( t ) D_i(t) D i ( t ) . Using this, as well as smoothness of the loss landscape, we obtain an upper bound on N 1 ( ϵ ) N_1(\epsilon) N 1 ( ϵ ) and a lower bound on N 2 ( ϵ ) N_2(\epsilon) N 2 ( ϵ ) , which yields the separation. The full unabridged version of this theorem statement is in Appendix § 9 .§ 3 .
Confidence-Based Routing
We now consider the complementary setting where the two teachers share a feature map ψ \psi ψ , but with heads of differing magnitudes. It turns out that in this case, teacher confidence is correlated with the magnitude of its head, which consequently controls the magnitude of the gradient signal to the student. Fix the prefix s t s_t s t and initial student head θ 0 \theta_0 θ 0 as before, and define the teacher’s entropy by
H i : = − ∑ v ∈ V π T i ( v ∣ s t ) log π T i ( v ∣ s t ) . H_i:=-\sum_{v\in\mathcal{V}}\pi_{T_i}(v\mid s_t)\log\pi_{T_i}(v\mid s_t). H i := − v ∈ V ∑ π T i ( v ∣ s t ) log π T i ( v ∣ s t ) .
Theorem 2 (Learning time guarantee for entropy-based routing, abridged). Suppose ψ ( s t , v ) : = ψ 1 ( s t , v ) = ψ 2 ( s t , v ) \psi(s_t,v) := \psi_1(s_t,v) = \psi_2(s_t,v) ψ ( s t , v ) := ψ 1 ( s t , v ) = ψ 2 ( s t , v ) for every token v v v ; that is, the two teachers share the fixed features. Then , under suitable assumptions, we have that if H 1 < H 2 H_1 < H_2 H 1 < H 2 , then it holds that a 1 > a 2 a_1 > a_2 a 1 > a 2 . For a sufficiently small learning rate η \eta η , it holds that
N 1 ( ε ) = O ( 1 η a 1 2 ) ≲ N 2 ( ε ) = Ω ( 1 η a 2 2 ) . N_1(\varepsilon) = O\left(\frac{1}{\eta a_1^2}\right) \lesssim N_2(\varepsilon) = \Omega\left(\frac{1}{\eta a_2^2}\right). N 1 ( ε ) = O ( η a 1 2 1 ) ≲ N 2 ( ε ) = Ω ( η a 2 2 1 ) .
Proof sketch. Roughly speaking, the scale of teacher logits increases with the magnitude of ∥ ω i ∥ 2 \lVert\omega_i\rVert_2 ∥ ω i ∥ 2 . Therefore, under mild assumptions, we show that increasing ∥ ω i ∥ 2 \lVert\omega_i\rVert_2 ∥ ω i ∥ 2 increases the logit gaps between different tokens, thus strictly lowering the entropy. As such, teacher 1 will have a stronger pull, in the sense of a large gradient, and from there, we can conclude the proof in a similar manner as Theorem 1 to obtain the separation. The full proof is deferred to Appendix § 10 .
Overlap with Good Solutions and Coverage
There is an additional benefit of our representation-based routing scheme from § 4.3 worth highlighting. Assuming high-quality modes are uniformly distributed, choosing a more aligned teacher gives a stronger guarantee on how many of these modes the optimized student retains. Put simply, we have stronger guarantees on the diversity over good responses learned by the student. We present the abridged theorem here.
Theorem 3 (Diversity guarantee, abridged). Let G 1 , … , G M G_1,\ldots,G_M G 1 , … , G M be disjoint, nonempty next-token sets identifying M ≥ 1 M \ge1 M ≥ 1 successful continuation modes. Assume a fixed shared continuation mechanism: tokens in G j G_j G j lead to success in mode j j j , and tokens outside their union fail; moreover, suppose that both teachers place probability c / M c/M c / M on each mode, for some common success probability c ∈ ( 0 , 1 ) c \in(0,1) c ∈ ( 0 , 1 ) . Then , there exists a teacher-dependent error term e i ∈ [ 0 , c / M ) e_i \in[0,c/M) e i ∈ [ 0 , c / M ) that increases as D i ( t ) D_i(t) D i ( t ) increases, which satisfies that the expected number of distinct successful modes observed in k k k independent samples from π θ i ∗ \pi_{\theta_i^*} π θ i ∗ is at least M [ 1 − ( 1 − c / M + e i ) k ] M\left[1-\left(1-c/M+e_i\right)^k\right] M [ 1 − ( 1 − c / M + e i ) k ] , where θ i ∗ = arg min θ L i , t ( θ ) \theta_i^* = \arg\min_\theta L_{i,t}(\theta) θ i ∗ = arg min θ L i , t ( θ ) .
Proof sketch. The feature overlap provides the direction for learnable teacher signal. Under the uniform mode assumption, we can prove that the student, when optimized against teacher i i i , will retain at least c / M − e i c/M-e_i c / M − e i probability on every mode, yielding the desired result.
Furthermore, a related concept is the coverage profile perspective of Chen et al. [ [5 ] , which characterizes how well a distribution covers some target distribution (and is also predictive of pass@k k k performance). For our setting, let ν ( j ) : = 1 / M \nu(j) := 1/M ν ( j ) := 1/ M be the target distribution, uniform over the M M M good modes. For a threshold parameter N > 1 / c N > 1/c N > 1/ c , we adapt the framework in Chen et al. [ [5 ] to define the undercoverage by
C N m o d e ( ν ∥ π θ i ∗ ) : = 1 M ∑ j = 1 M 1 { π θ i ∗ ( G j ) ≤ 1 M N } . (5) C_N^{\mathrm{mode}}(\nu\Vert\pi_{\theta_i^*}) := \frac{1}{M}\sum_{j=1}^{M}\mathbf{1}\left\{\pi_{\theta_i^*}(G_j) \le\frac{1}{MN}\right\}. \tag*{(5)} C N mode ( ν ∥ π θ i ∗ ) := M 1 j = 1 ∑ M 1 { π θ i ∗ ( G j ) ≤ M N 1 } . (5)
Corollary 1 (Undercoverage of successful modes). *In the setting of Theorem 3, for every N > 1 / c N > 1/c N > 1/ c ,
C N m o d e ( ν ∥ π θ i ∗ ) ≤ e i c − 1 / N . C_N^{\mathrm{mode}}(\nu\Vert\pi_{\theta_i^*}) \le\frac{e_i}{c-1/N}. C N mode ( ν ∥ π θ i ∗ ) ≤ c − 1/ N e i .
We remark that our analysis here provides a comparison of the lower bounds of expected number of distinct modes, rather than the value itself. Nevertheless, we believe it is still a reasonable surrogate to look at; our experiments demonstrate that our representation-matching method indeed yields higher pass@k k k even when pass@1 is not necessarily higher. We give the full proof of all results above in Appendix § 9 .§ 4 .
Experimental Results
We study token-level teacher selection in settings that encompass the domains of math, coding, Triton kernel generation, and visual reasoning8 . More specifically, we consider the following setups:
A synthetic math-triton task with access to respective math and Triton teachers where there is a clear way to perform teacher selection via section routing (§ 5.1 )
A Triton-only task with access to a thinking model and a domain expert (§ 5.2 )
Algorithmic coding tasks under a math and code teacher (§ 5.3 )
Precise scoring functions used are defined in Appendix § 12 .§ 2 , as they may differ in implementation from our theoretical formulations in § 4 . One concrete example of this is when we choose to use the Hellinger score instead of the feature distance score in some cases, due to the teacher and student having different architectures. Additional training details and evaluation protocols are given in Appendices § 13 and § 14 . Notably, for our score-based routing frameworks, we will generally sweep through several temperatures τ \tau τ , as well as choices of policy gradient implementation (i.e. either sampled token advantage or the Top-K KL). For sampled token advantage, we use τ = 0 \tau= 0 τ = 0 (i.e. hard routing) by default. In our tables, besides reporting results on token-level routing, we also report baselines of vanilla OPD (which uses sampled token advantage by default), as well as the teachers and initial student performance.
A Synthetic Math-Triton Task
We construct more than 8000 training prompts by pairing DeepMath problems [14 ] with KernelBook tasks [33 ] . Each prompt requests both solutions, with the task order assigned randomly and held fixed. The student model we use is a Qwen3-4B [37 ] , using the non-base variant with thinking mode off. For the teachers, we use a Qwen3-4B that has gone through math RL training on DeepMath, as well as the Dr.Kernel-8B [22 ] . We train the student for 300 updates on these composite prompts.
For evaluation, we use the size 3000 set of AIME 2025 × \times × KernelBench Level 2 [30 , 31 ] combinations (30 AIME problems and 100 KernelBench Level 2 problems). Joint success requires a correct math answer and a correct kernel in the same response, with kernel correctness measured by f a s t 0 \mathrm{fast}_0 fast 0 , which gives a binary reward purely depending on correctness, without regard to speedup. Our results are shown in Table 1 , in which we compare against the baselines of the initial student model, the teachers, and vanilla OPD. With token-level routing, our Hellinger routing metric performs the best on this joint f a s t 0 \mathrm{fast}_0 fast 0 score, for both pass@1 and pass@16, reaching 29.30% on pass@16, which is close to 10 percentage points over vanilla OPD on either teacher, the entropy-routing training, and even the naive section-routing variant.
Table 1. AIME 2025 × \times × KernelBench L2 (%). Joint fast0 _0 0 requires correctness of both components in one response (higher is better); we also report the math-portion and kernel-portion breakdown for completeness. Note that for the sampled advantage Hellinger routing, the scores on each individual section recover roughly the teacher performance, and together yield the highest joint score.
To solve the largest rectangular area in a histogram problem efficiently in O ( N ) O(N) O ( N ) time and O ( N ) O(N) O ( N ) space, we can use a monotonic stack approach.
Intuition:
For each bar, we want to find:
[. . .]
Python Code:
def getMaxArea(arr):
stack = []
max_area = 0
n = len(arr)
for i in range(n):
while stack and arr[i] < arr[stack[-1]]:
height = arr[stack.pop()]
width = i if not stack else i - stack[-1] - 1
max_area = max(max_area, height * width)
stack.append(i)
[. . .]
return max_area
Test Cases:
# Example 1
print(getMaxArea([6, 2, 5, 4, 5, 1, 6])) # Output: 12
[. . .]
Triton-only Task with Thinking Mode
In this setting, we consider a Qwen3-4B student with thinking mode turned on and train it to generate Triton kernels. For the teachers, we will use the Qwen3-30B-A3B-Thinking model and Dr.Kernel-8B, with the goal of combining general reasoning ability with specialized domain knowledge in Triton. We train the student for 300 steps on KernelBook tasks.
For evaluation, we use the 100 KernelBench Level 2 benchmark problems. In Table 2 , we compare our token-level routing schemes with the base model, the Triton expert, and vanilla OPD. In this thinking model setup, it turns out that entropy-based routing performs the best for fast0 _0 0 score. In contrast to the previous settings, entropy-based is more effective than the Hellinger-based routing. We illustrate this using an example rollout in Figure 1 .
Figure 1. Triton-only entropy routing (τ = 0.1 \tau= 0.1 τ = 0.1 ; iteration 300). Here, we plot the score gap of the kernel teacher minus the thinking teacher. The full trace is included in Appendix § 15 .§ 3 , where we can observe that the blue (positive) regions on this plot correspond roughly to parts of the student rollout where Triton code is being generated, and the red parts correspond to general reasoning or thinking behavior to plan the kernel code.
Table 2. Triton-only evaluation on 100 KernelBench Level 2 tasks (%). F a s t 0 \mathrm{Fast}_0 Fast 0 measures kernel correctness.
Algorithmic Coding
For algorithmic coding, we keep the Qwen3-4B non-base variant as the initial student. For the teachers, we first train a code RL expert using more than 25000 Eurus-2-RL code prompts [9 ] . We also use the teacher trained via math RL from the previous synthetic task, and these two teachers form the domain experts that we use in this algorithmic coding setting, where it is reasonable to expect mathematical ability may improve algorithmic thinking and coding ability. Then, we train the student for 300 updates on code-only problems from Eurus-2-RL.
For evaluation, we use HumanEval+ and MBPP+ benchmarks [6 , 2 , 21 ] . Our results are presented in Table 3 , in which we compare against the baselines of the initial student model, the RL math and RL code teachers, as well as vanilla OPD. With token-level routing, the training with the feature-matching scheme shows improvements for pass@64 over all of the other baselines, despite not necessarily having higher pass@1. This pattern is consistent with our theory of preserving coverage of successful responses in § 4.5 . Finally, we also illustrate in Figure 2 an example of how the feature matching scheme routes the teacher across a single student rollout.
Figure 2. Abridged rollout on algorithmic coding task by a student trained with feature routing, at step 300. Here, the text is colored by the code-minus-math routing score. Note that the coloring demonstrates that the reasoning part of the rollout leans more towards the math teacher, and the Python implementation is markedly closer to the code teacher. Omitted text is marked by [. . .], and the full per-token score gap and complete rollout are in Figure 3 and Appendix § 15 .§ 2 .
Table 3. Algorithmic coding correctness (%). Although our feature-matching selection does not achieve the highest pass@1, it shows improvements for pass@64, indicating the benefits of diversity of this router.
Interpreting Effective Routing Schemes
We note that in the above three settings, Hellinger- or feature-based routing performed better on the code-only task and the synthetic Triton-math task, whereas the entropy-based routing performed better on the Triton-thinking task. Looking back at Equation (4) , we observe that when the LLM heads have similar magnitudes, the feature alignment ρ \rho ρ is the useful router. Under the code-only and Triton-math task, we have access to teachers which are essentially fine-tuned versions of the base model. Empirically speaking, fine-tuning should not change head norms ∥ ω ∥ 2 \lVert\omega\rVert_2 ∥ ω ∥ 2 by much, and as such the feature alignment becomes the important term. Analogously, Equation (4) demonstrates that when the teacher features are equally (mis-)aligned with the student features, entropy becomes the useful router. Indeed, in the Triton-thinking task, neither teacher is from the same model family as the base model, so the student and the teachers naturally do not have much feature alignment. In that sense, we would expect the entropy-based routing to be more effective, which it indeed is.
Conclusion
In this work, we explore token-level teacher routing as an additional axis for OPD training. To that end, we propose a theoretical framework in the log-linear setting to unify existing classes of teacher selection methods (e.g. entropy-based) as well as a new class of representation-based routing that we propose. Together, these allow us to predict empirically when one scheme may be more beneficial than the other, in the context of the trained student’s ability and output diversity. We believe there is room for much more design and improvement on this axis, as well as understanding of its downstream benefits. For instance, an interesting open question would be to understand if the diversity improvements of our teacher selection scheme can be used to create a better warm start for RL post-OPD. In addition, it would also be worthwhile to derive teacher selection metrics that are more reward-aware, beyond simply choosing the strongest teacher.
AI use statement
In this work, we used generative AI tools for literature search, writing code, and brainstorming ideas. We have reviewed all AI-assisted work. We take responsibility for the final content of this work, including text, claims or artifacts produced with the aid of generative AI.
Related Work
LLM post-training. Post-training LLMs with RL has generally concerned optimizing for some reward, such as a learned preference reward in RLHF [8 , 32 ] or a verifiable one in RLVR [10 ] . Beyond recent algorithmic innovations to the classic policy gradient algorithms [55 , 47 ] such as TRPO and PPO [40 , 41 ] , a growing line of theoretical work has been aimed towards understanding what sorts of reward models yield favorable optimization guarantees [39 , 42 ] . In addition, there has also been an extensive line of work understanding the interplay between on- and off-policy data in training, most notably in contrasting the post-training phases of SFT and RL [45 , 53 , 35 , 28 , 16 ] .
On-policy distillation. On-policy distillation (OPD) replaces the scalar reward in RL with dense token-level supervision from a teacher queried on the student’s own rollouts [15 , 1 ] . G-OPD connects vanilla OPD to KL-regularized RL and separates the reward scale from the regularization strength [57 ] , and recent work by Li et al. [2026a] finds that OPD followed by RL outperforms RL alone. A related line of work in the direction of OPD is on-policy self-distillation (OPSD), which removes the separate teacher by conditioning the same model on privileged context such as a reference solution [61 ] , with unsupervised [20 ] and shortcut-purified [44 ] variants. In addition, MOPD is a way to distill from several independently trained domain experts [26 ] .
OPD dynamics and prefix drift. Several recent works examine why dense teacher feedback can nonetheless be hard to learn from. For instance, Fu et al. [2026a] separate the token-local update from the sequence-level reverse KL gradient and identify imbalanced sampled-token signals and support mismatch as failure modes; Li et al. [2026b] find that compatible thinking patterns and genuinely new capabilities are distinct conditions for transfer; and Fu et al. [2026b] show that a single query already induces broad state visitation while the supervision itself is incorporated slowly. On the theory side, Zhang et al. [2026] show that the advantage of online over offline imitation in post-training hinges on non-realizability of the expert rather than on horizon-driven error accumulation, and Sriraman et al. [2026] show that with noisy expert feedback, OPD attains polynomial rather than exponential-in-horizon sample complexity. Additional analyses have suggested that prefixes are generally off-policy for the teacher: early-token supervision is more effective than late-token supervision [56 ] , teacher confidence decays along student rollouts [23 ] , and student–teacher mismatch invites length-dependent exploitation of the objective [51 ] . Our work provides an additional theoretical perspective for understanding teachers that yield good optimization guarantees under OPD.
Teacher selection, student compatibility, and token-level supervision. A more general line of work that spans the knowledge distillation literature is understanding teacher suitability for the student. For example GRACE scores teachers by the distribution of student gradients on their outputs [34 ] , and the Rank–Surprisal Ratio proposed by Yang et al. [2026b] balances alignment with the student against informativeness. Indeed, both of these above works choose a teacher once for the entire training duration. H-OPD [59 ] suggests the use of confidence as a way to do token-level routing, but their analysis is limited to the setting of vision tasks. Some more recent works analyze the other end of the spectrum, which is to see how little supervision one can get away with in OPD while preserving its advantages. For instance, OPSA replaces the teacher advantage with low-probability tokens [11 ] , and Liu et al. [2026c] supervise only one or two tokens per rollout. Our insight then, is that if we specialize to the on-policy training case, then we can naturally extend teacher arbitration to the token level, using different routing schemes depending on the setting.
Interventions for better coverage. The coverage principle of Chen et al. [2025] argues that the probability a model already assigns to high-quality responses governs what post-training and test-time selection can achieve. This framework has guided several follow-up works in terms of better interventions for improving coverage. For instance, TailSFT filters already-fit sequences out of SFT so that learning concentrates on under-modeled regions, improving pass@k k k before RL [27 ] . In addition, Cheng et al. [2026] trace the gap between pass@1 1 1 gains and pass@N N N losses after RL to a reshaping of strategy selection and connect it to coverage and transfer. The OPD-then-RL setup of Li et al. [2026a] can also be interpreted as first broadening the set of teacher-supported solutions and then concentrating probability on the successful ones. Moreover, Tuyls et al. [ [48 ] also designs a representation-aware RL post-training scheme in order to induce better diversity of output responses. In our work, we prove that our representation-based teacher selection scheme in § 4.3 is coverage-aware in a similar spirit; that is, our diversity analysis in § 4.5 upper bounds the undercoverage quantity of high-quality continuations.
Proofs of the Feature-Matching Teacher Selection
We briefly describe the organization of this section below. First, in Appendix § 9 .§ 1 , we describe how teacher competence (as measured in expected reward) and teacher-student compatibility complement each other in terms of the training outcome of OPD, via the performance difference lemma; notably, this also allows us to realize the potential of token-level teacher selection over using only a single teacher. Then, in Appendix § 9 .§ 2 , we list out the properties of the gradient and optimization landscape at initialization to work towards a proof of Theorem 1. Afterwards, in Appendix § 9 .§ 3 , we explicitly quantify the benefit of using our feature-matching selection scheme to give the full proof of Theorem 1. Finally in Appendix § 9 .§ 4 , we provide the full proofs on how our selection scheme can improve the coverage of good response modes.
Why Minimize Token-Level KL? A Performance-Difference View
Recall the performance difference lemma:
J ( π ∗ ) − J ( π θ ) = Δ T ⏟ teacher competence gap + J ( π T ) − J ( π θ ) ⏟ student-teacher gap = Δ T − ∑ t = 1 H E s t ∼ d t θ , v ∼ π θ ( ⋅ ∣ s t ) A t π T ( s t , v ) = Δ T + ∑ t = 1 H E s t ∼ d t θ ∑ v ∈ V ( π T ( v ∣ s t ) − π θ ( v ∣ s t ) ) Q t π T ( s t , v ) . (6) \begin{aligned}
J(\pi^*) - J(\pi_\theta) = \underbrace{\Delta_T}_{\text{teacher competence gap}} + \underbrace{J(\pi_T) - J(\pi_\theta)}_{\text{student-teacher gap}} \\
&= \Delta_T - \sum_{t=1}^{H} \mathbb{E}_{s_t \sim d_t^\theta,\ v \sim\pi_\theta(\cdot\mid s_t)} A_t^{\pi_T}(s_t,v) \\
&= \Delta_T + \sum_{t=1}^{H} \mathbb{E}_{s_t \sim d_t^\theta} \sum_{v \in\mathcal{V}} \left(\pi_T(v \mid s_t) - \pi_\theta(v \mid s_t)\right) Q_t^{\pi_T}(s_t,v). \tag*{(6)}
\end{aligned} J ( π ∗ ) − J ( π θ ) = teacher competence gap Δ T + student-teacher gap J ( π T ) − J ( π θ ) = Δ T − t = 1 ∑ H E s t ∼ d t θ , v ∼ π θ ( ⋅ ∣ s t ) A t π T ( s t , v ) = Δ T + t = 1 ∑ H E s t ∼ d t θ v ∈ V ∑ ( π T ( v ∣ s t ) − π θ ( v ∣ s t ) ) Q t π T ( s t , v ) . (6)
We now prove Lemma 2 from the main text.
Proof of Lemma 2. Since the terminal reward lies in [ 0 , 1 ] [0,1] [ 0 , 1 ] , its conditional expectation Q t π T ( s t , v ) Q_t^{\pi_T}(s_t,v) Q t π T ( s t , v ) also lies in [ 0 , 1 ] [0,1] [ 0 , 1 ] for every prefix s t s_t s t and token v v v . Moreover, the student and teacher probabilities each sum to one. Thus, for every fixed prefix,
∣ ∑ v ∈ V ( π T ( v ∣ s t ) − π θ ( v ∣ s t ) ) Q t π T ( s t , v ) ∣ = ∣ ∑ v ∈ V ( π T ( v ∣ s t ) − π θ ( v ∣ s t ) ) ( Q t π T ( s t , v ) − 1 2 ) ∣ ≤ 1 2 ∑ v ∈ V ∣ π T ( v ∣ s t ) − π θ ( v ∣ s t ) ∣ = TV ( π θ ( ⋅ ∣ s t ) , π T ( ⋅ ∣ s t ) ) , \begin{aligned}
\left|\sum_{v \in\mathcal{V}} \left(\pi_T(v \mid s_t) - \pi_\theta(v \mid s_t)\right) Q_t^{\pi_T}(s_t,v)\right| \\
&= \left|\sum_{v \in\mathcal{V}} \left(\pi_T(v \mid s_t) - \pi_\theta(v \mid s_t)\right) \left(Q_t^{\pi_T}(s_t,v) - \frac{1}{2}\right)\right| \\
&\le\frac{1}{2} \sum_{v \in\mathcal{V}} \left|\pi_T(v \mid s_t) - \pi_\theta(v \mid s_t)\right| \\
&= \operatorname{TV}\left(\pi_\theta(\cdot\mid s_t), \pi_T(\cdot\mid s_t)\right),
\end{aligned} v ∈ V ∑ ( π T ( v ∣ s t ) − π θ ( v ∣ s t ) ) Q t π T ( s t , v ) = v ∈ V ∑ ( π T ( v ∣ s t ) − π θ ( v ∣ s t ) ) ( Q t π T ( s t , v ) − 2 1 ) ≤ 2 1 v ∈ V ∑ ∣ π T ( v ∣ s t ) − π θ ( v ∣ s t ) ∣ = TV ( π θ ( ⋅ ∣ s t ) , π T ( ⋅ ∣ s t ) ) ,
where TV denotes total variation distance. By Pinsker’s inequality,
TV ( π θ ( ⋅ ∣ s t ) , π T ( ⋅ ∣ s t ) ) ≤ 1 2 KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t ) ) = 1 2 L T , t ( θ ; s t ) . \operatorname{TV}\left(\pi_\theta(\cdot\mid s_t), \pi_T(\cdot\mid s_t)\right) \le\sqrt{\frac{1}{2}\operatorname{KL}\left(\pi_\theta(\cdot\mid s_t) \mathbin{\|} \pi_T(\cdot\mid s_t)\right)} = \sqrt{\frac{1}{2}L_{T,t}(\theta; s_t)}. TV ( π θ ( ⋅ ∣ s t ) , π T ( ⋅ ∣ s t ) ) ≤ 2 1 KL ( π θ ( ⋅ ∣ s t ) ∥ π T ( ⋅ ∣ s t ) ) = 2 1 L T , t ( θ ; s t ) .
Finally, apply the triangle inequality to the student-teacher gap in Equation (6) and use the pointwise bound:
∣ J ( π T ) − J ( π θ ) ∣ ≤ ∑ t = 1 H E s t ∼ d t π θ ∣ ∑ v ∈ V ( π T ( v ∣ s t ) − π θ ( v ∣ s t ) ) Q t π T ( s t , v ) ∣ ≤ ∑ t = 1 H E s t ∼ d t π θ 1 2 L T , t ( θ ; s t ) . \begin{aligned}
\left|J(\pi_T)-J(\pi_\theta)\right| \le\sum_{t=1}^{H}\mathbb{E}_{s_t\sim d_t^{\pi_\theta}}\left|\sum_{v\in\mathcal{V}}\left(\pi_T(v\mid s_t)-\pi_\theta(v\mid s_t)\right)Q_t^{\pi_T}(s_t,v)\right| \\
&\le\sum_{t=1}^{H}\mathbb{E}_{s_t\sim d_t^{\pi_\theta}}\sqrt{\frac{1}{2}L_{T,t}(\theta;s_t)}.
\end{aligned} ∣ J ( π T ) − J ( π θ ) ∣ ≤ t = 1 ∑ H E s t ∼ d t π θ v ∈ V ∑ ( π T ( v ∣ s t ) − π θ ( v ∣ s t ) ) Q t π T ( s t , v ) ≤ t = 1 ∑ H E s t ∼ d t π θ 2 1 L T , t ( θ ; s t ) .
This proves the claim.
Proofs for Gradients at Initialization
For the rest of this section, we simply fix a prefix state s t = ( x , y < t ) s_t=(x,y_{<t}) s t = ( x , y < t ) and prompt x x x . Recall that we are working in the setting of log-linear model families, for both the student and teachers. For the student model, we have their frozen features to be ϕ ( s t , v ) ∈ R d \phi(s_t,v)\in\mathbb{R}^{d} ϕ ( s t , v ) ∈ R d , and similarly for the teachers i i i , which have features ψ i ( s t , v ) ∈ R d \psi_i(s_t,v)\in\mathbb{R}^{d} ψ i ( s t , v ) ∈ R d for i = 1 , 2 i=1,2 i = 1 , 2 . For the student, the only trainable parameter is its linear head θ ∈ R d \theta\in\mathbb{R}^{d} θ ∈ R d , and let θ 0 \theta_0 θ 0 be its initial value. Similarly, ω i ∈ R d \omega_i\in\mathbb{R}^{d} ω i ∈ R d are the fixed heads of the teachers i i i , though those will be fixed as we do not train the teachers.
Then, we have the following policies conditioned on s t s_t s t :
π θ ( v ∣ s t ) = e θ ⊤ ϕ ( s t , v ) Z S ( θ ; s t ) , π T i ( v ∣ s t ) = e ω i ⊤ ψ i ( s t , v ) Z T i ( s t ) , \pi_\theta(v\mid s_t)=\frac{e^{\theta^\top\phi(s_t,v)}}{Z_S(\theta;s_t)},\qquad\pi_{T_i}(v\mid s_t)=\frac{e^{\omega_i^\top\psi_i(s_t,v)}}{Z_{T_i}(s_t)}, π θ ( v ∣ s t ) = Z S ( θ ; s t ) e θ ⊤ ϕ ( s t , v ) , π T i ( v ∣ s t ) = Z T i ( s t ) e ω i ⊤ ψ i ( s t , v ) ,
where Z S Z_S Z S and Z T i Z_{T_i} Z T i are normalizing terms over V \mathcal{V} V . For the teacher i i i that we choose, the loss is the reverse KL loss:
L i ( θ ) = L i , t ( θ ) : = ∑ v ∈ V π θ ( v ∣ s t ) log π θ ( v ∣ s t ) π T i ( v ∣ s t ) . L_i(\theta)=L_{i,t}(\theta):=\sum_{v\in\mathcal{V}}\pi_\theta(v\mid s_t)\log\frac{\pi_\theta(v\mid s_t)}{\pi_{T_i}(v\mid s_t)}. L i ( θ ) = L i , t ( θ ) := v ∈ V ∑ π θ ( v ∣ s t ) log π T i ( v ∣ s t ) π θ ( v ∣ s t ) .
When it is clear from the exposition, we will sometimes omit s t s_t s t in our notations of the features or policies, or use alternative notation that will be defined when needed.
In the rest of the section, we will give a closed form expression for the gradient under our mild assumptions. Then, we will proceed to prove Theorem 1.
Additional notation. Recall that θ 0 \theta_0 θ 0 is the student head at initialization, ω i \omega_i ω i is the fixed head of teacher i i i , and ϕ ( s t , v ) , ψ i ( s t , v ) \phi(s_t,v),\psi_i(s_t,v) ϕ ( s t , v ) , ψ i ( s t , v ) are the respective d d d -dimensional feature vectors at the same prefix s t s_t s t . In addition, we define the notation
E t [ f ] : = ∑ v π θ 0 ( v ∣ s t ) f ( v ) \mathbb{E}_t[f]:=\sum_v\pi_{\theta_0}(v\mid s_t)f(v) E t [ f ] := v ∑ π θ 0 ( v ∣ s t ) f ( v )
for the expectation of a function f f f over the student policy π θ 0 \pi_{\theta_0} π θ 0 (i.e. the student at initialization). Using this notation, we define the following feature means and covariance matrices:
ϕ ˉ t : = E t [ ϕ ( s t , v ) ] , ψ ˉ i , t : = E t [ ψ i ( s t , v ) ] , \bar{\phi}_t:=\mathbb{E}_t[\phi(s_t,v)],\qquad\bar{\psi}_{i,t}:=\mathbb{E}_t[\psi_i(s_t,v)], ϕ ˉ t := E t [ ϕ ( s t , v )] , ψ ˉ i , t := E t [ ψ i ( s t , v )] ,
F t : = E t [ ( ϕ − ϕ ˉ t ) ( ϕ − ϕ ˉ t ) ⊤ ] , C i ( t ) : = E t [ ( ϕ − ϕ ˉ t ) ( ψ i − ψ ˉ i , t ) ⊤ ] . F_t:=\mathbb{E}_t[(\phi-\bar{\phi}_t)(\phi-\bar{\phi}_t)^\top],\qquad C_i(t):=\mathbb{E}_t[(\phi-\bar{\phi}_t)(\psi_i-\bar{\psi}_{i,t})^\top]. F t := E t [( ϕ − ϕ ˉ t ) ( ϕ − ϕ ˉ t ) ⊤ ] , C i ( t ) := E t [( ϕ − ϕ ˉ t ) ( ψ i − ψ ˉ i , t ) ⊤ ] .
That is, F t F_t F t is the student feature covariance, and C i ( t ) C_i(t) C i ( t ) is the student-teacher cross-covariance. Furthermore, we also define notation for gradient related terms:
d i ( t ) : = − ∇ L i ( θ 0 ) , a i : = ∥ d i ( t ) ∥ 2 , d_i(t):=-\nabla L_i(\theta_0),\qquad a_i:=\lVert d_i(t)\rVert_2, d i ( t ) := − ∇ L i ( θ 0 ) , a i := ∥ d i ( t ) ∥ 2 ,
as well as the mean squared feature discrepancy between the teacher and student:
D i ( t ) : = E t ∥ ϕ ( s t , v ) − ψ i ( s t , v ) ∥ 2 2 . D_i(t):=\mathbb{E}_t\lVert\phi(s_t,v)-\psi_i(s_t,v)\rVert_2^2. D i ( t ) := E t ∥ ϕ ( s t , v ) − ψ i ( s t , v ) ∥ 2 2 .
We make the following assumptions at initialization. Let I d I_d I d denote the d × d d\times d d × d identity matrix, and abbreviate the features ϕ ( s t , v ) , ψ i ( s t , v ) \phi(s_t,v),\psi_i(s_t,v) ϕ ( s t , v ) , ψ i ( s t , v ) by ϕ , ψ i \phi,\psi_i ϕ , ψ i inside expectations.
Assumption 1 (Initialization whitening and teacher-student alignment). At initialization, the features are centered and whitened under π θ 0 ( ⋅ ∣ s t ) \pi_{\theta_0}(\cdot\mid s_t) π θ 0 ( ⋅ ∣ s t ) :
E t [ ϕ ] = E t [ ψ i ] = 0 , E t [ ϕ ϕ T ] = E t [ ψ i ψ i T ] = I d . \mathbb{E}_t[\phi]=\mathbb{E}_t[\psi_i]=0,\qquad\mathbb{E}_t[\phi\phi^{\mathsf{T}}]=\mathbb{E}_t[\psi_i\psi_i^{\mathsf{T}}]=I_d. E t [ ϕ ] = E t [ ψ i ] = 0 , E t [ ϕ ϕ T ] = E t [ ψ i ψ i T ] = I d . Moreover, for each teacher i ∈ { 1 , 2 } i \in\{1,2\} i ∈ { 1 , 2 } , we have E t [ ϕ ψ i T ] = ρ i I d \mathbb{E}_t[\phi\psi_i^{\mathsf{T}}]=\rho_i I_d E t [ ϕ ψ i T ] = ρ i I d with ρ i ∈ [ 0 , 1 ] \rho_i \in[0,1] ρ i ∈ [ 0 , 1 ] .
Assumption 2 (Comparable teacher head scales). The teacher heads satisfy ∥ ω i ∥ 2 = W > 0 \lVert\omega_i\rVert_2=W>0 ∥ ω i ∥ 2 = W > 0 and ⟨ ω i , θ 0 ⟩ = b \langle\omega_i,\theta_0\rangle=b ⟨ ω i , θ 0 ⟩ = b , with the same scalars W W W and b b b for both teachers.
The following lemma gives the initial gradient for using either teacher in the student loss function. We then use these identities to compare the two teachers.
Lemma 3 (Initial gradient). Under Assumptions 1 and 2, when the gradient is taken with respect to teacher π T i \pi_{T_i} π T i , we have:
D i ( t ) = 2 d ( 1 − ρ i ) , d i ( t ) = ρ i ω i − θ 0 , D_i(t)=2d(1-\rho_i),\qquad d_i(t)=\rho_i\omega_i-\theta_0, D i ( t ) = 2 d ( 1 − ρ i ) , d i ( t ) = ρ i ω i − θ 0 , a i 2 = W 2 ρ i 2 + ∥ θ 0 ∥ 2 2 − 2 b ρ i . (7) a_i^2=W^2\rho_i^2+\lVert\theta_0\rVert_2^2-2b\rho_i. \tag*{(7)} a i 2 = W 2 ρ i 2 + ∥ θ 0 ∥ 2 2 − 2 b ρ i . (7)
Proof. Recall that
L i ( θ ) = L i , t ( θ ) : = ∑ v ∈ V π θ ( v ∣ s t ) log π θ ( v ∣ s t ) π T i ( v ∣ s t ) . L_i(\theta)=L_{i,t}(\theta):=\sum_{v\in\mathcal{V}}\pi_\theta(v\mid s_t)\log\frac{\pi_\theta(v\mid s_t)}{\pi_{T_i}(v\mid s_t)}. L i ( θ ) = L i , t ( θ ) := v ∈ V ∑ π θ ( v ∣ s t ) log π T i ( v ∣ s t ) π θ ( v ∣ s t ) .
Since ∑ v ∇ π θ ( v ∣ s t ) = 0 \sum_v\nabla\pi_\theta(v\mid s_t)=0 ∑ v ∇ π θ ( v ∣ s t ) = 0 , it holds that
∇ L i ( θ ) = ∑ v ∇ π θ ( v ∣ s t ) [ log π θ ( v ∣ s t ) π T i ( v ∣ s t ) + 1 ] = E π θ [ ∇ log π θ ( v ∣ s t ) log π θ ( v ∣ s t ) π T i ( v ∣ s t ) ] . \nabla L_i(\theta)=\sum_v\nabla\pi_\theta(v\mid s_t)\left[\log\frac{\pi_\theta(v\mid s_t)}{\pi_{T_i}(v\mid s_t)}+1\right]
=\mathbb{E}_{\pi_\theta}\left[\nabla\log\pi_\theta(v\mid s_t)\log\frac{\pi_\theta(v\mid s_t)}{\pi_{T_i}(v\mid s_t)}\right]. ∇ L i ( θ ) = v ∑ ∇ π θ ( v ∣ s t ) [ log π T i ( v ∣ s t ) π θ ( v ∣ s t ) + 1 ] = E π θ [ ∇ log π θ ( v ∣ s t ) log π T i ( v ∣ s t ) π θ ( v ∣ s t ) ] .
We now proceed to evaluate this gradient at initialization θ 0 \theta_0 θ 0 . First, note that
∇ θ log π θ ( v ∣ s t ) ∣ θ = θ 0 = ϕ ( s t , v ) − ϕ ˉ t \left.\nabla_\theta\log\pi_\theta(v\mid s_t)\right|_{\theta=\theta_0}=\phi(s_t,v)-\bar{\phi}_t ∇ θ log π θ ( v ∣ s t ) ∣ θ = θ 0 = ϕ ( s t , v ) − ϕ ˉ t
and
log π T i ( v ∣ s t ) π θ 0 ( v ∣ s t ) = ω i T ψ i ( s t , v ) − θ 0 T ϕ ( s t , v ) + log Z S ( θ 0 ; s t ) − log Z T i ( s t ) . \log\frac{\pi_{T_i}(v\mid s_t)}{\pi_{\theta_0}(v\mid s_t)}
=\omega_i^{\mathsf{T}}\psi_i(s_t,v)-\theta_0^{\mathsf{T}}\phi(s_t,v)
+\log Z_S(\theta_0;s_t)-\log Z_{T_i}(s_t). log π θ 0 ( v ∣ s t ) π T i ( v ∣ s t ) = ω i T ψ i ( s t , v ) − θ 0 T ϕ ( s t , v ) + log Z S ( θ 0 ; s t ) − log Z T i ( s t ) .
Evaluating ∇ L i ( θ ) \nabla L_i(\theta) ∇ L i ( θ ) at θ 0 \theta_0 θ 0 using the above expressions, and combining with the fact that log Z S ( θ 0 ; s t ) − log Z T i ( s t ) \log Z_S(\theta_0;s_t)-\log Z_{T_i}(s_t) log Z S ( θ 0 ; s t ) − log Z T i ( s t ) does not depend on token v v v , we have that:
d i ( t ) = E t [ ( ϕ − ϕ ˉ t ) log π T i ( v ∣ s t ) π θ 0 ( v ∣ s t ) ] = C i ( t ) ω i − F t θ 0 . (8) d_i(t)=\mathbb{E}_t\left[(\phi-\bar{\phi}_t)\log\frac{\pi_{T_i}(v\mid s_t)}{\pi_{\theta_0}(v\mid s_t)}\right]=C_i(t)\omega_i-F_t\theta_0. \tag*{(8)} d i ( t ) = E t [ ( ϕ − ϕ ˉ t ) log π θ 0 ( v ∣ s t ) π T i ( v ∣ s t ) ] = C i ( t ) ω i − F t θ 0 . (8)
By assumption at initialization: ϕ ˉ t = ψ ˉ i , t = 0 \bar{\phi}_t=\bar{\psi}_{i,t}=0 ϕ ˉ t = ψ ˉ i , t = 0 , F t = E t [ ϕ ϕ T ] = I d F_t=\mathbb{E}_t[\phi\phi^{\mathsf{T}}]=I_d F t = E t [ ϕ ϕ T ] = I d , and C i ( t ) = ρ i I d C_i(t)=\rho_i I_d C i ( t ) = ρ i I d , where ρ i ∈ [ 0 , 1 ] \rho_i\in[0,1] ρ i ∈ [ 0 , 1 ] is teacher i i i ’s alignment coefficient. Then, we have that:
D i ( t ) = tr ( I d ) + tr ( I d ) − 2 tr ( C i ( t ) ) = 2 d ( 1 − ρ i ) , D_i(t)=\operatorname{tr}(I_d)+\operatorname{tr}(I_d)-2\operatorname{tr}(C_i(t))=2d(1-\rho_i), D i ( t ) = tr ( I d ) + tr ( I d ) − 2 tr ( C i ( t )) = 2 d ( 1 − ρ i ) ,
where we recall that W = ∥ ω i ∥ 2 W=\lVert\omega_i\rVert_2 W = ∥ ω i ∥ 2 and b = ⟨ ω i , θ 0 ⟩ b=\langle\omega_i,\theta_0\rangle b = ⟨ ω i , θ 0 ⟩ . Substituting F t = I d F_t=I_d F t = I d and C i ( t ) = ρ i I d C_i(t)=\rho_i I_d C i ( t ) = ρ i I d into (8) , we obtain
d i ( t ) = ρ i ω i − θ 0 , d_i(t)=\rho_i\omega_i-\theta_0, d i ( t ) = ρ i ω i − θ 0 ,
from which we see that
a i 2 = ∥ ρ i ω i − θ 0 ∥ 2 2 = W 2 ρ i 2 + ∥ θ 0 ∥ 2 2 − 2 b ρ i , a_i^2=\lVert\rho_i\omega_i-\theta_0\rVert_2^2=W^2\rho_i^2+\lVert\theta_0\rVert_2^2-2b\rho_i, a i 2 = ∥ ρ i ω i − θ 0 ∥ 2 2 = W 2 ρ i 2 + ∥ θ 0 ∥ 2 2 − 2 b ρ i ,
as desired.
Given the expressions of the gradients with respect to each teacher, we now compare them, under the following assumption which essentially says teacher 1 is more aligned to the student than teacher 2, without loss of generality.
Assumption 3. Without loss of generality, ρ 1 > ρ 2 \rho_1 > \rho_2 ρ 1 > ρ 2 . In addition, assume that b ≤ W 2 ρ 2 b \le W^2\rho_2 b ≤ W 2 ρ 2 .
We now give the formal statement that compares the magnitudes of the norms of the gradient losses corresponding to either teacher, which exactly corresponds to the student-teacher alignment ρ i \rho_i ρ i under our setup.
Lemma 4 (Comparison of initial gradients). Under the preceding assumptions, we have that D 1 ( t ) < D 2 ( t ) D_1(t) < D_2(t) D 1 ( t ) < D 2 ( t ) if and only if ρ 1 > ρ 2 \rho_1 > \rho_2 ρ 1 > ρ 2 . Moreover,
a 1 2 − a 2 2 = ( ρ 1 − ρ 2 ) [ W 2 ( ρ 1 + ρ 2 ) − 2 b ] > 0 , (9) a_1^2-a_2^2=(\rho_1-\rho_2)\left[W^2(\rho_1+\rho_2)-2b\right]>0, \tag*{(9)} a 1 2 − a 2 2 = ( ρ 1 − ρ 2 ) [ W 2 ( ρ 1 + ρ 2 ) − 2 b ] > 0 , (9) and hence a 1 > a 2 a_1 > a_2 a 1 > a 2 .
Proof of Lemma 4. Since D i ( t ) = 2 d ( 1 − ρ i ) D_i(t)=2d(1-\rho_i) D i ( t ) = 2 d ( 1 − ρ i ) , smaller feature discrepancy means larger ρ i \rho_i ρ i and hence D 1 ( t ) < D 2 ( t ) ⟺ ρ 1 > ρ 2 D_1(t)<D_2(t)\Longleftrightarrow\rho_1>\rho_2 D 1 ( t ) < D 2 ( t ) ⟺ ρ 1 > ρ 2 . Furthermore,
a 1 2 − a 2 2 = W 2 ( ρ 1 2 − ρ 2 2 ) − 2 b ( ρ 1 − ρ 2 ) = ( ρ 1 − ρ 2 ) [ W 2 ( ρ 1 + ρ 2 ) − 2 b ] . a_1^2-a_2^2=W^2(\rho_1^2-\rho_2^2)-2b(\rho_1-\rho_2)=(\rho_1-\rho_2)\left[W^2(\rho_1+\rho_2)-2b\right]. a 1 2 − a 2 2 = W 2 ( ρ 1 2 − ρ 2 2 ) − 2 b ( ρ 1 − ρ 2 ) = ( ρ 1 − ρ 2 ) [ W 2 ( ρ 1 + ρ 2 ) − 2 b ] .
Indeed, both terms on the right hand side are positive, since ρ 1 > ρ 2 \rho_1>\rho_2 ρ 1 > ρ 2 and W 2 ( ρ 1 + ρ 2 ) > 2 W 2 ρ 2 ≥ 2 b W^2(\rho_1+\rho_2)>2W^2\rho_2\ge2b W 2 ( ρ 1 + ρ 2 ) > 2 W 2 ρ 2 ≥ 2 b .
We remark that since ⟨ d i ( t ) , ω i ⟩ = W 2 ρ i − b \langle d_i(t),\omega_i\rangle=W^2\rho_i-b ⟨ d i ( t ) , ω i ⟩ = W 2 ρ i − b , we are in the regime where this inner product is nonnegative, in which case increasing teacher-student alignment corresponds with this increasing gradient norm. Although this is a statement about initialization, we will show in the next section that under certain suitable assumptions, this yields a separation in the rate of optimization.
Proofs for Learning-Time Separation
Fix a prefix s t = ( x , y < t ) s_t=(x,y_{<t}) s t = ( x , y < t ) . Recall the log-linear student and teachers from § 4.2 :
π θ ( v ∣ s t ) = exp ( θ ⊤ ϕ ( s t , v ) ) Z S ( θ ; s t ) , π T i ( v ∣ s t ) = exp ( ω i ⊤ ψ i ( s t , v ) ) Z T i ( s t ) , i ∈ { 1 , 2 } . \pi_\theta(v\mid s_t)=\frac{\exp(\theta^\top\phi(s_t,v))}{Z_S(\theta;s_t)},\qquad\pi_{T_i}(v\mid s_t)=\frac{\exp(\omega_i^\top\psi_i(s_t,v))}{Z_{T_i}(s_t)},\qquad i\in\{1,2\}. π θ ( v ∣ s t ) = Z S ( θ ; s t ) exp ( θ ⊤ ϕ ( s t , v )) , π T i ( v ∣ s t ) = Z T i ( s t ) exp ( ω i ⊤ ψ i ( s t , v )) , i ∈ { 1 , 2 } .
as well as our loss functions:
L i ( θ ) : = KL ( π θ ( ⋅ ∣ s t ) ∥ π T i ( ⋅ ∣ s t ) ) . L_i(\theta):=\operatorname{KL}(\pi_\theta(\cdot\mid s_t)\parallel\pi_{T_i}(\cdot\mid s_t)). L i ( θ ) := KL ( π θ ( ⋅ ∣ s t ) ∥ π T i ( ⋅ ∣ s t )) .
Starting from the same student head θ 0 \theta_0 θ 0 , gradient descent with a common learning rate η > 0 \eta>0 η > 0 gives
θ 0 ( i ) = θ 0 , θ n + 1 ( i ) = θ n ( i ) − η ∇ L i ( θ n ( i ) ) . \theta_0^{(i)}=\theta_0,\qquad\theta_{n+1}^{(i)}=\theta_n^{(i)}-\eta\nabla L_i(\theta_n^{(i)}). θ 0 ( i ) = θ 0 , θ n + 1 ( i ) = θ n ( i ) − η ∇ L i ( θ n ( i ) ) .
Recall our notation a i : = ∥ ∇ L i ( θ 0 ) ∥ 2 a_i:=\lVert\nabla L_i(\theta_0)\rVert_2 a i := ∥ ∇ L i ( θ 0 ) ∥ 2 for the initial gradient norm. For a target loss level 0 < ϵ < min i L i ( θ 0 ) 0<\epsilon<\min_i L_i(\theta_0) 0 < ϵ < min i L i ( θ 0 ) , define
δ i : = L i ( θ 0 ) − ϵ , N i ( ϵ ) : = inf { n ∈ Z ≥ 0 : L i ( θ n ( i ) ) ≤ ϵ } . \delta_i:=L_i(\theta_0)-\epsilon,\qquad N_i(\epsilon):=\inf\{n\in\mathbb{Z}_{\ge0}:L_i(\theta_n^{(i)})\le\epsilon\}. δ i := L i ( θ 0 ) − ϵ , N i ( ϵ ) := inf { n ∈ Z ≥ 0 : L i ( θ n ( i ) ) ≤ ϵ } .
We begin with the following bounded features assumption.
Assumption 4 (Bounded student and teacher features). For every candidate token v v v at the fixed prefix and each teacher i ∈ { 1 , 2 } i\in\{1,2\} i ∈ { 1 , 2 } ,
∥ ϕ ( s t , v ) ∥ 2 ≤ B , ∥ ψ i ( s t , v ) ∥ 2 ≤ B \lVert\phi(s_t,v)\rVert_2\le B,\qquad\lVert\psi_i(s_t,v)\rVert_2\le B ∥ ϕ ( s t , v ) ∥ 2 ≤ B , ∥ ψ i ( s t , v ) ∥ 2 ≤ B for some B > 0 B>0 B > 0 .
In the rest of this section, we will work with learning rates η \eta η that satisfy 0 < η Λ < 1 0<\eta\Lambda<1 0 < η Λ < 1 , and we denote r : = η Λ r:=\eta\Lambda r := η Λ . We first introduce the following additional notation: for teacher i i i , let h i , n : = ∥ ∇ L i ( θ n ( i ) ) ∥ 2 h_{i,n}:=\lVert\nabla L_i(\theta_n^{(i)})\rVert_2 h i , n := ∥ ∇ L i ( θ n ( i ) ) ∥ 2 be the gradient norm after n n n updates, and let P i ( n ) : = L i ( θ 0 ) − L i ( θ n ( i ) ) P_i(n):=L_i(\theta_0)-L_i(\theta_n^{(i)}) P i ( n ) := L i ( θ 0 ) − L i ( θ n ( i ) ) be the total loss reduction after those updates.
Lemma 5 (Two-sided loss-reduction bounds). If ∇ L i \nabla L_i ∇ L i is Λ \Lambda Λ -Lipschitz and 0 < r = η Λ < 1 0<r=\eta\Lambda<1 0 < r = η Λ < 1 , then, for every integer n ≥ 0 n\ge0 n ≥ 0 ,
( 1 − r ) n a i ≤ h i , n ≤ ( 1 + r ) n a i (1-r)^n a_i \le h_{i,n} \le(1+r)^n a_i ( 1 − r ) n a i ≤ h i , n ≤ ( 1 + r ) n a i and
a i 2 2 Λ [ 1 − ( 1 − r ) 2 n ] ≤ P i ( n ) ≤ a i 2 2 Λ [ ( 1 + r ) 2 n − 1 ] . (10) \frac{a_i^2}{2\Lambda}\left[1-(1-r)^{2n}\right]\le P_i(n)\le\frac{a_i^2}{2\Lambda}\left[(1+r)^{2n}-1\right]. \tag*{(10)} 2Λ a i 2 [ 1 − ( 1 − r ) 2 n ] ≤ P i ( n ) ≤ 2Λ a i 2 [ ( 1 + r ) 2 n − 1 ] . (10)
Proof. First, we have by Λ \Lambda Λ -smoothness that:
∣ h i , n + 1 − h i , n ∣ ≤ ∥ ∇ L i ( θ n + 1 ( i ) ) − ∇ L i ( θ n ( i ) ) ∥ 2 ≤ Λ ∥ θ n + 1 ( i ) − θ n ( i ) ∥ 2 = r h i , n . \left|h_{i,n+1}-h_{i,n}\right|\le\left\|\nabla L_i\left(\theta_{n+1}^{(i)}\right)-\nabla L_i\left(\theta_n^{(i)}\right)\right\|_2\le\Lambda\left\|\theta_{n+1}^{(i)}-\theta_n^{(i)}\right\|_2=r h_{i,n}. ∣ h i , n + 1 − h i , n ∣ ≤ ∇ L i ( θ n + 1 ( i ) ) − ∇ L i ( θ n ( i ) ) 2 ≤ Λ θ n + 1 ( i ) − θ n ( i ) 2 = r h i , n .
By triangle inequality, we have ( 1 − r ) h i , n ≤ h i , n + 1 ≤ ( 1 + r ) h i , n (1-r)h_{i,n}\le h_{i,n+1}\le(1+r)h_{i,n} ( 1 − r ) h i , n ≤ h i , n + 1 ≤ ( 1 + r ) h i , n , from which induction yields ( 1 − r ) n a i ≤ h i , n ≤ ( 1 + r ) n a i (1-r)^n a_i\le h_{i,n}\le(1+r)^n a_i ( 1 − r ) n a i ≤ h i , n ≤ ( 1 + r ) n a i .
Furthermore, for a Λ \Lambda Λ -smooth loss, the error in its first-order Taylor expansion along an update is at most Λ η 2 h i , n 2 / 2 \Lambda\eta^2h_{i,n}^2/2 Λ η 2 h i , n 2 /2 in absolute value. Consequently,
η ( 1 − r / 2 ) h i , n 2 ≤ L i ( θ n ( i ) ) − L i ( θ n + 1 ( i ) ) ≤ η ( 1 + r / 2 ) h i , n 2 . \eta(1-r/2)h_{i,n}^2\le L_i\left(\theta_n^{(i)}\right)-L_i\left(\theta_{n+1}^{(i)}\right)\le\eta(1+r/2)h_{i,n}^2. η ( 1 − r /2 ) h i , n 2 ≤ L i ( θ n ( i ) ) − L i ( θ n + 1 ( i ) ) ≤ η ( 1 + r /2 ) h i , n 2 .
Using the above gradient bound, we sum and telescope these inequalities over j = 0 , … , n − 1 j=0,\ldots,n-1 j = 0 , … , n − 1 to obtain
P i ( n ) ≥ η ( 1 − r / 2 ) a i 2 ∑ j = 0 n − 1 ( 1 − r ) 2 j = a i 2 2 Λ [ 1 − ( 1 − r ) 2 n ] , P_i(n)\ge\eta(1-r/2)a_i^2\sum_{j=0}^{n-1}(1-r)^{2j}=\frac{a_i^2}{2\Lambda}\left[1-(1-r)^{2n}\right], P i ( n ) ≥ η ( 1 − r /2 ) a i 2 j = 0 ∑ n − 1 ( 1 − r ) 2 j = 2Λ a i 2 [ 1 − ( 1 − r ) 2 n ] ,
P i ( n ) ≤ η ( 1 + r / 2 ) a i 2 ∑ j = 0 n − 1 ( 1 + r ) 2 j = a i 2 2 Λ [ ( 1 + r ) 2 n − 1 ] , P_i(n)\le\eta(1+r/2)a_i^2\sum_{j=0}^{n-1}(1+r)^{2j}=\frac{a_i^2}{2\Lambda}\left[(1+r)^{2n}-1\right], P i ( n ) ≤ η ( 1 + r /2 ) a i 2 j = 0 ∑ n − 1 ( 1 + r ) 2 j = 2Λ a i 2 [ ( 1 + r ) 2 n − 1 ] ,
as desired.
Proposition 1 (Learning time bounds from the initial gradient). For a i > 0 a_i>0 a i > 0 , 0 < r = η Λ < 1 0<r=\eta\Lambda<1 0 < r = η Λ < 1 , and δ i = L i ( θ 0 ) − ϵ > 0 \delta_i=L_i(\theta_0)-\epsilon>0 δ i = L i ( θ 0 ) − ϵ > 0 ,
N i ( ϵ ) ≥ ⌈ log ( 1 + 2 Λ δ i / a i 2 ) 2 log ( 1 + r ) ⌉ . (11) N_i(\epsilon)\ge\left\lceil\frac{\log(1+2\Lambda\delta_i/a_i^2)}{2\log(1+r)}\right\rceil. \tag*{(11)} N i ( ϵ ) ≥ ⌈ 2 log ( 1 + r ) log ( 1 + 2Λ δ i / a i 2 ) ⌉ . (11) If additionally 0 < 2 Λ δ i / a i 2 < 1 0<2\Lambda\delta_i/a_i^2<1 0 < 2Λ δ i / a i 2 < 1 , then
N i ( ϵ ) ≤ ⌈ log ( 1 − 2 Λ δ i / a i 2 ) 2 log ( 1 − r ) ⌉ . (12) N_i(\epsilon)\le\left\lceil\frac{\log(1-2\Lambda\delta_i/a_i^2)}{2\log(1-r)}\right\rceil. \tag*{(12)} N i ( ϵ ) ≤ ⌈ 2 log ( 1 − r ) log ( 1 − 2Λ δ i / a i 2 ) ⌉ . (12) Proof. We first analyze the lower bound. Note that reaching the target requires P i ( n ) ≥ δ i P_i(n)\ge\delta_i P i ( n ) ≥ δ i . From the upper bound in (10) , we must have ( 1 + r ) 2 n ≥ 1 + 2 Λ δ i / a i 2 (1+r)^{2n}\ge1+2\Lambda\delta_i/a_i^2 ( 1 + r ) 2 n ≥ 1 + 2Λ δ i / a i 2 to achieve this. Taking logarithms and rounding up yields the lower bound on n n n to be the right hand side of (11) .
For the upper bound, it suffices that the lower bound on P i ( n ) P_i(n) P i ( n ) is at least δ i \delta_i δ i . When 2 Λ δ i / a i 2 < 1 2\Lambda\delta_i/a_i^2<1 2Λ δ i / a i 2 < 1 , this holds as soon as
( 1 − r ) 2 n ≤ 1 − 2 Λ δ i a i 2 . (1-r)^{2n}\le1-\frac{2\Lambda\delta_i}{a_i^2}. ( 1 − r ) 2 n ≤ 1 − a i 2 2Λ δ i . By a similar manipulation, we obtain that n n n must be at least the bound in (12) .
We now proceed to the proof of the main theorem.
Theorem 4 (Full version of Theorem 1). Let x i : = 2 Λ δ i / a i 2 x_i:=2\Lambda\delta_i/a_i^2 x i := 2Λ δ i / a i 2 , and suppose that for a fixed constant κ ∈ ( 0 , 1 ) \kappa\in(0,1) κ ∈ ( 0 , 1 ) , we have that η , ϵ \eta,\epsilon η , ϵ satisfy:
0 < r = η Λ ≤ κ , 0 < x i = 2 Λ [ L i ( θ 0 ) − ϵ ] a i 2 ≤ κ , i ∈ { 1 , 2 } . 0<r=\eta\Lambda\le\kappa,\qquad0<x_i=\frac{2\Lambda[L_i(\theta_0)-\epsilon]}{a_i^2}\le\kappa,\qquad i\in\{1,2\}. 0 < r = η Λ ≤ κ , 0 < x i = a i 2 2Λ [ L i ( θ 0 ) − ϵ ] ≤ κ , i ∈ { 1 , 2 } .
Then, for each teacher i i i ,
⌈ δ i ( 1 + κ ) η a i 2 ⌉ ≤ N i ( ε ) ≤ ⌈ δ i ( 1 − κ ) η a i 2 ⌉ . (13) \left\lceil\frac{\delta_i}{(1+\kappa)\eta a_i^2} \right\rceil\le N_i(\varepsilon) \le\left\lceil\frac{\delta_i}{(1-\kappa)\eta a_i^2} \right\rceil. \tag*{(13)} ⌈ ( 1 + κ ) η a i 2 δ i ⌉ ≤ N i ( ε ) ≤ ⌈ ( 1 − κ ) η a i 2 δ i ⌉ . (13)
In particular,
N 1 ( ε ) = O ( 1 + δ 1 η a 1 2 ) , N 2 ( ε ) = Ω ( δ 2 η a 2 2 ) , N_1(\varepsilon)=O\left(1+\frac{\delta_1}{\eta a_1^2}\right), \qquad N_2(\varepsilon)=\Omega\left(\frac{\delta_2}{\eta a_2^2}\right), N 1 ( ε ) = O ( 1 + η a 1 2 δ 1 ) , N 2 ( ε ) = Ω ( η a 2 2 δ 2 ) ,
with constants depending only on κ \kappa κ , within the stated regime.
Proof. For 0 ≤ z ≤ κ < 1 0 \le z \le\kappa< 1 0 ≤ z ≤ κ < 1 , integration of 1 / ( 1 − z ) 1/(1-z) 1/ ( 1 − z ) and 1 / ( 1 + z ) 1/(1+z) 1/ ( 1 + z ) gives
z ≤ − log ( 1 − z ) ≤ z 1 − κ , z 1 + κ ≤ log ( 1 + z ) ≤ z . z \le-\log(1-z) \le\frac{z}{1-\kappa}, \qquad\frac{z}{1+\kappa} \le\log(1+z) \le z. z ≤ − log ( 1 − z ) ≤ 1 − κ z , 1 + κ z ≤ log ( 1 + z ) ≤ z .
Apply the first pair to x i x_i x i and r r r in the upper bound:
− log ( 1 − x i ) 2 [ − log ( 1 − r ) ] ≤ x i 2 ( 1 − κ ) r = δ i ( 1 − κ ) η a i 2 . \frac{-\log(1-x_i)}{2[-\log(1-r)]} \le\frac{x_i}{2(1-\kappa)r} = \frac{\delta_i}{(1-\kappa)\eta a_i^2}. 2 [ − log ( 1 − r )] − log ( 1 − x i ) ≤ 2 ( 1 − κ ) r x i = ( 1 − κ ) η a i 2 δ i .
Apply the second pair to the lower bound:
log ( 1 + x i ) 2 log ( 1 + r ) ≥ x i 2 ( 1 + κ ) r = δ i ( 1 + κ ) η a i 2 . \frac{\log(1+x_i)}{2\log(1+r)} \ge\frac{x_i}{2(1+\kappa)r} = \frac{\delta_i}{(1+\kappa)\eta a_i^2}. 2 log ( 1 + r ) log ( 1 + x i ) ≥ 2 ( 1 + κ ) r x i = ( 1 + κ ) η a i 2 δ i .
Taking ceilings and using Proposition 1 proves the result.
Proofs for Diversity and Undercoverage
We first compute the part of the teacher’s logit signal that the student features cannot represent, in the following sense. Define the teacher–student logit gap and its variance under the initial student below:
r i , θ ( v ) : = ω i ⊤ ψ i ( v ) − θ ⊤ ϕ ( v ) , R i ( θ ) : = Var π θ 0 [ r i , θ ( v ) ] . r_{i,\theta}(v) := \omega_i^\top\psi_i(v)-\theta^\top\phi(v), \qquad R_i(\theta):=\operatorname{Var}_{\pi_{\theta_0}}[r_{i,\theta}(v)]. r i , θ ( v ) := ω i ⊤ ψ i ( v ) − θ ⊤ ϕ ( v ) , R i ( θ ) := Var π θ 0 [ r i , θ ( v )] .
Then, the following lemma quantifies this representational gap through the structure at initialization.
Lemma 6 (Residual logit variance from feature alignment). Let θ ˉ i : = ρ i ω i \bar{\theta}_i:=\rho_i\omega_i θ ˉ i := ρ i ω i and E i : = R i ( θ ˉ i ) E_i:=R_i(\bar{\theta}_i) E i := R i ( θ ˉ i ) . Under the preceding assumptions, it holds that
R i ( θ ) = ∥ θ − θ ˉ i ∥ 2 2 + E i , E i = min θ ∈ R d R i ( θ ) = W 2 ( 1 − ρ i 2 ) . (14) R_i(\theta)=\|\theta-\bar{\theta}_i\|_2^2+E_i, \qquad E_i=\min_{\theta\in\mathbb{R}^d}R_i(\theta)=W^2(1-\rho_i^2). \tag*{(14)} R i ( θ ) = ∥ θ − θ ˉ i ∥ 2 2 + E i , E i = θ ∈ R d min R i ( θ ) = W 2 ( 1 − ρ i 2 ) . (14) In particular,
Var π θ 0 [ ω i ⊤ ψ i ] = W 2 , Var π θ 0 [ θ ˉ i ⊤ ϕ ] = ρ i 2 W 2 , E π θ 0 [ ϕ r i , θ ˉ i ] = 0. \operatorname{Var}_{\pi_{\theta_0}}[\omega_i^\top\psi_i]=W^2, \qquad\operatorname{Var}_{\pi_{\theta_0}}[\bar{\theta}_i^\top\phi]=\rho_i^2W^2, \qquad\mathbb{E}_{\pi_{\theta_0}}[\phi r_{i,\bar{\theta}_i}]=0. Var π θ 0 [ ω i ⊤ ψ i ] = W 2 , Var π θ 0 [ θ ˉ i ⊤ ϕ ] = ρ i 2 W 2 , E π θ 0 [ ϕ r i , θ ˉ i ] = 0. Thus the candidate captures a fraction ρ i 2 \rho_i^2 ρ i 2 of the teacher’s logit variance, leaving a fraction 1 − ρ i 2 1-\rho_i^2 1 − ρ i 2 outside the student feature span.
Proof. Unless noted otherwise, all expectations in this section are taken over the initial student policy π θ 0 \pi_{\theta_0} π θ 0 . We calculate as follows:
R i ( θ ) = E [ ( ω i ⊤ ψ i − θ ⊤ ϕ ) 2 ] = ω i ⊤ E [ ψ i ψ i ⊤ ] ω i − 2 θ ⊤ E [ ϕ ψ i ⊤ ] ω i + θ ⊤ E [ ϕ ϕ ⊤ ] θ = W 2 − 2 ρ i θ ⊤ ω i + ∥ θ ∥ 2 2 = ∥ θ − ρ i ω i ∥ 2 2 + W 2 ( 1 − ρ i 2 ) . \begin{aligned}
R_i(\theta) &= \mathbb{E}[(\omega_i^\top\psi_i-\theta^\top\phi)^2] \\
&= \omega_i^\top\mathbb{E}[\psi_i\psi_i^\top]\omega_i-2\theta^\top\mathbb{E}[\phi\psi_i^\top]\omega_i+\theta^\top\mathbb{E}[\phi\phi^\top]\theta\\
&= W^2-2\rho_i\theta^\top\omega_i+\|\theta\|_2^2 \\
&= \|\theta-\rho_i\omega_i\|_2^2+W^2(1-\rho_i^2).
\end{aligned} R i ( θ ) = E [( ω i ⊤ ψ i − θ ⊤ ϕ ) 2 ] = ω i ⊤ E [ ψ i ψ i ⊤ ] ω i − 2 θ ⊤ E [ ϕ ψ i ⊤ ] ω i + θ ⊤ E [ ϕ ϕ ⊤ ] θ = W 2 − 2 ρ i θ ⊤ ω i + ∥ θ ∥ 2 2 = ∥ θ − ρ i ω i ∥ 2 2 + W 2 ( 1 − ρ i 2 ) .
In particular, the first term is minimized at θ ˉ i = ρ i ω i \bar{\theta}_i=\rho_i\omega_i θ ˉ i = ρ i ω i , which proves Equation (14) . The teacher-logit and candidate-logit variances are respectively ∥ ω i ∥ 2 2 = W 2 \|\omega_i\|_2^2=W^2 ∥ ω i ∥ 2 2 = W 2 and ∥ θ ˉ i ∥ 2 2 = ρ i 2 W 2 \|\bar{\theta}_i\|_2^2=\rho_i^2W^2 ∥ θ ˉ i ∥ 2 2 = ρ i 2 W 2 . Finally,
E [ ϕ r i , θ ˉ i ] = E [ ϕ ψ i ⊤ ] ω i − E [ ϕ ϕ ⊤ ] θ ˉ i = ρ i ω i − θ ˉ i = 0. \mathbb{E}[\phi r_{i,\bar{\theta}_i}]=\mathbb{E}[\phi\psi_i^\top]\omega_i-\mathbb{E}[\phi\phi^\top]\bar{\theta}_i=\rho_i\omega_i-\bar{\theta}_i=0. E [ ϕ r i , θ ˉ i ] = E [ ϕ ψ i ⊤ ] ω i − E [ ϕ ϕ ⊤ ] θ ˉ i = ρ i ω i − θ ˉ i = 0.
We next convert the residual variance into a bound on reverse KL. For a student head θ \theta θ and an interpolation parameter λ ∈ [ 0 , 1 ] \lambda\in[0,1] λ ∈ [ 0 , 1 ] , define
π i , θ , λ ( v ) : = exp { ( 1 − λ ) θ ⊤ ϕ ( v ) + λ ω i ⊤ ψ i ( v ) } ∑ u ∈ V exp { ( 1 − λ ) θ ⊤ ϕ ( u ) + λ ω i ⊤ ψ i ( u ) } . \pi_{i,\theta,\lambda}(v) := \frac{\exp\{(1-\lambda)\theta^{\top}\phi(v)+\lambda\omega_i^{\top}\psi_i(v)\}}{\sum_{u\in\mathcal{V}}\exp\{(1-\lambda)\theta^{\top}\phi(u)+\lambda\omega_i^{\top}\psi_i(u)\}}. π i , θ , λ ( v ) := ∑ u ∈ V exp {( 1 − λ ) θ ⊤ ϕ ( u ) + λ ω i ⊤ ψ i ( u )} exp {( 1 − λ ) θ ⊤ ϕ ( v ) + λ ω i ⊤ ψ i ( v )} .
Here, λ = 0 \lambda=0 λ = 0 and λ = 1 \lambda=1 λ = 1 correspond to policies π θ \pi_\theta π θ and π T i \pi_{T_i} π T i , respectively. The following lemma allows us to use properties of this interpolation policy to bound the reverse KL.
Lemma 7 (Reverse KL is controlled by residual logit variance). For a student head θ \theta θ , suppose Γ ≥ 1 \Gamma\ge1 Γ ≥ 1 satisfies the following probability control condition:
π i , θ , λ ( v ) ≤ Γ π θ 0 ( v ) for every v ∈ V , λ ∈ [ 0 , 1 ] . (15) \pi_{i,\theta,\lambda}(v) \le\Gamma\pi_{\theta_0}(v) \quad\text{for every } v\in\mathcal{V},\ \lambda\in[0,1]. \tag*{(15)} π i , θ , λ ( v ) ≤ Γ π θ 0 ( v ) for every v ∈ V , λ ∈ [ 0 , 1 ] . (15) Then
L i ( θ ) ≤ Γ 2 Var π θ 0 [ ω i ⊤ ψ i − θ ⊤ ϕ ] = Γ 2 R i ( θ ) . (16) L_i(\theta) \le\frac{\Gamma}{2}\operatorname{Var}_{\pi_{\theta_0}}\left[\omega_i^{\top}\psi_i-\theta^{\top}\phi\right] = \frac{\Gamma}{2}R_i(\theta). \tag*{(16)} L i ( θ ) ≤ 2 Γ Var π θ 0 [ ω i ⊤ ψ i − θ ⊤ ϕ ] = 2 Γ R i ( θ ) . (16) In particular, if the condition holds at θ ˉ i = ρ i ω i \bar{\theta}_i=\rho_i\omega_i θ ˉ i = ρ i ω i , then
L i ⋆ : = inf θ L i ( θ ) ≤ L i ( θ ˉ i ) ≤ Γ 2 E i = Γ W 2 ( 1 − ρ i 2 ) 2 . (17) L_i^\star:= \inf_{\theta}L_i(\theta) \le L_i(\bar{\theta}_i) \le\frac{\Gamma}{2}E_i = \frac{\Gamma W^2(1-\rho_i^2)}{2}. \tag*{(17)} L i ⋆ := θ inf L i ( θ ) ≤ L i ( θ ˉ i ) ≤ 2 Γ E i = 2 Γ W 2 ( 1 − ρ i 2 ) . (17)
Proof. Recall that r i , θ ( v ) = ω i ⊤ ψ i ( v ) − θ ⊤ ϕ ( v ) r_{i,\theta}(v)=\omega_i^{\top}\psi_i(v)-\theta^{\top}\phi(v) r i , θ ( v ) = ω i ⊤ ψ i ( v ) − θ ⊤ ϕ ( v ) is the logit error. For the fixed head θ \theta θ , define the scalar log-partition function
A i , θ ( λ ) : = log ∑ v exp { θ ⊤ ϕ ( v ) + λ r i , θ ( v ) } . A_{i,\theta}(\lambda):=\log\sum_v\exp\{\theta^{\top}\phi(v)+\lambda r_{i,\theta}(v)\}. A i , θ ( λ ) := log v ∑ exp { θ ⊤ ϕ ( v ) + λ r i , θ ( v )} .
Differentiating yields
A i , θ ′ ( λ ) = E π i , θ , λ [ r i , θ ] , A i , θ ′ ′ ( λ ) = Var π i , θ , λ [ r i , θ ] . A'_{i,\theta}(\lambda)=\mathbb{E}_{\pi_{i,\theta,\lambda}}[r_{i,\theta}], \qquad A''_{i,\theta}(\lambda)=\operatorname{Var}_{\pi_{i,\theta,\lambda}}[r_{i,\theta}]. A i , θ ′ ( λ ) = E π i , θ , λ [ r i , θ ] , A i , θ ′′ ( λ ) = Var π i , θ , λ [ r i , θ ] .
Substituting these quantities into the reverse KL loss and using Taylor expansion, we have that
L i ( θ ) = A i , θ ( 1 ) − A i , θ ( 0 ) − A i , θ ′ ( 0 ) = ∫ 0 1 ( 1 − λ ) Var π i , θ , λ [ r i , θ ] d λ . (18) \begin{aligned}
L_i(\theta) &= A_{i,\theta}(1)-A_{i,\theta}(0)-A'_{i,\theta}(0) \\
&= \int_0^1 (1-\lambda)\operatorname{Var}_{\pi_{i,\theta,\lambda}}[r_{i,\theta}]\,d\lambda. \tag*{(18)}
\end{aligned} L i ( θ ) = A i , θ ( 1 ) − A i , θ ( 0 ) − A i , θ ′ ( 0 ) = ∫ 0 1 ( 1 − λ ) Var π i , θ , λ [ r i , θ ] d λ . (18)
To bound the path variance, note that:
Var π i , θ , λ [ r i , θ ] ≤ E π i , θ , λ [ ( r i , θ − E π θ 0 [ r i , θ ] ) 2 ] ≤ Γ E π θ 0 [ ( r i , θ − E π θ 0 [ r i , θ ] ) 2 ] = Γ R i ( θ ) . \begin{aligned}
\operatorname{Var}_{\pi_{i,\theta,\lambda}}[r_{i,\theta}]
&\le\mathbb{E}_{\pi_{i,\theta,\lambda}}\left[\left(r_{i,\theta}-\mathbb{E}_{\pi_{\theta_0}}[r_{i,\theta}]\right)^2\right] \\
&\le\Gamma\mathbb{E}_{\pi_{\theta_0}}\left[\left(r_{i,\theta}-\mathbb{E}_{\pi_{\theta_0}}[r_{i,\theta}]\right)^2\right] \\
&= \Gamma R_i(\theta).
\end{aligned} Var π i , θ , λ [ r i , θ ] ≤ E π i , θ , λ [ ( r i , θ − E π θ 0 [ r i , θ ] ) 2 ] ≤ Γ E π θ 0 [ ( r i , θ − E π θ 0 [ r i , θ ] ) 2 ] = Γ R i ( θ ) .
where the second inequality uses the pointwise probability bound from earlier. Substituting this back into Equation (18) yields
L i ( θ ) ≤ Γ R i ( θ ) ∫ 0 1 ( 1 − λ ) d λ = Γ 2 R i ( θ ) . L_i(\theta)\le\Gamma R_i(\theta)\int_0^1(1-\lambda)\,d\lambda=\frac{\Gamma}{2}R_i(\theta). L i ( θ ) ≤ Γ R i ( θ ) ∫ 0 1 ( 1 − λ ) d λ = 2 Γ R i ( θ ) .
In particular, at θ ˉ i \bar{\theta}_i θ ˉ i , Lemma 6 gives R i ( θ ˉ i ) = E i = W 2 ( 1 − ρ i 2 ) R_i(\bar{\theta}_i)=E_i=W^2(1-\rho_i^2) R i ( θ ˉ i ) = E i = W 2 ( 1 − ρ i 2 ) . Since L i ⋆ = inf θ L i ( θ ) ≤ L i ( θ ˉ i ) L_i^\star=\inf_\theta L_i(\theta)\le L_i(\bar{\theta}_i) L i ⋆ = inf θ L i ( θ ) ≤ L i ( θ ˉ i ) , Equation (17) follows.
In the next part, we will translate the above bound on the KL minimizer into a lower bound on the diversity of the high-quality modes that the student will learn. Recall that G 1 , … , G M ⊆ V G_1,\ldots,G_M\subseteq\mathcal{V} G 1 , … , G M ⊆ V are disjoint, nonempty next-token sets representing M M M successful continuation modes. We now make the following assumption about the distribution of the modes from the teacher policy.
Assumption 5 (Uniformity of high-quality modes). Assume that selecting a token in G j G_j G j leads to success in mode j j j , and selecting outside their union leads to failure. Each teacher has success probability c ∈ ( 0 , 1 ) c \in(0,1) c ∈ ( 0 , 1 ) (i.e. the probability of sampling a good mode) and
π T i ( G j ) = c / M , j = 1 , … , M . (19) \pi_{T_i}(G_j) = c/M,\qquad j=1,\ldots,M. \tag*{(19)} π T i ( G j ) = c / M , j = 1 , … , M . (19)
In addition, we make the following technical assumption that allows us to obtain non-vacuous guarantees in any of the diversity quantities in the main theorem.
Assumption 6 (Probability control and small teacher heads). Let Γ \Gamma Γ be defined as in Lemma 7. Then, the norm of the teacher head satisfies:
0 < W < 2 c M Γ . (20) 0 < W < \frac{2c}{M\sqrt{\Gamma}}. \tag*{(20)} 0 < W < M Γ 2 c . (20)
For a policy π \pi π and an integer k ≥ 1 k \ge1 k ≥ 1 counting independent samples, the expected number of distinct successful modes is
Distinct k ( π ) : = ∑ j = 1 M [ 1 − ( 1 − π ( G j ) ) k ] . \operatorname{Distinct}_k(\pi) := \sum_{j=1}^{M}\left[1-\left(1-\pi(G_j)\right)^k\right]. Distinct k ( π ) := j = 1 ∑ M [ 1 − ( 1 − π ( G j ) ) k ] .
In the following theorem, we will analyze this quantity.
Theorem 5 (Diversity guarantee at a KL minimum, full statement). Under the preceding assumptions, let θ i ⋆ \theta_i^\star θ i ⋆ be a finite global minimizer of L i ( θ ) = KL ( π θ ∥ π T i ) L_i(\theta)=\operatorname{KL}(\pi_\theta\Vert\pi_{T_i}) L i ( θ ) = KL ( π θ ∥ π T i ) for each teacher i ∈ { 1 , 2 } i\in\{1,2\} i ∈ { 1 , 2 } . Define the teacher-dependent error bound
e i : = W 2 Γ ( 1 − ρ i 2 ) . (21) e_i := \frac{W}{2}\sqrt{\Gamma(1-\rho_i^2)}. \tag*{(21)} e i := 2 W Γ ( 1 − ρ i 2 ) . (21) Then 0 ≤ e i < c / M 0\le e_i<c/M 0 ≤ e i < c / M , and for every j ∈ { 1 , … , M } j\in\{1,\ldots,M\} j ∈ { 1 , … , M } and integer k ≥ 1 k\ge1 k ≥ 1 ,
TV ( π θ i ⋆ , π T i ) ≤ e i , π θ i ⋆ ( G j ) ≥ c / M − e i > 0 , Distinct k ( π θ i ⋆ ) ≥ M [ 1 − ( 1 − c / M + e i ) k ] . (22) \begin{aligned}
\operatorname{TV}(\pi_{\theta_i^\star},\pi_{T_i}) &\le e_i,\\
\pi_{\theta_i^\star}(G_j) &\ge c/M-e_i>0,\\
\operatorname{Distinct}_k(\pi_{\theta_i^\star}) &\ge M\left[1-\left(1-c/M+e_i\right)^k\right]. \tag*{(22)}
\end{aligned} TV ( π θ i ⋆ , π T i ) π θ i ⋆ ( G j ) Distinct k ( π θ i ⋆ ) ≤ e i , ≥ c / M − e i > 0 , ≥ M [ 1 − ( 1 − c / M + e i ) k ] . (22)
Proof of Theorem 5. Fix a teacher i i i and prefix state s t s_t s t . Then, we have from Lemmas 6 and 7 that
KL ( π θ i ⋆ ∥ π T i ) = L i ⋆ ≤ L i ( θ ˉ i ) ≤ Γ E i 2 = 2 e i 2 . (23) \operatorname{KL}(\pi_{\theta_i^\star}\Vert\pi_{T_i})=L_i^\star\le L_i(\bar{\theta}_i)\le\frac{\Gamma E_i}{2}=2e_i^2. \tag*{(23)} KL ( π θ i ⋆ ∥ π T i ) = L i ⋆ ≤ L i ( θ ˉ i ) ≤ 2 Γ E i = 2 e i 2 . (23)
Pinsker’s inequality therefore implies
TV ( π θ i ⋆ , π T i ) ≤ L i ⋆ 2 ≤ e i . \operatorname{TV}(\pi_{\theta_i^\star},\pi_{T_i})\le\sqrt{\frac{L_i^\star}{2}}\le e_i. TV ( π θ i ⋆ , π T i ) ≤ 2 L i ⋆ ≤ e i .
Since total variation bounds the probability difference of any event, each good mode satisfies
π θ i ⋆ ( G j ) ≥ π T i ( G j ) − TV ( π θ i ⋆ , π T i ) ≥ c / M − e i > 0. \pi_{\theta_i^\star}(G_j)\ge\pi_{T_i}(G_j)-\operatorname{TV}(\pi_{\theta_i^\star},\pi_{T_i})\ge c/M-e_i>0. π θ i ⋆ ( G j ) ≥ π T i ( G j ) − TV ( π θ i ⋆ , π T i ) ≥ c / M − e i > 0.
In k k k independent samples, mode j j j is observed at least once with probability 1 − ( 1 − π θ i ⋆ ( G j ) ) k 1-(1-\pi_{\theta_i^\star}(G_j))^k 1 − ( 1 − π θ i ⋆ ( G j ) ) k . Summing these probabilities gives the expected number of distinct good modes, so
Distinct k ( π θ i ⋆ ) = ∑ j = 1 M [ 1 − ( 1 − π θ i ⋆ ( G j ) ) k ] ≥ M [ 1 − ( 1 − c / M + e i ) k ] . (24) \begin{aligned}
\operatorname{Distinct}_k(\pi_{\theta_i^\star})
&=\sum_{j=1}^{M}\left[1-\left(1-\pi_{\theta_i^\star}(G_j)\right)^k\right]\\
&\ge M\left[1-\left(1-c/M+e_i\right)^k\right]. \tag*{(24)}
\end{aligned} Distinct k ( π θ i ⋆ ) = j = 1 ∑ M [ 1 − ( 1 − π θ i ⋆ ( G j ) ) k ] ≥ M [ 1 − ( 1 − c / M + e i ) k ] . (24)
We remark that the error e i e_i e i decreases monotonically with the alignment quantity ρ i \rho_i ρ i . Hence, D 1 ( t ) < D 2 ( t ) D_1(t) < D_2(t) D 1 ( t ) < D 2 ( t ) gives teacher 1 a stronger lower bound in the diversity. As a corollary to this, we consider the following quantity, the undercoverage , as adapted from Chen et al. [2025].
Recall the target distribution ν ( j ) = 1 / M \nu(j) = 1/M ν ( j ) = 1/ M , uniform over the M M M good modes, and the threshold N > 1 / c N > 1/c N > 1/ c . The quantity C N m o d e C_N^{\mathrm{mode}} C N mode in Equation (5) is the fraction of these modes with student probability at most ν ( j ) / N = 1 / ( M N ) \nu(j)/N = 1/(MN) ν ( j ) / N = 1/ ( M N ) .
Proof of Corollary 1. Fix N > 1 / c N > 1/c N > 1/ c and define
A N : = { j : π θ i ∗ ( G j ) ≤ 1 / ( M N ) } , B N : = ⋃ j ∈ A N G j . A_N := \{j : \pi_{\theta_i^*}(G_j) \le1/(MN)\}, \qquad B_N := \bigcup_{j \in A_N} G_j. A N := { j : π θ i ∗ ( G j ) ≤ 1/ ( M N )} , B N := j ∈ A N ⋃ G j .
Let the golden reference distribution on the M M M good modes be uniform; that is, ν ( j ) = 1 / M \nu(j) = 1/M ν ( j ) = 1/ M . Hence the undercoverage probability is C N m o d e ( ν ∥ π θ i ∗ ) = ∣ A N ∣ / M C_N^{\mathrm{mode}}(\nu\mathbin\Vert\pi_{\theta_i^*}) = |A_N|/M C N mode ( ν ∥ π θ i ∗ ) = ∣ A N ∣/ M , the fraction of modes in A N A_N A N . The sets G j G_j G j are disjoint, so
π T i ( B N ) = c ∣ A N ∣ M , π θ i ∗ ( B N ) ≤ ∣ A N ∣ M N . \pi_{T_i}(B_N) = \frac{c|A_N|}{M}, \qquad\pi_{\theta_i^*}(B_N) \le\frac{|A_N|}{MN}. π T i ( B N ) = M c ∣ A N ∣ , π θ i ∗ ( B N ) ≤ M N ∣ A N ∣ .
From the proof of Theorem 5, we established TV ( π θ i ∗ , π T i ) ≤ e i \operatorname{TV}(\pi_{\theta_i^*}, \pi_{T_i}) \le e_i TV ( π θ i ∗ , π T i ) ≤ e i . Applying this bound to the single event B N B_N B N gives
( c − 1 N ) ∣ A N ∣ M ≤ π T i ( B N ) − π θ i ∗ ( B N ) ≤ e i , \left(c - \frac{1}{N}\right)\frac{|A_N|}{M} \le\pi_{T_i}(B_N) - \pi_{\theta_i^*}(B_N) \le e_i, ( c − N 1 ) M ∣ A N ∣ ≤ π T i ( B N ) − π θ i ∗ ( B N ) ≤ e i ,
and the result follows via straightforward manipulation. □
Helper Lemmas
In this section, we list out explicit instantiations of the problem-relevant parameters in our setting, such as Γ \Gamma Γ and Λ \Lambda Λ . As these are all proven to be finite values, the exact quantity of them is irrelevant for our main proofs.
Lemma 8 (Smoothness of the reverse KL loss). ∇ L i \nabla L_i ∇ L i is Λ i \Lambda_i Λ i -Lipschitz, where
Λ i = Λ : = B 2 [ 1 + 5 ( log ∣ V ∣ + W B ) ] . (25) \Lambda_i = \Lambda:= B^2\left[1 + 5(\log|V| + WB)\right]. \tag*{(25)} Λ i = Λ := B 2 [ 1 + 5 ( log ∣ V ∣ + W B ) ] . (25)
Proof. We will bound the operator norm ∥ ∇ 2 L i ( θ ) ∥ o p \lVert\nabla^2 L_i(\theta)\rVert_{\mathrm{op}} ∥ ∇ 2 L i ( θ ) ∥ op . First, note that ∣ ω i ⊤ ψ i ( s t , v ) ∣ ≤ W B |\omega_i^\top\psi_i(s_t,v)| \le WB ∣ ω i ⊤ ψ i ( s t , v ) ∣ ≤ W B . For a student head θ \theta θ , define
z θ ( v ) : = ϕ ( s t , v ) − E π θ [ ϕ ( s t , v ) ] , ℓ i , θ ( v ) : = log π θ ( v ∣ s t ) π T i ( v ∣ s t ) . z_\theta(v) := \phi(s_t,v) - \mathbb{E}_{\pi_\theta}[\phi(s_t,v)], \qquad\ell_{i,\theta}(v) := \log\frac{\pi_\theta(v \mid s_t)}{\pi_{T_i}(v \mid s_t)}. z θ ( v ) := ϕ ( s t , v ) − E π θ [ ϕ ( s t , v )] , ℓ i , θ ( v ) := log π T i ( v ∣ s t ) π θ ( v ∣ s t ) .
Denote the covariance matrix F t ( θ ) = E π θ [ z θ z θ ⊤ ] F_t(\theta) = \mathbb{E}_{\pi_\theta}[z_\theta z_\theta^\top] F t ( θ ) = E π θ [ z θ z θ ⊤ ] . Recall that ∇ L i = E π θ [ z θ ℓ i , θ ] \nabla L_i = \mathbb{E}_{\pi_\theta}[z_\theta\ell_{i,\theta}] ∇ L i = E π θ [ z θ ℓ i , θ ] . Then, we differentiate to obtain:
∇ 2 L i ( θ ) = F t ( θ ) + E π θ [ ( z θ z θ ⊤ − F t ( θ ) ) ℓ i , θ ] . (26) \nabla^2 L_i(\theta) = F_t(\theta) + \mathbb{E}_{\pi_\theta}\left[(z_\theta z_\theta^\top- F_t(\theta))\ell_{i,\theta}\right]. \tag*{(26)} ∇ 2 L i ( θ ) = F t ( θ ) + E π θ [ ( z θ z θ ⊤ − F t ( θ )) ℓ i , θ ] . (26)
Let ∥ ⋅ ∥ o p \lVert\cdot\rVert_{\mathrm{op}} ∥ ⋅ ∥ op denote the Euclidean operator norm. Since ∥ ϕ ∥ 2 ≤ B \lVert\phi\rVert_2 \le B ∥ ϕ ∥ 2 ≤ B , it holds that ∥ F t ( θ ) ∥ o p ≤ B 2 \lVert F_t(\theta)\rVert_{\mathrm{op}} \le B^2 ∥ F t ( θ ) ∥ op ≤ B 2 and ∥ z θ ( v ) ∥ 2 ≤ 2 B \lVert z_\theta(v)\rVert_2 \le2B ∥ z θ ( v ) ∥ 2 ≤ 2 B . To bound the operator norm of E π θ [ ( z θ z θ ⊤ − F t ( θ ) ) ℓ i , θ ] \mathbb{E}_{\pi_\theta}[(z_\theta z_\theta^\top- F_t(\theta))\ell_{i,\theta}] E π θ [( z θ z θ ⊤ − F t ( θ )) ℓ i , θ ] , we calculate:
∥ E π θ [ ( z θ z θ ⊤ − F t ( θ ) ) ℓ i , θ ] ∥ o p = ∥ E π θ [ ( z θ ( v ) z θ ( v ) ⊤ − F t ( θ ) ) ( log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v ) ) ] ∥ o p ≤ E π θ [ ∥ ( z θ ( v ) z θ ( v ) ⊤ − F t ( θ ) ) ( log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v ) ) ∥ o p ] = E π θ [ ∣ log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v ) ∣ ∥ z θ ( v ) z θ ( v ) ⊤ − F t ( θ ) ∥ o p ] ≤ 5 B 2 E π θ [ ∣ log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v ) ∣ ] ≤ 5 B 2 ( log ∣ V ∣ + W B ) , \begin{aligned}
\left\lVert\mathbb{E}_{\pi_\theta}\left[(z_\theta z_\theta^\top- F_t(\theta))\ell_{i,\theta}\right]\right\rVert_{\mathrm{op}}
&= \left\lVert\mathbb{E}_{\pi_\theta}\left[(z_\theta(v)z_\theta(v)^\top- F_t(\theta))(\log\pi_\theta(v \mid s_t) - \omega_i^\top\psi_i(s_t,v))\right]\right\rVert_{\mathrm{op}} \\
&\le\mathbb{E}_{\pi_\theta}\left[\left\lVert(z_\theta(v)z_\theta(v)^\top- F_t(\theta))(\log\pi_\theta(v \mid s_t) - \omega_i^\top\psi_i(s_t,v))\right\rVert_{\mathrm{op}}\right] \\
&= \mathbb{E}_{\pi_\theta}\left[|\log\pi_\theta(v \mid s_t) - \omega_i^\top\psi_i(s_t,v)|\lVert z_\theta(v)z_\theta(v)^\top- F_t(\theta)\rVert_{\mathrm{op}}\right] \\
&\le5B^2\mathbb{E}_{\pi_\theta}\left[|\log\pi_\theta(v \mid s_t) - \omega_i^\top\psi_i(s_t,v)|\right] \\
&\le5B^2(\log|V| + WB),
\end{aligned} E π θ [ ( z θ z θ ⊤ − F t ( θ )) ℓ i , θ ] op = E π θ [ ( z θ ( v ) z θ ( v ) ⊤ − F t ( θ )) ( log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v )) ] op ≤ E π θ [ ( z θ ( v ) z θ ( v ) ⊤ − F t ( θ )) ( log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v )) op ] = E π θ [ ∣ log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v ) ∣ ∥ z θ ( v ) z θ ( v ) ⊤ − F t ( θ ) ∥ op ] ≤ 5 B 2 E π θ [ ∣ log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v ) ∣ ] ≤ 5 B 2 ( log ∣ V ∣ + W B ) ,
where the second to last inequality follows from ∥ z θ ( v ) z θ ( v ) ⊤ − F t ( θ ) ∥ o p ≤ 5 B 2 \lVert z_\theta(v)z_\theta(v)^\top-F_t(\theta)\rVert_{\mathrm{op}}\leq5B^2 ∥ z θ ( v ) z θ ( v ) ⊤ − F t ( θ ) ∥ op ≤ 5 B 2 , and the last inequality follows from the following bound on the scale factor:
E π θ ∣ log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v ) ∣ = ∑ v ∈ V π θ ( v ∣ s t ) ∣ log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v ) ∣ ≤ ∑ v ∈ V π θ ( v ∣ s t ) ( ∣ log π θ ( v ∣ s t ) ∣ + ∣ ω i ⊤ ψ i ( s t , v ) ∣ ) ≤ ∑ v ∈ V π θ ( v ∣ s t ) ( − log π θ ( v ∣ s t ) + W B ) = H ( π θ ( ⋅ ∣ s t ) ) + W B ≤ log ∣ V ∣ + W B . \begin{aligned}
\mathbb{E}_{\pi_\theta}\lvert\log\pi_\theta(v\mid s_t)-\omega_i^\top\psi_i(s_t,v)\rvert
&=\sum_{v\in\mathcal{V}}\pi_\theta(v\mid s_t)\lvert\log\pi_\theta(v\mid s_t)-\omega_i^\top\psi_i(s_t,v)\rvert\\
&\leq\sum_{v\in\mathcal{V}}\pi_\theta(v\mid s_t)\left(\lvert\log\pi_\theta(v\mid s_t)\rvert+\lvert\omega_i^\top\psi_i(s_t,v)\rvert\right)\\
&\leq\sum_{v\in\mathcal{V}}\pi_\theta(v\mid s_t)\left(-\log\pi_\theta(v\mid s_t)+WB\right)\\
&=H\left(\pi_\theta(\cdot\mid s_t)\right)+WB\\
&\leq\log\lvert\mathcal{V}\rvert+WB.
\end{aligned} E π θ ∣ log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v )∣ = v ∈ V ∑ π θ ( v ∣ s t ) ∣ log π θ ( v ∣ s t ) − ω i ⊤ ψ i ( s t , v )∣ ≤ v ∈ V ∑ π θ ( v ∣ s t ) ( ∣ log π θ ( v ∣ s t )∣ + ∣ ω i ⊤ ψ i ( s t , v )∣ ) ≤ v ∈ V ∑ π θ ( v ∣ s t ) ( − log π θ ( v ∣ s t ) + W B ) = H ( π θ ( ⋅ ∣ s t ) ) + W B ≤ log ∣ V ∣ + W B .
Finally, by triangle inequality, we have
∥ ∇ 2 L i ( θ ) ∥ o p ≤ ∥ F t ( θ ) ∥ o p + ∥ E [ ( z θ z θ ⊤ − F t ( θ ) ) ℓ i , θ ] ∥ o p ≤ B 2 ( 1 + 5 ( log ∣ V ∣ + W B ) ) , \lVert\nabla^2L_i(\theta)\rVert_{\mathrm{op}}\leq\lVert F_t(\theta)\rVert_{\mathrm{op}}+\left\lVert\mathbb{E}\left[(z_\theta z_\theta^\top-F_t(\theta))\ell_{i,\theta}\right]\right\rVert_{\mathrm{op}}\leq B^2(1+5(\log\lvert\mathcal{V}\rvert+WB)), ∥ ∇ 2 L i ( θ ) ∥ op ≤ ∥ F t ( θ ) ∥ op + E [ ( z θ z θ ⊤ − F t ( θ )) ℓ i , θ ] op ≤ B 2 ( 1 + 5 ( log ∣ V ∣ + W B )) ,
as desired.
Lemma 9 (Explicit probability control constants). For a real function f f f on the vocabulary V \mathcal{V} V , define osc ( f ) : = max v f ( v ) − min v f ( v ) \operatorname{osc}(f):=\max_v f(v)-\min_v f(v) osc ( f ) := max v f ( v ) − min v f ( v ) . Abbreviating the student and teacher features by ϕ ( v ) \phi(v) ϕ ( v ) , ψ i ( v ) \psi_i(v) ψ i ( v ) respectively, let
g i , θ S ( v ) : = ( θ − θ 0 ) ⊤ ϕ ( v ) , g i T ( v ) : = ω i ⊤ ψ i ( v ) − θ 0 ⊤ ϕ ( v ) , g^S_{i,\theta}(v):=(\theta-\theta_0)^\top\phi(v),\qquad g^T_i(v):=\omega_i^\top\psi_i(v)-\theta_0^\top\phi(v), g i , θ S ( v ) := ( θ − θ 0 ) ⊤ ϕ ( v ) , g i T ( v ) := ω i ⊤ ψ i ( v ) − θ 0 ⊤ ϕ ( v ) , and
δ i ( θ ) : = max { osc ( g i , θ S ) , osc ( g i T ) } . \delta_i(\theta):=\max\left\{\operatorname{osc}(g^S_{i,\theta}),\operatorname{osc}(g^T_i)\right\}. δ i ( θ ) := max { osc ( g i , θ S ) , osc ( g i T ) } . Then the interpolation π i , θ , λ \pi_{i,\theta,\lambda} π i , θ , λ satisfies
e − δ i ( θ ) ≤ π i , θ , λ ( v ) π θ 0 ( v ) ≤ e δ i ( θ ) for every v ∈ V , λ ∈ [ 0 , 1 ] , (27) e^{-\delta_i(\theta)}\leq\frac{\pi_{i,\theta,\lambda}(v)}{\pi_{\theta_0}(v)}\leq e^{\delta_i(\theta)}\quad\text{for every }v\in\mathcal{V},\ \lambda\in[0,1], \tag*{(27)} e − δ i ( θ ) ≤ π θ 0 ( v ) π i , θ , λ ( v ) ≤ e δ i ( θ ) for every v ∈ V , λ ∈ [ 0 , 1 ] , (27) where the oscillations are bounded by
0 ≤ δ i ( θ ) ≤ 2 B max { ∥ θ − θ 0 ∥ 2 , W + ∥ θ 0 ∥ 2 } . (28) 0\leq\delta_i(\theta)\leq2B\max\left\{\lVert\theta-\theta_0\rVert_2,W+\lVert\theta_0\rVert_2\right\}. \tag*{(28)} 0 ≤ δ i ( θ ) ≤ 2 B max { ∥ θ − θ 0 ∥ 2 , W + ∥ θ 0 ∥ 2 } . (28) In particular, for the candidate heads θ ˉ i = ρ i ω i \bar{\theta}_i=\rho_i\omega_i θ ˉ i = ρ i ω i with ρ i ∈ [ 0 , 1 ] \rho_i\in[0,1] ρ i ∈ [ 0 , 1 ] , we can choose
Γ c a n d : = exp ( max i ∈ { 1 , 2 } δ i ( θ ˉ i ) ) ≤ exp { 2 B ( W + ∥ θ 0 ∥ 2 ) } < ∞ . (29) \Gamma_{\mathrm{cand}}:=\exp\left(\max_{i\in\{1,2\}}\delta_i(\bar{\theta}_i)\right)\leq\exp\left\{2B(W+\lVert\theta_0\rVert_2)\right\}<\infty. \tag*{(29)} Γ cand := exp ( i ∈ { 1 , 2 } max δ i ( θ ˉ i ) ) ≤ exp { 2 B ( W + ∥ θ 0 ∥ 2 ) } < ∞. (29) to satisfy Γ c a n d − 1 π θ 0 ( v ) ≤ π i , θ ˉ i , λ ( v ) ≤ Γ c a n d π θ 0 ( v ) \Gamma_{\mathrm{cand}}^{-1}\pi_{\theta_0}(v)\leq\pi_{i,\bar{\theta}_i,\lambda}(v)\leq\Gamma_{\mathrm{cand}}\pi_{\theta_0}(v) Γ cand − 1 π θ 0 ( v ) ≤ π i , θ ˉ i , λ ( v ) ≤ Γ cand π θ 0 ( v ) for both teachers and all v , λ v,\lambda v , λ .
Proof. Let g i , θ , λ ( v ) : = ( 1 − λ ) g i , θ S ( v ) + λ g i T ( v ) g_{i,\theta,\lambda}(v):=(1-\lambda)g^S_{i,\theta}(v)+\lambda g^T_i(v) g i , θ , λ ( v ) := ( 1 − λ ) g i , θ S ( v ) + λ g i T ( v ) . Then, by normalization, we obtain
π i , θ , λ ( v ) π θ 0 ( v ) = exp g i , θ , λ ( v ) E π θ 0 exp g i , θ , λ . (30) \frac{\pi_{i,\theta,\lambda}(v)}{\pi_{\theta_0}(v)}=\frac{\exp g_{i,\theta,\lambda}(v)}{\mathbb{E}_{\pi_{\theta_0}}\exp g_{i,\theta,\lambda}.} \tag*{(30)} π θ 0 ( v ) π i , θ , λ ( v ) = E π θ 0 exp g i , θ , λ . exp g i , θ , λ ( v ) (30) For λ ∈ [ 0 , 1 ] \lambda\in[0,1] λ ∈ [ 0 , 1 ] , the oscillation of this convex combination satisfies
osc ( g i , θ , λ ) ≤ ( 1 − λ ) osc ( g i , θ S ) + λ osc ( g i T ) ≤ δ i ( θ ) . \operatorname{osc}(g_{i,\theta,\lambda})\leq(1-\lambda)\operatorname{osc}(g^S_{i,\theta})+\lambda\operatorname{osc}(g^T_i)\leq\delta_i(\theta). osc ( g i , θ , λ ) ≤ ( 1 − λ ) osc ( g i , θ S ) + λ osc ( g i T ) ≤ δ i ( θ ) . Also, because the denominator is an expectation,
e min u g i , θ , λ ( u ) ≤ E π θ 0 e g i , θ , λ ≤ e max u g i , θ , λ ( u ) . e^{\min_u g_{i,\theta,\lambda}(u)}\leq\mathbb{E}_{\pi_{\theta_0}}e^{g_{i,\theta,\lambda}}\leq e^{\max_u g_{i,\theta,\lambda}(u)}. e m i n u g i , θ , λ ( u ) ≤ E π θ 0 e g i , θ , λ ≤ e m a x u g i , θ , λ ( u ) .
Combining these inequalities with Equation (30) bounds the ratio between e − osc ( g i , θ , λ ) e^{-\operatorname{osc}(g_{i,\theta,\lambda})} e − osc ( g i , θ , λ ) and e osc ( g i , θ , λ ) e^{\operatorname{osc}(g_{i,\theta,\lambda})} e osc ( g i , θ , λ ) , proving Equation (27) . Finally, to show that Γ c a n d \Gamma_{\mathrm{cand}} Γ cand satisfies the condition, note that Cauchy–Schwarz and the feature bounds give, for every token,
∣ g i , θ S ( v ) ∣ ≤ B ∥ θ − θ 0 ∥ 2 , ∣ g i T ( v ) ∣ ≤ B ( W + ∥ θ 0 ∥ 2 ) , \lvert g^S_{i,\theta}(v)\rvert\le B\lVert\theta-\theta_0\rVert_2,\qquad\lvert g^T_i(v)\rvert\le B(W+\lVert\theta_0\rVert_2), ∣ g i , θ S ( v )∣ ≤ B ∥ θ − θ 0 ∥ 2 , ∣ g i T ( v )∣ ≤ B ( W + ∥ θ 0 ∥ 2 ) ,
and by triangle inequality we have
osc ( g i , θ S ) ≤ 2 B ∥ θ − θ 0 ∥ 2 , osc ( g i T ) ≤ 2 B ( W + ∥ θ 0 ∥ 2 ) , \operatorname{osc}(g^S_{i,\theta}) \le2B\lVert\theta-\theta_0\rVert_2,\qquad\operatorname{osc}(g^T_i) \le2B(W+\lVert\theta_0\rVert_2), osc ( g i , θ S ) ≤ 2 B ∥ θ − θ 0 ∥ 2 , osc ( g i T ) ≤ 2 B ( W + ∥ θ 0 ∥ 2 ) ,
which proves Equation (28) . At the candidate heads,
∥ θ ˉ i − θ 0 ∥ 2 ≤ ρ i ∥ ω i ∥ 2 + ∥ θ 0 ∥ 2 ≤ W + ∥ θ 0 ∥ 2 . \lVert\bar{\theta}_i-\theta_0\rVert_2 \le\rho_i\lVert\omega_i\rVert_2+\lVert\theta_0\rVert_2 \le W+\lVert\theta_0\rVert_2. ∥ θ ˉ i − θ 0 ∥ 2 ≤ ρ i ∥ ω i ∥ 2 + ∥ θ 0 ∥ 2 ≤ W + ∥ θ 0 ∥ 2 .
Substituting into the oscillation bound and taking the maximum over the two teachers proves Equation (29) .
Proofs of Confidence-Based Routing Selection
In this section, we give results for understanding when entropy-based teacher routing can lead to good learnability. In Appendix D, we will see how this selection method is actually complementary to the representation-based selection method from before. As before, we are not concerned with the reward, as the contribution of that is deferred to the corresponding term of the performance difference lemma in Appendix B.1.
We continue with similar notation from previous sections, fixing a prefix s t = ( x , y < t ) s_t=(x,y_{<t}) s t = ( x , y < t ) . One difference, however, is that for technical reasons, we will assume the two teachers share the same feature map. Let ϕ ( s t , v ) ∈ R d \phi(s_t,v)\in\mathbb{R}^d ϕ ( s t , v ) ∈ R d be the frozen student feature map, and let ψ ( s t , v ) ∈ R d \psi(s_t,v)\in\mathbb{R}^d ψ ( s t , v ) ∈ R d be a frozen feature map shared by the two teachers. We abbreviate these maps by ϕ ( v ) \phi(v) ϕ ( v ) and ψ ( v ) \psi(v) ψ ( v ) at the fixed prefix. Then, the policies are
π θ ( v ) = exp ( θ ⊤ ϕ ( v ) ) ∑ z ∈ V exp ( θ ⊤ ϕ ( z ) ) , π T i ( v ) = exp ( ω i ⊤ ψ ( v ) ) ∑ z ∈ V exp ( ω i ⊤ ψ ( z ) ) . \pi_\theta(v)=\frac{\exp(\theta^\top\phi(v))}{\sum_{z\in\mathcal{V}}\exp(\theta^\top\phi(z))},\qquad\pi_{T_i}(v)=\frac{\exp(\omega_i^\top\psi(v))}{\sum_{z\in\mathcal{V}}\exp(\omega_i^\top\psi(z))}. π θ ( v ) = ∑ z ∈ V exp ( θ ⊤ ϕ ( z )) exp ( θ ⊤ ϕ ( v )) , π T i ( v ) = ∑ z ∈ V exp ( ω i ⊤ ψ ( z )) exp ( ω i ⊤ ψ ( v )) .
As before, let θ 0 \theta_0 θ 0 be the student head at initialization, and let ω i \omega_i ω i be the fixed head of teacher i i i . Define once again the following:
L i ( θ ) : = KL ( π θ ∥ π T i ) , d i : = − ∇ L i ( θ 0 ) , a i : = ∥ d i ∥ 2 . L_i(\theta):=\operatorname{KL}(\pi_\theta\Vert\pi_{T_i}),\qquad d_i:=-\nabla L_i(\theta_0),\qquad a_i:=\lVert d_i\rVert_2. L i ( θ ) := KL ( π θ ∥ π T i ) , d i := − ∇ L i ( θ 0 ) , a i := ∥ d i ∥ 2 .
In addition, we will write H ( π ) : = − ∑ v π ( v ) log π ( v ) H(\pi):=-\sum_v\pi(v)\log\pi(v) H ( π ) := − ∑ v π ( v ) log π ( v ) for entropy of π \pi π at this fixed prefix and H i : = H ( π T i ) H_i:=H(\pi_{T_i}) H i := H ( π T i ) for teacher i i i ’s entropy.
Assumption 7 (Equal feature alignment and teacher head directions). In addition to Assumption 1 from before, we will also assume that the teacher heads have a common unit direction u ∈ R d \boldsymbol{u}\in\mathbb{R}^d u ∈ R d :
ω i = W i u , ∥ u ∥ 2 = 1 , W i > 0 , i ∈ { 1 , 2 } . \omega_i=W_i\boldsymbol{u},\qquad\lVert\boldsymbol{u}\rVert_2=1,\qquad W_i>0,\qquad i\in\{1,2\}. ω i = W i u , ∥ u ∥ 2 = 1 , W i > 0 , i ∈ { 1 , 2 } . We also denote the cross-covariance scalar multiple as ρ ∈ ( 0 , 1 ] \rho\in(0,1] ρ ∈ ( 0 , 1 ] , where E π θ 0 [ ϕ ψ ⊤ ] = ρ I d \mathbb{E}_{\pi_{\theta_0}}[\phi\psi^\top]=\rho I_d E π θ 0 [ ϕ ψ ⊤ ] = ρ I d , where we define ρ : = ρ 1 = ρ 2 \rho:=\rho_1=\rho_2 ρ := ρ 1 = ρ 2 and ψ : = ψ 1 = ψ 2 \psi:=\psi_1=\psi_2 ψ := ψ 1 = ψ 2 from the setting of Assumption 1.
As a technical assumption similar to the previous analysis, we will assume the following about the inner product between the teacher and student heads at initialization.
Assumption 8. Let β : = ⟨ u , θ 0 ⟩ \beta:=\langle\boldsymbol{u},\theta_0\rangle β := ⟨ u , θ 0 ⟩ . Then, ρ min { W 1 , W 2 } ≥ β \rho\min\{W_1,W_2\}\ge\beta ρ min { W 1 , W 2 } ≥ β .
We now prove the following theorem.
Theorem 6 (Comparison of initial gradients). Under the preceding assumptions, we have that H 1 < H 2 H_1<H_2 H 1 < H 2 if and only if W 1 > W 2 W_1>W_2 W 1 > W 2 . Moreover,
a 1 2 − a 2 2 = ρ ( W 1 − W 2 ) [ ρ ( W 1 + W 2 ) − 2 β ] , (31) a_1^2-a_2^2=\rho(W_1-W_2)\left[\rho(W_1+W_2)-2\beta\right], \tag*{(31)} a 1 2 − a 2 2 = ρ ( W 1 − W 2 ) [ ρ ( W 1 + W 2 ) − 2 β ] , (31) which is positive if and only if a 1 > a 2 a_1>a_2 a 1 > a 2 .
Proof. Let the common scalar logit profile be f ( v ) : = u ⊤ ψ ( v ) f(v) := u^\top\psi(v) f ( v ) := u ⊤ ψ ( v ) . For a scalar head magnitude w > 0 w > 0 w > 0 , write
A ( w ) : = log ∑ v e w f ( v ) , π w T ( v ) : = e w f ( v ) − A ( w ) . A(w) := \log\sum_v e^{w f(v)}, \qquad\pi_w^T(v) := e^{w f(v)-A(w)}. A ( w ) := log v ∑ e w f ( v ) , π w T ( v ) := e w f ( v ) − A ( w ) .
Using this notation, we have that the teachers are π T i = π W i T \pi_{T_i} = \pi_{W_i}^T π T i = π W i T . Differentiating the above yields
A ′ ( w ) = E π w T [ f ] , A ′ ′ ( w ) = Var π w T ( f ) . A'(w) = \mathbb{E}_{\pi_w^T}[f], \qquad A''(w) = \operatorname{Var}_{\pi_w^T}(f). A ′ ( w ) = E π w T [ f ] , A ′′ ( w ) = Var π w T ( f ) .
Substituting log π w T = w f − A ( w ) \log\pi_w^T = wf - A(w) log π w T = w f − A ( w ) into entropy yields
H ( π w T ) = A ( w ) − w A ′ ( w ) , d d w H ( π w T ) = − w A ′ ′ ( w ) = − w Var π w T ( f ) < 0. H(\pi_w^T) = A(w) - wA'(w), \qquad\frac{d}{dw}H(\pi_w^T) = -wA''(w) = -w\operatorname{Var}_{\pi_w^T}(f) < 0. H ( π w T ) = A ( w ) − w A ′ ( w ) , d w d H ( π w T ) = − w A ′′ ( w ) = − w Var π w T ( f ) < 0.
Thus, H 1 < H 2 H_1 < H_2 H 1 < H 2 if and only if W 1 > W 2 W_1 > W_2 W 1 > W 2 , as all of the above steps are reversible. Next, we recall the gradient from Equation (8) as
d i = C i ( t ) ω i − F t θ 0 = ρ W i u − θ 0 . d_i = C_i(t)\omega_i - F_t\theta_0 = \rho W_i u - \theta_0. d i = C i ( t ) ω i − F t θ 0 = ρ W i u − θ 0 .
We therefore subtract the two squared norms to obtain
a 1 2 − a 2 2 = ρ 2 ( W 1 2 − W 2 2 ) − 2 ρ β ( W 1 − W 2 ) = ρ ( W 1 − W 2 ) [ ρ ( W 1 + W 2 ) − 2 β ] . \begin{aligned}
a_1^2-a_2^2 &= \rho^2(W_1^2-W_2^2)-2\rho\beta(W_1-W_2) \\
&=\rho(W_1-W_2)\left[\rho(W_1+W_2)-2\beta\right].
\end{aligned} a 1 2 − a 2 2 = ρ 2 ( W 1 2 − W 2 2 ) − 2 ρβ ( W 1 − W 2 ) = ρ ( W 1 − W 2 ) [ ρ ( W 1 + W 2 ) − 2 β ] .
If W 1 > W 2 W_1 > W_2 W 1 > W 2 , we have by Assumption 8 that
ρ ( W 1 + W 2 ) − 2 β ≥ ρ ( W 1 + W 2 ) − 2 ρ W 2 = ρ ( W 1 − W 2 ) > 0 , \rho(W_1+W_2)-2\beta\ge\rho(W_1+W_2)-2\rho W_2 = \rho(W_1-W_2)>0, ρ ( W 1 + W 2 ) − 2 β ≥ ρ ( W 1 + W 2 ) − 2 ρ W 2 = ρ ( W 1 − W 2 ) > 0 ,
which implies a 1 > a 2 a_1 > a_2 a 1 > a 2 , as desired. □
Proof of Theorem 2. From here, we can proceed with the argument the same way as Theorem 4 to finish the proof of the learning time separation. □
Unifying Compatibility- and Confidence-Based Teacher Selection
In this section, we detail the heuristic calculations we made in § 4.2 . As before, we fix a prefix s t = ( x , y < t ) s_t=(x,y_{<t}) s t = ( x , y < t ) . Recall from the previous sections that, under our assumptions, the gradient d i d_i d i (and its corresponding norm a i a_i a i ) with respect to teacher i i i can be simplified to
d i ( t ) = ρ i W i u i ⏟ accessible teacher signal − θ 0 , a i 2 = ρ i 2 W i 2 + ∥ θ 0 ∥ 2 − 2 ρ i W i ⟨ u i , θ 0 ⟩ . (32) \begin{aligned}
d_i(t) &= \underbrace{\rho_i W_i u_i}_{\text{accessible teacher signal}}-\theta_0, \\
a_i^2 &= \rho_i^2W_i^2+\lVert\theta_0\rVert^2-2\rho_iW_i\langle u_i,\theta_0\rangle. \tag*{(32)}
\end{aligned} d i ( t ) a i 2 = accessible teacher signal ρ i W i u i − θ 0 , = ρ i 2 W i 2 + ∥ θ 0 ∥ 2 − 2 ρ i W i ⟨ u i , θ 0 ⟩ . (32)
where u i u_i u i defines some unit direction in R d \mathbb{R}^d R d , and W i W_i W i denotes the teacher head magnitudes. In particular, ρ i W i u i \rho_iW_i u_i ρ i W i u i is the part of the teacher’s logit signal represented in the student’s feature coordinates. Considering only that term in the gradient expression, we can make the following observations (which is also justified in our theory):
Closer student-teacher feature gap increases the ρ i \rho_i ρ i towards 1, holding everything else fixed (e.g. the teacher head norms W i W_i W i ). Indeed, in this case, Appendix § 9 shows that this leads to bigger gradient norm.
Lower entropy increases the teacher head norm ∥ ω i ∥ 2 \lVert\omega_i\rVert_2 ∥ ω i ∥ 2 , holding all else fixed (e.g. the teacher features). Indeed, Appendix § 10 proves that this does lead to bigger gradient norm.
Separating imitation from reward. The gradient comparison concerns how strongly a teacher moves the student toward minimizing its KL objective with a given teacher. In the performance-difference decomposition of Appendix § 9 .§ 1 , this concerns imitation; the teacher’s competence remains in its separate reward-gap term. In general, it is an open question to quantify the trade-off between teacher competence and optimization pressures, but we would nonetheless like to include a brief discussion of success cases and failure modes of our two families of teacher selection.
To kick this discussion off, we remark that in most OPD settings, the teachers have some level of competence, and this is simply due to the fact that OPD in the recent literature generally distills from a model that was either 1) a post-trained version of the student, whether via RL or the likes, 2) a bigger (and hence more capable) model from the same model family as the student, or 3) both of the above. We will operate under this mental model for the rest of our exposition in this section.
On the confidence-based selection scheme. One obvious failure mode of this selection scheme is choosing a teacher that is confidently wrong. This may happen if, for instance the teacher was post-trained on bad data that perhaps caused model collapse. However, even barring this pathological case, another failure mode is simply the decrease in diversity of student responses due to imitation of a low-entropy distribution. This is a setting that we noticed in our experiments too by checking pass@k k k , in the sense that there were cases where although the entropy-routed model had better pass@1, it was worse on pass@k k k .
On the other hand, if the teacher is confidently right, then the teacher could potentially be a promising candidate for supervision. Nevertheless, if the thinking patterns do not match with the student, supervision can still remain difficult. The ideal case is where the teacher is confidently right, and the thinking patterns are compatible. In the context of our theory, this would correspond to ψ = ϕ \psi= \phi ψ = ϕ , with very large teacher head.
On the representation-based selection scheme. As with the entropy-based selection scheme, one failure mode is where the teacher (assumed to be post-trained version of the student or a variant) has been tilted towards some undesirable reward distribution. In this case, the student has no choice but to follow the teacher. Indeed, this is the big open problem in post-training, of how to calibrate competence vs. magnitude learning signal.
Formulations of Various Objectives
Implementation of OPD Objectives and Gradients
Recall that a commonly used approximation to the full reverse KL gradient is the expression in Equation (1) , which ignores the terms of future time steps that a prefix may influence. For ease of exposition, we write the given gradient here once again:
E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ ∑ t = 1 ∣ y ∣ log π θ ( y t ∣ s t ) π T ( y t ∣ s t ) ∇ θ log π θ ( y t ∣ s t ) ] (33) \mathbb{E}_{x\sim\mathcal{D},y\sim\pi_\theta(\cdot\mid x)}\left[\sum_{t=1}^{\lvert y\rvert}\log\frac{\pi_\theta(y_t\mid s_t)}{\pi_T(y_t\mid s_t)}\nabla_\theta\log\pi_\theta(y_t\mid s_t)\right] \tag*{(33)} E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) t = 1 ∑ ∣ y ∣ log π T ( y t ∣ s t ) π θ ( y t ∣ s t ) ∇ θ log π θ ( y t ∣ s t ) (33)
Even in this semi-gradient approximation, we can implement it several ways. In our experiments from § 5 , we consider 1) sampled-token advantage, and 2) top-k k k KL formulation. Previous works in the literature have explored the differences between the two [12 , 19 ] , though in our setting, we are not concerned with the differences between the two implementations. We leave a more detailed analysis of these implementations to future work.
Sampled-token advantage. Let π T ( ⋅ ∣ s t ) \pi_T(\cdot\mid s_t) π T ( ⋅ ∣ s t ) denote the routed teacher at prefix s t s_t s t : the selected teacher under hard routing, or the arithmetic mixture π T , w ( ⋅ ∣ s t ) = ∑ i w i ( s t ) π T i ( ⋅ ∣ s t ) \pi_{T,w}(\cdot\mid s_t)=\sum_i w_i(s_t)\pi_{T_i}(\cdot\mid s_t) π T , w ( ⋅ ∣ s t ) = ∑ i w i ( s t ) π T i ( ⋅ ∣ s t ) under soft routing (in which case the log probability of the sampled token is log ∑ i w i ( s t ) π T i ( y t ∣ s t ) \log\sum_i w_i(s_t)\pi_{T_i}(y_t\mid s_t) log ∑ i w i ( s t ) π T i ( y t ∣ s t ) ). Writing the token-level advantage from Section 2 as
A t : = log π T ( y t ∣ s t ) − log π θ ( y t ∣ s t ) , (34) A_t := \log\pi_T(y_t\mid s_t)-\log\pi_\theta(y_t\mid s_t), \tag*{(34)} A t := log π T ( y t ∣ s t ) − log π θ ( y t ∣ s t ) , (34)
the loss we implement is
L s a m p l e d ( θ ) : = − E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ 1 ∣ y ∣ ∑ t = 1 ∣ y ∣ sg [ A t ] log π θ ( y t ∣ s t ) ] (35) \mathcal{L}_{\mathrm{sampled}}(\theta) := -\mathbb{E}_{x\sim\mathcal{D},y\sim\pi_\theta(\cdot\mid x)}\left[\frac{1}{\lvert y\rvert}\sum_{t=1}^{\lvert y\rvert}\operatorname{sg}[A_t]\log\pi_\theta(y_t\mid s_t)\right] \tag*{(35)} L sampled ( θ ) := − E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) ∣ y ∣ 1 t = 1 ∑ ∣ y ∣ sg [ A t ] log π θ ( y t ∣ s t ) (35)
where sg [ ⋅ ] \operatorname{sg}[\cdot] sg [ ⋅ ] is the stop-gradient operator. That is, the advantage (including its student log probability) is treated as a constant, and only the trailing log π θ ( y t ∣ s t ) \log\pi_\theta(y_t\mid s_t) log π θ ( y t ∣ s t ) is differentiated, so that
∇ θ L s a m p l e d ( θ ) = − E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ 1 ∣ y ∣ ∑ t = 1 ∣ y ∣ A t ∇ θ log π θ ( y t ∣ s t ) ] (36) \nabla_\theta\mathcal{L}_{\mathrm{sampled}}(\theta)=-\mathbb{E}_{x\sim\mathcal{D},y\sim\pi_\theta(\cdot\mid x)}\left[\frac{1}{\lvert y\rvert}\sum_{t=1}^{\lvert y\rvert}A_t\nabla_\theta\log\pi_\theta(y_t\mid s_t)\right] \tag*{(36)} ∇ θ L sampled ( θ ) = − E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) ∣ y ∣ 1 t = 1 ∑ ∣ y ∣ A t ∇ θ log π θ ( y t ∣ s t ) (36)
This is exactly Equation (1) with the routed teacher plugged in, up to the 1 / ∣ y ∣ 1/\lvert y\rvert 1/ ∣ y ∣ factor: each rollout contributes the average over its own length, and the outer expectation is estimated by averaging over the rollouts in the batch. Prompt and padding tokens are never included in either average. The routing weights and the teacher distribution are held fixed during the update, so the choice of teacher enters only through A t A_t A t .
Top-k KL. Let Ω i ( s t ) \Omega_i(s_t) Ω i ( s t ) be the set of top-K K K tokens of teacher i i i at prefix s t s_t s t , where we take K = 8 K=8 K = 8 throughout, and let π ˉ T i ( ⋅ ∣ s t ) \bar{\pi}_{T_i}(\cdot\mid s_t) π ˉ T i ( ⋅ ∣ s t ) be π T i ( ⋅ ∣ s t ) \pi_{T_i}(\cdot\mid s_t) π T i ( ⋅ ∣ s t ) restricted to Ω i ( s t ) \Omega_i(s_t) Ω i ( s t ) and renormalized to sum to one. The teacher target is
π ˉ T , w ( v ∣ s t ) : = ∑ i w i ( s t ) π ˉ T i ( v ∣ s t ) , v ∈ Ω ( s t ) : = ⋃ i : w i ( s t ) > 0 Ω i ( s t ) (37) \bar{\pi}_{T,w}(v\mid s_t):=\sum_i w_i(s_t)\bar{\pi}_{T_i}(v\mid s_t),\qquad v\in\Omega(s_t):=\bigcup_{i:w_i(s_t)>0}\Omega_i(s_t) \tag*{(37)} π ˉ T , w ( v ∣ s t ) := i ∑ w i ( s t ) π ˉ T i ( v ∣ s t ) , v ∈ Ω ( s t ) := i : w i ( s t ) > 0 ⋃ Ω i ( s t ) (37)
so each teacher is normalized on its own top-K K K support before mixing, and the support of the target is the union of the supports of the teachers with positive weight. Let π θ Ω ( ⋅ ∣ s t ) \pi^\Omega_\theta(\cdot\mid s_t) π θ Ω ( ⋅ ∣ s t ) denote the student’s softmax restricted to Ω ( s t ) \Omega(s_t) Ω ( s t ) , i.e. renormalized over the same support. The loss is then the reverse KL between these two restricted distributions, averaged over the length of the rollout as before:
L T o p K ( θ ) : = E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ 1 ∣ y ∣ ∑ t = 1 ∣ y ∣ KL ( π θ Ω ( ⋅ ∣ s t ) ∥ π ˉ T , w ( ⋅ ∣ s t ) ) ] (38) \mathcal{L}_{\mathrm{TopK}}(\theta):=\mathbb{E}_{x\sim\mathcal{D},y\sim\pi_\theta(\cdot\mid x)}\left[\frac{1}{\lvert y\rvert}\sum_{t=1}^{\lvert y\rvert}\operatorname{KL}\left(\pi^\Omega_\theta(\cdot\mid s_t)\mathbin{\|}\bar{\pi}_{T,w}(\cdot\mid s_t)\right)\right] \tag*{(38)} L TopK ( θ ) := E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) ∣ y ∣ 1 t = 1 ∑ ∣ y ∣ KL ( π θ Ω ( ⋅ ∣ s t ) ∥ π ˉ T , w ( ⋅ ∣ s t ) ) (38)
In the same spirit as Equation (1) , we differentiate only through the per-token KL terms, with the sampled prefixes and the teacher target held fixed, which gives
∇ θ L T o p K ( θ ) = E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) [ 1 ∣ y ∣ ∑ t = 1 ∣ y ∣ ∑ v ∈ Ω ( s t ) π θ Ω ( v ∣ s t ) log π θ Ω ( v ∣ s t ) π ˉ T , w ( v ∣ s t ) ∇ θ log π θ Ω ( v ∣ s t ) ] (39) \nabla_\theta\mathcal{L}_{\mathrm{TopK}}(\theta)=\mathbb{E}_{x\sim\mathcal{D},y\sim\pi_\theta(\cdot\mid x)}\left[\frac{1}{\lvert y\rvert}\sum_{t=1}^{\lvert y\rvert}\sum_{v\in\Omega(s_t)}\pi^\Omega_\theta(v\mid s_t)\log\frac{\pi^\Omega_\theta(v\mid s_t)}{\bar{\pi}_{T,w}(v\mid s_t)}\nabla_\theta\log\pi^\Omega_\theta(v\mid s_t)\right] \tag*{(39)} ∇ θ L TopK ( θ ) = E x ∼ D , y ∼ π θ ( ⋅ ∣ x ) ∣ y ∣ 1 t = 1 ∑ ∣ y ∣ v ∈ Ω ( s t ) ∑ π θ Ω ( v ∣ s t ) log π ˉ T , w ( v ∣ s t ) π θ Ω ( v ∣ s t ) ∇ θ log π θ Ω ( v ∣ s t ) (39)
Unlike the sampled-token advantage, which only ever sees the sampled token y t y_t y t , this takes a full expectation over the restricted support at each position, so no sampling noise enters at the token level; on the other hand, the student’s probability mass outside of Ω ( s t ) \Omega(s_t) Ω ( s t ) receives no direct signal. The same batch averaging conventions as above apply.
Routing Scores and Teacher Targets
In this section, we give the precise score functions S i ( s t ; θ j ) S_i(s_t;\theta_j) S i ( s t ; θ j ) that enter the router in Equation (2) , organized into the same three families as § 3 , followed by the temperatures we use. In every case, the score is computed from the same prefix s t = ( x , y < t ) s_t=(x,y_{<t}) s t = ( x , y < t ) whose next token y t y_t y t the loss supervises, so there is no lookahead into y t y_t y t , and the resulting weights w i ( s t ) w_i(s_t) w i ( s t ) are detached and held fixed during the update. Given the weights, the teacher target is the selected teacher under hard routing (τ = 0 \tau=0 τ = 0 ) or the arithmetic mixture π T , w \pi_{T,w} π T , w under soft routing, which then enters either the sampled-token advantage or the top-K K K KL objective exactly as described in Appendix § 12 .§ 1 .
Direct section routing. We use this in the two settings where the response has an explicit section structure. In the synthetic math–Triton task of Section 5.1, the composite prompt asks for both solutions in a specified order and asks that each be wrapped in its own tag (<math_solution> and <triton_solution>). Routing is then deterministic given the tags completed so far in the prefix: before any tag is opened, we route to the teacher of the task requested first; inside an opened tag, we route to that domain’s teacher, and once a tag is closed, we route to the teacher of the remaining task. Tags appearing inside fenced or inline code are ignored, and a token that completes a tag is still routed according to the state before it. In the Triton-only task of Section 5.2, the sections are the student’s thinking block and the answer that follows it: every token generated while the thinking block is open is routed to the thinking teacher, and every token after the closing thinking tag is routed to Dr.Kernel, again with the closing tag itself routed according to the state before it. In the notation of (2) , this is equivalent to taking τ = 0 \tau= 0 τ = 0 with S i ( s t ; θ j ) = 1 S_i(s_t; \theta_j) = 1 S i ( s t ; θ j ) = 1 for the assigned teacher and 0 otherwise.
Confidence-based routing. Following H-OPD [59 ] , the score of teacher i i i is its negative entropy at the prefix,
S i e n t ( s t ; θ j ) = − H ( π ˉ T i ( ⋅ ∣ s t ) ) , (40) S_i^{\mathrm{ent}}(s_t; \theta_j) = -H(\bar{\pi}_{T_i}(\cdot\mid s_t)), \tag*{(40)} S i ent ( s t ; θ j ) = − H ( π ˉ T i ( ⋅ ∣ s t )) , (40)
where π ˉ T i ( ⋅ ∣ s t ) \bar{\pi}_{T_i}(\cdot\mid s_t) π ˉ T i ( ⋅ ∣ s t ) is the teacher’s top-K K K distribution renormalized on its own support, with K = 8 K = 8 K = 8 , as in Appendix § 12 .§ 1 . In other words, this is the entropy of the teacher’s top-8 renormalized distribution rather than its full-vocabulary entropy. Note that the score does not depend on the student at all.
Representation-based routing. We implement two scores in this family, depending on whether or not the student and teachers share an architecture.
Feature matching. In the algorithmic coding setting of Section 5.3, the student and both teachers are Qwen3-4B models, so their hidden states live in the same space. Let h θ ( s t ) h_\theta(s_t) h θ ( s t ) and h i ( s t ) h_i(s_t) h i ( s t ) denote the student’s and teacher i i i ’s hidden states at the last position of the prefix, taken after the residual addition of the final decoder block (block 36) and before the final RMSNorm. We normalize each to unit length and score teacher i i i by the negative squared Euclidean distance,
S i f e a t ( s t ; θ j ) = − ∥ h θ ( s t ) ∥ h θ ( s t ) ∥ 2 − h i ( s t ) ∥ h i ( s t ) ∥ 2 ∥ 2 2 , (41) S_i^{\mathrm{feat}}(s_t; \theta_j) = -\left\lVert\frac{h_\theta(s_t)}{\lVert h_\theta(s_t)\rVert_2} - \frac{h_i(s_t)}{\lVert h_i(s_t)\rVert_2} \right\rVert_2^2, \tag*{(41)} S i feat ( s t ; θ j ) = − ∥ h θ ( s t ) ∥ 2 h θ ( s t ) − ∥ h i ( s t ) ∥ 2 h i ( s t ) 2 2 , (41)
so that teachers whose feature direction is closer to the student’s receive a higher score.
Hellinger distance. In the synthetic math–Triton, visual reasoning, and Triton-only settings, at least one teacher has a different hidden size from the student (Dr.Kernel-8B, the Qwen3-VL-4B and Qwen3-4B teachers of the 2B student, and Qwen3-30B-A3B-Thinking, respectively), so we instead compare next-token distributions. For scoring, let Ω ( s t ) \Omega(s_t) Ω ( s t ) be the union of both teachers’ top-8 supports at s t s_t s t (so ∣ Ω ( s t ) ∣ ≤ 16 |\Omega(s_t)| \le16 ∣Ω ( s t ) ∣ ≤ 16 ), regardless of whether the eventual loss uses a hard-selected teacher. We gather the student’s and each teacher’s logits at every token in Ω ( s t ) \Omega(s_t) Ω ( s t ) and renormalize there, writing π θ Ω \pi_\theta^\Omega π θ Ω and π T i Ω \pi_{T_i}^\Omega π T i Ω for the resulting distributions. The score is the negative Hellinger distance between the two,
S i H e l ( s t ; θ j ) = − H ( π θ Ω ( ⋅ ∣ s t ) , π T i Ω ( ⋅ ∣ s t ) ) , H ( μ , ν ) = [ 1 2 ∑ v ∈ Ω ( s t ) ( μ ( v ) − ν ( v ) ) 2 ] 1 / 2 , (42) S_i^{\mathrm{Hel}}(s_t; \theta_j) = -H(\pi_\theta^\Omega(\cdot\mid s_t), \pi_{T_i}^\Omega(\cdot\mid s_t)), \qquad H(\mu,\nu) = \left[\frac{1}{2}\sum_{v \in\Omega(s_t)}\left(\sqrt{\mu(v)}-\sqrt{\nu(v)}\right)^2\right]^{1/2}, \tag*{(42)} S i Hel ( s t ; θ j ) = − H ( π θ Ω ( ⋅ ∣ s t ) , π T i Ω ( ⋅ ∣ s t )) , H ( μ , ν ) = 2 1 v ∈ Ω ( s t ) ∑ ( μ ( v ) − ν ( v ) ) 2 1/2 , (42)
which is the same definition as in Section 3.
Routing temperatures. Soft weights are obtained by plugging the raw scores above into (2) . For entropy and feature matching, we sweep τ ∈ { 0.1 , 0.25 , 0.5 , 1 } \tau\in\{0.1, 0.25, 0.5, 1\} τ ∈ { 0.1 , 0.25 , 0.5 , 1 } , and for Hellinger routing, we sweep τ ∈ { 10 − 4 , 10 − 3 , 10 − 2 } \tau\in\{10^{-4}, 10^{-3}, 10^{-2}\} τ ∈ { 1 0 − 4 , 1 0 − 3 , 1 0 − 2 } , since Hellinger distances lie in [ 0 , 1 ] [0, 1] [ 0 , 1 ] and the gaps between two teachers are typically small. In each setting, we report the temperature with the best pass @1.
Training Details and Hyperparameters
Algorithmic coding. The distillation prompts are the 25,276 Eurus-2-RL code training prompts [9 ] , with 1,024 code prompts held out for validation. These are the same prompts on which the code RL expert was trained. The math RL expert is trained on DeepMath [14 ] for 500 iterations, following the domain-specialization setup of Yang et al. [ [57 ] .
Synthetic math–Triton task. The Triton side starts from 11,621 KernelBook programs [33 ] , which deduplicate by exact source code to 8,884 distinct programs. Before any length filtering, 512 programs are reserved for validation and 256 for a future test split; every remaining program is paired with a distinct, shuffled DeepMath training problem, and the math problems used for validation are excluded from math training. Composite prompts longer than 4,096 tokens are dropped, leaving 8,077 training pairs and 509 validation pairs.
Visual reasoning. The visual reasoning runs use the training set released with H-OPD [59 ] : 54,840 image-based problems with verifiable answers drawn from MMFineReason-123K and filtered by the authors with a GPT-4.1-mini judge. Each problem comes with a Qwen3-VL-generated description of its image; the vision-language teacher receives the image, while the text-only teacher receives the question with the description appended in place of the image. The student is Qwen3-VL-2B-Instruct and the teachers are Qwen3-VL-4B-Instruct and the text-only Qwen3-4B-Instruct-2507 [38 a] .
Optimization and sampling. All four settings share the same recipe. The student is trained for 300 updates (400 for visual reasoning) with a batch of 128 prompts and a single rollout per prompt, sampled at temperature 1 and top-p p p = 1 with no top-k k k restriction. We use AdamW with a constant learning rate of 10 − 6 10^{-6} 1 0 − 6 , no warmup, and gradient clipping at 1. The prompt and response token caps are 2,048 and 8,192 for algorithmic coding, 4,096 and 16,384 for the synthetic math–Triton and Triton-only tasks, and 16,384 for both in visual reasoning. Thinking mode is disabled everywhere except in the Triton-only task.
Evaluations
Computing pass@k k k . For every evaluation task, we draw n n n independent responses at temperature 1 and top-p p p = 1 with no top-k k k restriction, using seeds shared across all compared models, and count the number c i c_i c i of responses that are correct for task i i i . With N N N tasks, we report the unbiased estimator of Chen et al. [ [6 ] ,
pass@ k ^ = 1 N ∑ i = 1 N [ 1 − ( n − c i k ) ( n k ) ] , (43) \widehat{\operatorname{pass@}k} = \frac{1}{N} \sum_{i=1}^{N} \left[1 - \frac{\binom{n-c_i}{k}}{\binom{n}{k}}\right], \tag*{(43)} pass@ k = N 1 i = 1 ∑ N [ 1 − ( k n ) ( k n − c i ) ] , (43)
so that every k k k for a given model is computed from the same pool of n n n samples. We report pass@1 1 1 and pass@16 16 16 for the synthetic math–Triton and Triton-only tasks, pass@1 1 1 and pass@64 64 64 for algorithmic coding, and pass@1 1 1 only for visual reasoning.
Synthetic math–Triton. The evaluation set pairs the 30 AIME 2025 problems released by OpenCompass [30 ] with the 100 KernelBench Level 2 tasks [31 ] , giving 3,000 composite prompts, each with a fixed and balanced requested order of the two parts. We evaluate on the 3,000 pairs with n = 16 n = 16 n = 16 responses per pair, a 16,384-token response cap, and thinking disabled. Let M ( r ) M(r) M ( r ) indicate that response r r r gives the correct math answer and C ( r ) C(r) C ( r ) that its kernel passes all configured correctness trials (the fast0 _0 0 criterion of KernelBench). The joint score is J 0 ( r ) = M ( r ) C ( r ) J_0(r) = M(r)C(r) J 0 ( r ) = M ( r ) C ( r ) , so joint fast0 _0 0 requires both parts to be correct in the same response; the math-portion and kernel-portion columns of Table 1 report M M M and C C C separately.
Triton-only. We evaluate on the same 100 KernelBench Level 2 tasks with the same kernel prompt, drawing n = 16 n = 16 n = 16 responses per task with a 32,768-token response cap so that the thinking-mode student can complete its reasoning. Correctness is fast₀ as above, and Table 2 reports pass@1 and pass@16.
Algorithmic coding. We evaluate on the 164 HumanEval+ and 378 MBPP+ problems of EvalPlus [6 , 2 , 21 ] , drawing n = 128 n = 128 n = 128 responses per problem. Table 3 reports pass@1 and pass@64 from this pool.
Visual reasoning. We report pass@1 only, on WeMath [36 ] , MathVista-mini [25 ] , and the reasoning questions of the CharXiv validation split [52 ] . WeMath is scored as question-level accuracy averaged over 16 sampled responses per question; MathVista-mini and CharXiv use a single sampled response per question. Final answers are extracted and graded with an LLM judge following the VLMEvalKit protocol used by H-OPD [59 ] ; we use GPT-5.6 as the judge in place of GPT-4o-mini from the original paper.
Additional Experiments and Analyses
Visual Reasoning
We report our results for visual reasoning tasks in this section. In Table 4 , Hellinger routing achieves the highest student pass@1 on WeMath [36 ] and MathVista-mini [25 ] : 68.69% and 67.40%, improving over the entropy-based routing by 0.67 and 0.70 percentage points. It ties H-OPD on CharXiv RQ [52 ] at 33.20% and outperforms single-teacher OPD on all three benchmarks.
Table 4. Visual reasoning question-level pass@1 (%).
Code-only feature routing trace
In this section, we present the example rollout from the algorithmic coding task that was referred to in Figure 2 and Figure 3 .
Figure 3. Code-only final-layer feature routing (τ = 0.1 \tau= 0.1 τ = 0.1 ; step 300). We plot the code-minus-math score gap here against response token index. Here, the dashed colored segments show the mean gaps during explanation and implementation.
Prompt
user
Find the largest rectangular area possible in a given histogram where the largest rectangle can be
made of a number of contiguous bars. For simplicity, assume that all bars have the same width
and the width is 1 unit, there will be N bars height of each bar will be given by the array arr.
Example 1:
Input:
N = 7
arr[] = {6,2,5,4,5,1,6}
Output: 12
````text Explanation: In this example the largest area would be 12 of height 4 and width 3. We can achieve this area by choosing 3rd, 4th and 5th bars. Example 2: Input: N = 8 arr[] = {7 2 8 9 1 3 6 5} Output: 16 Explanation: Maximum size of the histogram will be 8 and there will be 2 consecutive histogram. And hence the area of the histogram will be 8x2 = 16. Your Task: The task is to complete the function getMaxArea() which takes the array arr[] and its size N as inputs and finds the largest rectangular area possible and returns the answer. Expected Time Complxity : O(N) Expected Auxilliary Space : O(N) Constraints: 1 <U+2264> N <U+2264> 10^{6} 0 <U+2264> arr[i] <U+2264> 10^{12}
Write Python code to solve the problem. Present the code in
Your code
at the end. You need to think first then write the Python code. assistant <think> </think> ````
To solve the largest rectangular area in a histogram problem efficiently in O(N) time and O(N) space, we can use a monotonic stack approach.
Intuition:
For each bar, we want to find:
Then, the maximum area for that bar is ‘height * (right_bound - left_bound - 1)‘.
This is because:
The bar can extend from ‘left_bound + 1‘ to ‘right_bound - 1‘.
The width is ‘(right_bound - left_bound - 1)‘, and the height is the height of the current bar.
### Steps:
1. Initialize an empty stack.
2. Iterate through the array:
- While the stack is not empty and the current bar’s height is less than the height of the bar at the top of the stack:
- Pop the top of the stack and calculate the area.
- The popped bar’s height is the height of the rectangle.
- The width is determined by the current index and the new top of the stack (or 0 if stack is empty).
- Push the current index into the stack.
3. After the iteration, process any remaining elements in the stack in a similar way.
### Edge Cases:
- If all bars are increasing, the stack will be processed at the end.
- If all bars are decreasing, we process each bar as we go.
### Python Code:
```python
def getMaxArea(arr):
stack = []
max_area = 0
n = len(arr)
for i in range(n):
while stack and arr[i] < arr[stack[-1]]:
height = arr[stack.pop()]
width = i if not stack else i - stack[-1] - 1
max_area = max(max_area, height * width)
stack.append(i)
# Process remaining bars in the stack
while stack:
height = arr[stack.pop()]
width = n if not stack else n - stack[-1] - 1
max_area = max(max_area, height * width)
return max_area
Example Test Cases:
# Example 1
print(getMaxArea([6, 2, 5, 4, 5, 1, 6])) # Output: 12
# Example 2
print(getMaxArea([7, 2, 8, 9, 1, 3, 6, 5])) # Output: 16
Complexity:
Time Complexity: O ( N ) O(N) O ( N ) , as each bar is pushed and popped from the stack exactly once.
Space Complexity: O ( N ) O(N) O ( N ) , for the stack.
This solution is efficient and meets the constraints given.
## Triton-only entropy routing trace {#sec:H.3}
In this section, we present the example rollout from the Triton-thinking task for which we plotted the teacher score gaps in {xref}`Figure 1`.
**Prompt**
user
You write custom Triton kernels to replace the pytorch operators in the given architecture to get speedups.
You have complete freedom to choose the set of operators you want to replace. You may make the
decision to replace some operators with custom Triton kernels and leave others unchanged. You may replace multiple operators with custom implementations, consider operator fusion opportunities (combining multiple operators into a single kernel, for example, combining matmul+relu), or algorithmic changes (such as online softmax). You are only limited by your imagination.
Here’s an example to show you the syntax of inline embedding custom Triton kernels in torch: The example given architecture is:
import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self) -> None:
super().__init__()
def forward(self, a, b):
return a + b
def get_inputs():
# randomly generate input tensors based on the model architecture
a = torch.randn(1, 128).cuda()
b = torch.randn(1, 128).cuda()
return [a, b]
def get_init_inputs():
# randomly generate tensors required for initialization based on the model architecture
return []
The example new arch with custom Triton kernels looks like this:
import torch
import torch.nn as nn
import torch.nn.functional as F
import triton
import triton.language as tl
@triton.jit
def add_kernel(
x_ptr, # Pointer to first input
y_ptr, # Pointer to second input
out_ptr, # Pointer to output
n_elements, # Total number of elements in input/output
BLOCK_SIZE: tl.constexpr,
):
# Each program handles a contiguous block of data of size BLOCK_SIZE
block_start = tl.program_id(0) * BLOCK_SIZE
# Create a range of offsets [0..BLOCK_SIZE-1]
offsets = block_start + tl.arange(0, BLOCK_SIZE)
# Mask to ensure we don’t go out of bounds
mask = offsets < n_elements
# Load input values
x = tl.load(x_ptr + offsets, mask=mask, other=0.0)
y = tl.load(y_ptr + offsets, mask=mask, other=0.0)
# Perform the elementwise addition
out = x + y
# Store the result
tl.store(out_ptr + offsets, out, mask=mask)
def triton_add(x: torch.Tensor, y: torch.Tensor):
"""
This function wraps the Triton kernel call. It:
1. Ensures the inputs are contiguous on GPU.
2. Calculates the grid (blocks) needed.
3. Launches the Triton kernel.
"""
assert x.is_cuda and y.is_cuda, "Tensors must be on CUDA."
x = x.contiguous()
y = y.contiguous()
# Prepare output tensor
out = torch.empty_like(x)
# Number of elements in the tensor
n_elements = x.numel()
BLOCK_SIZE = 128 # Tunable parameter for block size
# Determine the number of blocks needed
grid = lambda meta: ((n_elements + meta["BLOCK_SIZE"] - 1) // meta["BLOCK_SIZE"],)
# Launch the Triton kernel
add_kernel[grid](x, y, out, n_elements, BLOCK_SIZE=BLOCK_SIZE)
return out
class ModelNew(nn.Module):
def __init__(self) -> None:
super().__init__()
def forward(self, a, b):
# Instead of "return a + b", call our Triton-based addition
return triton_add(a, b)
You are given the following architecture:
import torch
import torch.nn as nn
class Model(nn.Module):
"""Model.
.. seealso::
Lin, Tsung-Yi, et al. "Focal loss for dense object detection."
Proceedings of the IEEE international conference on computer vision. 2017.
Args:
gamma (float): Value from 0 to 5, Control between easy background and hard ROI
training examples. If set to 0, equivalent to cross-entropy.
alpha (float): Value from 0 to 1, usually corresponding to the inverse of class frequency
to address class
imbalance.
eps (float): Epsilon to avoid division by zero.
Attributes:
gamma (float): Value from 0 to 5, Control between easy background and hard ROI
training examples. If set to 0, equivalent to cross-entropy.
alpha (float): Value from 0 to 1, usually corresponding to the inverse of class frequency
to address class
imbalance.
eps (float): Epsilon to avoid division by zero.
"""
def __init__(self, gamma=2, alpha=0.25, eps=1e-07):
super(Model, self).__init__()
self.gamma = gamma
self.alpha = alpha
self.eps = eps
def forward(self, input, target):
input = input.clamp(self.eps, 1.0 - self.eps)
cross_entropy = -(target * torch.log(input) + (1 - target) * torch.
log(1 - input))
logpt = -cross_entropy
pt = torch.exp(logpt)
at = self.alpha * target + (1 - self.alpha) * (1 - target)
balanced_cross_entropy = -at * logpt
focal_loss = balanced_cross_entropy * (1 - pt) ** self.gamma
return focal_loss.sum()
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return []
Optimize the architecture named Model with custom Triton kernels! Name your optimized output architecture ModelNew. Output the new code in codeblocks. Please generate real code, NOT pseudocode, make sure the code compiles and is fully functional. Just output the new model code, no other text, and NO testing code!
assistant
Student response
<think>
Okay, I need to optimize the given PyTorch model using Triton kernels. The model is a Focal Loss
implementation. Let me understand what the model does and where Triton can help.
The forward pass computes Focal Loss as follows:
1. Clamp input to [eps, 1 - eps].
2. Compute cross_entropy = -(target * log(input) + (1 - target) * log(1 - input)).
3. logpt = -cross_entropy.
4. pt = exp(logpt).
5. at = alpha * target + (1 - alpha) * (1 - target).
6. balanced_cross_entropy = -at * logpt.
7. focal_loss = balanced_cross_entropy * (1 - pt) ** gamma.
8. Return the sum of the focal loss.
The target and input are both 4D tensors with shape [4,4,4,4] in the example. The expectation is to
replace the PyTorch operations with Triton kernels to speed up.
First, I should identify which parts can be accelerated:
- The element-wise operations (clamp, log, exp, etc.) are all element-wise and could be fused into
a single kernel to reduce memory traffic and kernel launches.
- The gradient (hence the need for Triton) is not required here; we are just performing forward
pass.
Looking at the operations:
- clamp(input, eps, 1 - eps) is easy. Calculator can list output elements.
- log, log(1 - input), exp, (1 - pt) ** gamma, etc. are all element-wise. With Triton, we can write
a single kernel that computes all these steps in one pass.
But not all element-wise operations are compatible with Triton. Wait, we need to compute several
steps. Let’s see.
The main computation is:
- input_clamped = clamp(input, eps, 1 - eps)
- logpt = - (target * log(input_clamped) + (1 - target) * log(1 - input_clamped))
- pt = exp(logpt)
- at = alpha * target + (1 - alpha) * (1 - target)
- balanced_cross_entropy = -at * logpt
Most of these are element-wise. So a single Triton kernel could compute all these elements, then return the sum.
However, Triton kernels specify the output. The extreme case is that the kernel should compute all the elements and then the GPU sum can be done via a reduction in PyTorch. But Tripit can only compute per-element outputs, so data will be on the GPU. The sum can be done in PyTorch with .sum(). But the computational steps can be fused.
Wait, the return is focal_loss.sum(). So the offset is sum over all elements. The process is element-wise on the tensor.
So the approach is to create a Triton kernel that computes each element of focal_loss, writes it to the output tensor, and then return the sum of that output tensor.
But the meet selection point is passing the target and input as inputs to the kernel. The buffer size is the number of elements in the input.
Let’s outline the steps in the kernel:
Then in Python, we: compute output = triton_focal_loss(input, target, alpha, gamma, eps), then return output.sum().
This way, we reduce the number of kernel launches and memory reads/writes.
Now, let’s design the Triton kernel.
First, need to handle:
input and target are 4D tensors, but we can treat them as 1D for the kernel (since the scalar operations are element-wise).
eps, alpha, gamma are scalars.
In the kernel, we need to:
Let me write the kernel.
Constants for the kernel:
Given that user cloakares must run on<U+749E> half the ext<U+961C><U+4FEF> regulable. Wait, no squeeze. Let me think.
Wait, the<U+9A71><U+52A8> is size ’n_elements’. For the grid, we’ll use ((n_elements + BLOCK_SIZE - 1) // BLOCK_SIZE,).
Now, code for the kernel.
But how to handle differentiate sections (target and input) in the kernel.
Martins recommendation: use the pointers to input, target, output.
So kernel signature:
def focal_loss_kernel(input_ptr, target_ptr, output_ptr, n_elements, eps, alpha, gamma, BLOCK_SIZE:
tl.constexpr):
Wait, Triton allows dynamic arguments (like eps, alpha, gamma) but they need to be PL_DIST because
they are scalars. Wait, to pass floats, we can pass them as scalars. Triton kernal sizes can be
precomputed.
Wait, in Triton, the kernel can take scalar parameters as constants, but they need to be specified
in the compile-time (tl.constexpr). But in the example, they are not. Wait, no, Triton supports
passing floats as arguments to the kernel. Wait, the @triton.jit function accepts arguments.
For scalar arguments, they can be passed as python floats. So:
def focal_loss_kernel(input_ptr, target_ptr, output_ptr, n_elements, eps, alpha, gamma, BLOCK_SIZE:
tl.constexpr)
We can set eps, alpha, gamma as constants. Wait, but they are varies per instance. But DAO router
blue. Wait, like gamma is part of the model. So we need to make them available to the kernel.
Parameters to the kernel should be the first few arguments. Thertype method. Or we can define
them as a pointer? No, they are scalars.
Wait, Triton supports passing scalar arguments without. We can pass them as floats. So kernel can
take eps (float), alpha (float), gamma (float) as arguments.
But in thekernel, they need to be embedded as constants. Wait, Triton has a lesser IsNot(of known
type). Allow\Events.Parameters are real.
Wait, trial:
@triton.jit
def focal_loss_kernel(input_ptr, target_ptr, output_ptr, n_elements, eps, alpha, gamma, BLOCK_SIZE:
tl.constexpr):
pid = tl.program_id(0)
offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
# Load input and target
input_values = tl.load(input_ptr + offsets, mask=mask, other=0.0)
target_values = tl.load(target_ptr + offsets, mask=mask, other=0.0)
# Clamp input
clamped = tl.maximum(tl.minimum(input_values, 1.0 - eps), eps)
# Compute log(input) and log(1 - input)
log_input = tl.log(clamped)
log_1_minus = tl.log(1.0 - clamped)
# Compute cross_entropy_l = -(target * log(input) + (1 - target) * log(1 - input))
cross_entropy_l = -(target_values * log_input + (1.0 - target_values) * log_1_minus)
# logpt = -cross_entropy_l
logpt = -cross_entropy_l
# pt = exp(logpt)
pt = tl.exp(logpt)
# at = alpha * target + (1 - alpha) * (1 - target)
at = alpha * target_values + (1.0 - alpha) * (1.0 - target_values)
# balanced_cross_entropy = -at * logpt
balanced_cross_entropy = -at * logpt
# focal_loss = balanced_cross_entropy * (1 - pt) ** gamma
# Note: (1 - pt) and gamma are scalars per element. Use tl.pow for exponentiation.
# Ensure (1 - pt) is positive? If not, use tl.maximum(0, ...), but standard_CTL uses log slips.
focal_loss = balanced_cross_entropy * tl.pow(1.0 - pt, gamma)
# Store output
tl.store(output_ptr + offsets, focal_loss, mask=mask)
Wait, But tl.pow is [TBZ], yes.valuable. Work for general.
Alternatively, since gamma is an exponent, TL direct defines struct Keml as main long.
But alpha and gamma are scalars for each element, so it’s fine.
Now, the instantiation:
In the Python function,<U+65F6><U+95F4><U+8282><U+70B9><U+05DE><U+05E0><U+05D8>:
Ensure input and target are contiguous on CUDA.
Calculate n_elements = input.numel().
Create output tensor of dtype float32 (autograd by PyTorch).
Launch the kernel with grid size = (ceil(n_elements / BLOCK_SIZE),).
Return output.sum().
Wait, but World War III: the model returns sum of focal_loss. So after consuming the input, we can just return output.sum().
Now, let’s check if the kernel is correct.
<U+86E9>_CODE:
import torch
import torch.nn as nn
import triton
import triton.language as tl
@triton.jit
def focal_loss_kernel(input_ptr, target_ptr, output_ptr, n_elements, eps, alpha, gamma, BLOCK_SIZE:
tl.constexpr):
pid = tl.program_id(0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
# Load input and target
input_values = tl.load(input_ptr + offsets, mask=mask, other=0.0)
target_values = tl.load(target_ptr + offsets, mask=mask, other=0.0)
# Clamp input
clamped = tl.maximum(tl.minimum(input_values, 1.0 - eps), eps)
# Compute log(input) and log(1 - input)
log_input = tl.log(clamped)
log_1_minus = tl.log(1.0 - clamped)
# Compute cross_entropy_l = -(target * log(input) + (1 - target) * log(1 - input))
cross_entropy_l = -(target_values * log_input + (1.0 - target_values) * log_1_minus)
# logpt = -cross_entropy_l
logpt = -cross_entropy_l
# pt = exp(logpt)
pt = tl.exp(logpt)
# at = alpha * target + (1 - alpha) * (1 - target)
at = alpha * target_values + (1.0 - alpha) * (1.0 - target_values)
# balanced_cross_entropy = -at * logpt
balanced_cross_entropy = -at * logpt
# focal_loss = balanced_cross_entropy * (1 - pt) ** gamma
focal_loss = balanced_cross_entropy * tl.pow(1.0 - pt, gamma)
# Store result
tl.store(output_ptr + offsets, focal_loss, mask=mask)
def triton_focal_loss(input, target, alpha=0.25, gamma=2., eps=1e-7):
"""
Compute Focal Loss using Triton kernel.
Assumes input and target are CUDA tensors.
"""
assert input.is_cuda and target.is_cuda, "Tensors must be on CUDA."
input = input.contiguous()
target = target.contiguous()
n_elements = input.numel()
# Output tensor for focal loss per element
output = torch.empty(n_elements, dtype=torch.float32, device=input.device)
# Kernel launch
BLOCK_SIZE = 1024 # Can be tuned
grid = lambda meta: (triton.cdiv(n_elements, meta['BLOCK_SIZE']),)
focal_loss_kernel[grid](input, target, output, n_elements, eps, alpha, gamma,
BLOCK_SIZE=BLOCK_SIZE)
# Return sum of the focal loss
return output.sum()
class ModelNew(nn.Module):
def __init__(self, gamma=2, alpha=0.25, eps=1e-07):
super(ModelNew, self).__init__()
self.gamma = gamma
self.alpha = alpha
self.eps = eps
def forward(self, input, target):
# Use Triton kernel to compute focal loss
return triton_focal_loss(input, target, self.alpha, self.gamma, self.eps)
Wait, but in the original code, the input and target regeneration lot parametrised as something. Make sure the kernel parameters are passed correctly.
Wait, in the original model, during the forward, they do input.clamp(self.eps, 1.0 - self.eps), but in the determination flair<U+52A8><U+529B><U+7535><U+6C60><U+4E00><U+81F4>. However, thelose kernel expresses the clamping in the Triton kernel. So it’s correct.
The math is:
balanced_cross_entropy = -at * logpt
focal_loss = balanced_cross_entropy * (1 - pt) ** gamma
But root_YUV and/or thoughts: -deps = sum of all elements, so cherry in Exodus VT.
But let’s check if note: (1 - pt) can be zero or negative. PT since logpt is - cross_entropy. But pt = exp(-cross_entropy) always positive. So (1 - pt) could be negative. However, in Focal Loss, gamma is positive, even if (1 - pt) is negative, the exponential becomes relaxing taken care of by the kernel.
Regarding clamping: the original code clamp(input, eps, 1 - eps). But log(1 - input) requires 1 - input > 0, so input < 1. So clamping to [eps, 1 - eps] ensures 1 - input > 0, so log is defined. Good.
Now, check if heat pool alot < flotation current bit. Worksheet.
What’s the Guard(eps) here? Let’s see. PlattonHttps: current batch submit then host port.util may<U+0434><U+043E><U+0440><U+043E><U+0436> the user, but this is quantity in micro dt.
So expanding the code.
Wait, but in the original architecture, the inputs are torch.rand([4,4,4,4]) so shape (4,4,4,4). The forward pass does input.clamp(Self.eps, 1.0 - self.eps) which is include 4D tensor. The Triton kernel of lockdown.
But the tensor descriptor SSD direction SUM<U+0E40><U+0E09><U+0E1E><U+0E32>ICS iOS agent s<U+00E1>ng<U+4E2A><U+591A><U+5C0F><U+656F>. The dimensions aren’t immediately important as the kernel treats them as 1D. So we can pass the tensors as 1D.
But what productions? performance-wise: the block size makes sense. 1024 per block, logarithmic protocol. I can<U+3019> accumulation positions. But when scratched there is minor swellness benchmark.
Now, SAREN in each browser NFS directory. Let’s check if the code is correct.
Primary family structure:
Consider to NaN if log(1 - clamped) is incorrectly. Alternatively, fixing small eps, op/judgment harness.
Less likely with HD venom; the math is safe.
Now, refactor the code, delete the previouschemical$mail. Let’s output a new ModelNew class with Triton kernel.
Here’s the code:
import torch
import torch.nn as nn
import triton
import triton.language as tl
@triton.jit
def focal_loss_kernel(input_ptr, target_ptr, output_ptr, n_elements, eps, alpha, gamma, BLOCK_SIZE:
tl.constexpr):
pid = tl.program_id(0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
# Load input and target
input_values = tl.load(input_ptr + offsets, mask=mask, other=0.0)
target_values = tl.load(target_ptr + offsets, mask=mask, other=0.0)
# Clamp input to [eps, 1 - eps]
clamped = tl.maximum(tl.minimum(input_values, 1.0 - eps), eps)
# Compute log(input) and log(1 - input)
log_input = tl.log(clamped)
log_1_minus = tl.log(1.0 - clamped)
# Compute cross_entropy_l = -(target * log(input) + (1 - target) * log(1 - input))
cross_entropy_l = -(target_values * log_input + (1.0 - target_values) * log_1_minus)
# logpt = -cross_entropy_l
logpt = -cross_entropy_l
# pt = exp(logpt)
pt = tl.exp(logpt)
# at = alpha * target + (1 - alpha) * (1 - target)
at = alpha * target_values + (1.0 - alpha) * (1.0 - target_values)
# balanced_cross_entropy = -at * logpt
balanced_cross_entropy = -at * logpt
# focal_loss = balanced_cross_entropy * (1 - pt) ** gamma
focal_loss = balanced_cross_entropy * tl.pow(1.0 - pt, gamma)
# Store result
tl.store(output_ptr + offsets, focal_loss, mask=mask)
def triton_focal_loss(input, target, alpha=0.25, gamma=2., eps=1e-7):
"""
Compute Focal Loss using Triton kernel.
Assumes input and target are CUDA tensors.
"""
assert input.is_cuda and target.is_cuda, "Tensors must be on CUDA."
input = input.contiguous()
target = target.contiguous()
````text n_elements = input.numel()
Output tensor for focal loss per element
output = torch.empty(n_elements, dtype=torch.float32, device=input.device)
Kernel launch
BLOCK_SIZE = 1024 # Can be tuned grid = lambda meta: (triton.cdiv(n_elements, meta[’BLOCK_SIZE’]),) focal_loss_kernel[grid](input, target, output, n_elements, eps, alpha, gamma, BLOCK_SIZE=BLOCK_SIZE)
Return sum of the focal loss
return output.sum()
class ModelNew(nn.Module): def __init__(self, gamma=2, alpha=0.25, eps=1e-07): super(ModelNew, self).__init__() self.gamma = gamma self.alpha = alpha self.eps = eps
def forward(self, input, target):
Use Triton kernel to compute focal loss
return triton_focal_loss(input, target, self.alpha, self.gamma, self.eps) “\ Notes:
The Triton kernel computes the full element-wise Focal Loss and stores it in an output tensor, then the Python function returns the sum, which matches the original code.
The clamp, log, exp, and reduction steps are all fused into a single kernel, reducing the number of memory reads/writes and kernel launches.
Normal device check is done on the frontend.
The kernel uses a 1D grid with a BLOCK_SIZE of 1024. This is a common choice for element-wise operations; you can tune it for your hardware.
This should compile and run on CUDA-equipped systems. If you need more optimization, you could consider further multithreading or block size tuning, but this is a solid first step toward Triton-powered Focal Loss implementation. </think> “‘python import torch import torch.nn as nn import triton import triton.language as tl
@triton.jit def focal_loss_kernel(input_ptr, target_ptr, output_ptr, n_elements, eps, alpha, gamma, BLOCK_SIZE: tl.constexpr): pid = tl.program_id(0) block_start = pid * BLOCK_SIZE offsets = block_start + tl.arange(0, BLOCK_SIZE) mask = offsets < n_elements
input_values = tl.load(input_ptr + offsets, mask=mask, other=0.0) target_values = tl.load(target_ptr + offsets, mask=mask, other=0.0)
clamped = tl.maximum(tl.minimum(input_values, 1.0 - eps), eps)
log_input = tl.log(clamped) log_1_minus = tl.log(1.0 - clamped)
cross_entropy_l = -(target_values * log_input + (1.0 - target_values) * log_1_minus)
logpt = -cross_entropy_l
logpt = -cross_entropy_l ````
# pt = exp(logpt)
pt = tl.exp(logpt)
# at = alpha * target + (1 - alpha) * (1 - target)
at = alpha * target_values + (1.0 - alpha) * (1.0 - target_values)
# balanced_cross_entropy = -at * logpt
balanced_cross_entropy = -at * logpt
# focal_loss = balanced_cross_entropy * (1 - pt) ** gamma
focal_loss = balanced_cross_entropy * tl.pow(1.0 - pt, gamma)
# Store result
tl.store(output_ptr + offsets, focal_loss, mask=mask)
def triton_focal_loss(input, target, alpha=0.25, gamma=2., eps=1e-7):
"""
Compute Focal Loss using Triton kernel.
Assumes input and target are CUDA tensors.
"""
assert input.is_cuda and target.is_cuda, "Tensors must be on CUDA."
input = input.contiguous()
target = target.contiguous()
n_elements = input.numel()
output = torch.empty(n_elements, dtype=torch.float32, device=input.device)
BLOCK_SIZE = 1024
grid = lambda meta: (triton.cdiv(n_elements, meta['BLOCK_SIZE']),)
focal_loss_kernel[grid](input, target, output, n_elements, eps, alpha, gamma,
BLOCK_SIZE=BLOCK_SIZE)
return output.sum()
class ModelNew(nn.Module):
def __init__(self, gamma=2, alpha=0.25, eps=1e-07):
super(ModelNew, self).__init__()
self.gamma = gamma
self.alpha = alpha
self.eps = eps
def forward(self, input, target):
return triton_focal_loss(input, target, self.alpha, self.gamma, self.eps)