Skip to content
ImagineWorld

Unifying ICL, SFT, KL-Regularized RL Through a Bayesian Lens

node_idnode-paper_arxiv-2609.05111_unifying-icl-sft-kl-regularized-rl-through-a-bayesian-lens
node_typenode-paper
schema_profileworld.node_paper.v1
alternate_namesarxiv-2609.05111
statusactive
orthogonal_scopemanifold, entropy, authority, state
manifoldworld
entropymedium
authorityguides
stateexternal
domainimagineworld.net
node_interiorrosetta_contract
unisonone evidence claim read five ways: seated in the calibration-and-belief-priors field, the work unifies in-context learning, supervised fine-tuning, and KL-regularized RL under one Bayesian lens — three training regimes read as the same posterior computation under different constraints — its framework, regime, and stance agreeing on what it is
governed_byWORLD-MANIFOLD, CORPUS
constitutional_citationCONSTITUTION
evidence_bundleworld-bundle-paper
publication_classarxiv_preprint
paper_titleUnifying ICL, SFT, KL-Regularized RL Through a Bayesian Lens
paper_authorsJunxin Fan
arxiv_id2609.05111
arxiv_urlhttps://arxiv.org/abs/2609.05111
arxiv_categories{"primary":"cs.AI","secondary":[]}
arxiv_v2
arxiv_submitted_at2026-09-04
arxiv_updated_at2026-09-14
ocr_sourcearxiv_html
ocr_quality_classverbatim_latexml_html
extraction_toolarxiv-nodepaper-transpose
extraction_pipeline_versionworld-ingest-arxiv-html-v1.0
extracted_at2026-10-13T06:51:09Z
math_preserved_as_latextrue
figures_extractedfalse
references_structurally_parsedfalse
created_at2026-10-13T06:51:09Z
updated_at2026-10-14T05:10:36Z
local graph

Unifying ICL, SFT, KL-Regularized RL Through a Bayesian Lens

Section titled “Unifying ICL, SFT, KL-Regularized RL Through a Bayesian Lens”

Authors: Junxin Fan

arxiv: 2609.05111

Converted to markdown on 2026-10-13 from the arXiv HTML (LaTeXML) rendering. This paper’s figures are not image-based or were unavailable; captions are kept.


Supervised fine-tuning (SFT), few-shot in-context learning (ICL), KL-regularized RLHF/RLVR, and on-policy distillation are usually treated as distinct post-training paradigms. We develop a unified Bayesian perspective in which each is an instance of a two-step template: construct a (generalized) Bayes or Gibbs posterior from a reference model and a utility signal (log-likelihood, reward, or advantage), then approximate it by a forward-KL projection onto a parametric family, either in-weights (SFT/RL) or in-context (ICL). This yields a single chain of equivalences: few-shot ICL is an amortized projection onto the Bayes posterior predictive, and reward-weighted SFT, reward-weighted ICL, and advantage-weighted SFT are forward-KL projections of reward-induced Gibbs posteriors. The framework explains why supervised warm-up is practically unavoidable for importance-weighted projections, and interprets R1/o1-style reasoning models as combining test-time Bayesian search with training-time amortization. Matched-budget experiments on Qwen3 models corroborate the picture: operators that share their learning-signal granularity produce nearly identical updates when support is good and diverge when it degrades, and reward-weighted projection performs on par with standard baselines.

Keywords: in-context learning; supervised fine-tuning; KL-regularized reinforcement learning; Gibbs posterior; Bayesian meta-learning

Part I: Few-shot ICL ≈\approx SFT (Bayesian View)

Section titled “Part I: Few-shot ICL ≈\approx≈ SFT (Bayesian View)”

1.1 Supervised Fine-Tuning (SFT) as Maximum Likelihood

Section titled “1.1 Supervised Fine-Tuning (SFT) as Maximum Likelihood”

Given a dataset D={(x_i,y_i)}_i=1N\mathcal{D}=\{(x\_{i},y\_{i})\}\_{i=1}^{N}, standard supervised fine-tuning maximizes the conditional log-likelihood:

θ_SFT  =  arg⁡max⁡_θ∑_i=1Nlog⁡p_θ(y_i∣x_i).\theta\_{\mathrm{SFT}}\;=\;\arg\max\_{\theta}\sum\_{i=1}^{N}\log p\_{\theta}(y\_{i}\mid x\_{i}).(1)

Equivalently, define the empirical data distribution

p^_data(x,y)  =  1N∑_i=1Nδ_(x_i,y_i)(x,y),\hat{p}\_{\mathrm{data}}(x,y)\;=\;\frac{1}{N}\sum\_{i=1}^{N}\delta\_{(x\_{i},y\_{i})}(x,y),(2)

so that the SFT objective can be written as

θ_SFT  =  arg⁡min⁡_θE_(x,y)∼p^_data[−log⁡p_θ(y∣x)].\theta\_{\mathrm{SFT}}\;=\;\arg\min\_{\theta}\mathbb{E}\_{(x,y)\sim\hat{p}\_{\mathrm{data}}}\big[-\log p\_{\theta}(y\mid x)\big].(3)

Assume the data are generated from an unknown teacher conditional distribution q_true(y∣x)q\_{\mathrm{true}}(y\mid x), and that p^_data\hat{p}\_{\mathrm{data}} is an empirical approximation to the joint q_true(x,y)=q_true(x) q_true(y∣x)q\_{\mathrm{true}}(x,y)=q\_{\mathrm{true}}(x)\,q\_{\mathrm{true}}(y\mid x). Then

E_(x,y)∼q_true[−log⁡p_θ(y∣x)]\displaystyle\mathbb{E}\_{(x,y)\sim q\_{\mathrm{true}}}\big[-\log p\_{\theta}(y\mid x)\big]=E_x∼q_true(x)E_y∼q_true(⋅∣x)[−log⁡p_θ(y∣x)]\displaystyle=\mathbb{E}\_{x\sim q\_{\mathrm{true}}(x)}\mathbb{E}\_{y\sim q\_{\mathrm{true}}(\cdot\mid x)}\big[-\log p\_{\theta}(y\mid x)\big](4)
---------------
=E_x∼q_true(x)[H(q_true(⋅∣x))+KL(q_true(⋅∣x) ∥ p_θ(⋅∣x))],\displaystyle=\mathbb{E}\_{x\sim q\_{\mathrm{true}}(x)}\Big[H\big(q\_{\mathrm{true}}(\cdot\mid x)\big)+\mathrm{KL}\big(q\_{\mathrm{true}}(\cdot\mid x)\,\|\,p\_{\theta}(\cdot\mid x)\big)\Big],(5)

Here we expand the inner expectation using the standard cross-entropy decomposition H(q,p)=H(q)+KL(q∥p)H(q,p)=H(q)+\mathrm{KL}(q\|p) applied to q_true(⋅∣x)q\_{\mathrm{true}}(\cdot\mid x) and p_θ(⋅∣x)p\_{\theta}(\cdot\mid x), where H(⋅)H(\cdot) is conditional entropy. The first term is independent of θ\theta, so minimizing expected negative log-likelihood is equivalent to

θ∗  =  arg⁡min⁡_θE_x∼q_true(x)KL(q_true(⋅∣x) ∥ p_θ(⋅∣x)).\theta^{\ast}\;=\;\arg\min\_{\theta}\mathbb{E}\_{x\sim q\_{\mathrm{true}}(x)}\mathrm{KL}\big(q\_{\mathrm{true}}(\cdot\mid x)\,\|\,p\_{\theta}(\cdot\mid x)\big).(6)

In words, SFT learns p_θp\_{\theta} as the forward KL (maximum-likelihood) projection of the teacher q_trueq\_{\mathrm{true}} onto the model family {p_θ}\{p\_{\theta}\}.11 1 Here “projection” refers to minimizing the forward KL KL(q_true∥p_θ)\mathrm{KL}(q\_{\mathrm{true}}\|p\_{\theta}), also known as MLE or the m-projection in information geometry.

1.2 Hierarchical Bayesian model for tasks and contexts

Section titled “1.2 Hierarchical Bayesian model for tasks and contexts”

We now introduce a hierarchical Bayesian model for tasks, following the “ICL is Bayes” framework of Wakayama and Suzuki [25].

Let F\mathcal{F} be a space of functions f:X→Δ(Y)f:\mathcal{X}\to\Delta(\mathcal{Y}). A random task is sampled as

f∼P(f),f\sim P(f),(7)

and conditioned on ff, data pairs (x,y)(x,y) are generated i.i.d. by

x∼P_X,y∼f(⋅∣x).x\sim P\_{X},\qquad y\sim f(\cdot\mid x).(8)

For a given task ff, a few-shot context (prompt) and a query point are generated as

D_k={(x_i,y_i)}_i=1k,(x_k+1,y_k+1)∼P_X×f(⋅∣x_k+1).D\_{k}=\{(x\_{i},y\_{i})\}\_{i=1}^{k},\qquad(x\_{k+1},y\_{k+1})\sim P\_{X}\times f(\cdot\mid x\_{k+1}).(9)

Bayes posterior over tasks and posterior predictive.

Section titled “Bayes posterior over tasks and posterior predictive.”

Given context D_kD\_{k}, the posterior over tasks is

P(f∣D_k)  ∝  P(f) ∏_i=1kf(y_i∣x_i),P(f\mid D\_{k})\;\propto\;P(f)\,\prod\_{i=1}^{k}f(y\_{i}\mid x\_{i}),(10)

and the corresponding Bayes posterior predictive at a new query x_k+1x\_{k+1} is

P_Bayes(y∣x_k+1,D_k)  :=  E_f∼P(f∣D_k)[f(y∣x_k+1)].P\_{\mathrm{Bayes}}(y\mid x\_{k+1},D\_{k})\;:=\;\mathbb{E}\_{f\sim P(f\mid D\_{k})}\big[f(y\mid x\_{k+1})\big].(11)

Consider any in-context prediction rule MM that maps (D_k,x_k+1)(D\_{k},x\_{k+1}) to a predictive distribution M(D_k,x_k+1)∈Δ(Y).M(D\_{k},x\_{k+1})\in\Delta(\mathcal{Y}). Under log-loss, define the ICL risk

R(M)  :=  E[−log⁡M(D_k,x_k+1)(y_k+1)],R(M)\;:=\;\mathbb{E}\big[-\log M(D\_{k},x\_{k+1})(y\_{k+1})\big],(12)

where the expectation is over the hierarchical model above (sampling ff, then D_kD\_{k} and (x_k+1,y_k+1)(x\_{k+1},y\_{k+1})).

Theorem 1 (Bayes-optimal in-context predictor; after Wakayama and Suzuki [25]). Define the Bayes posterior predictive

M_Bayes(D_k,x_k+1):=P_Bayes(⋅∣x_k+1,D_k).M\_{\mathrm{Bayes}}(D\_{k},x\_{k+1}):=P\_{\mathrm{Bayes}}(\cdot\mid x\_{k+1},D\_{k}).(13)

Then:

  • (i)

    M_BayesM\_{\mathrm{Bayes}} is the unique minimizer of R(M)R(M) over all measurable predictors MM.

  • (ii)

    For any MM, we define its Bayes Gap as

    BayesGap(M)  :=  R(M)−R(M_Bayes).\mathrm{BayesGap}(M)\;:=\;R(M)-R(M\_{\mathrm{Bayes}}).(14)

    In particular, the excess risk satisfies

    R(M)−R(M_Bayes)  =  BayesGap(M).R(M)-R(M\_{\mathrm{Bayes}})\;=\;\mathrm{BayesGap}(M).(15)

    In the squared-loss setting of Wakayama and Suzuki [25], this quantity coincides with their Bayes Gap term R_BG(M)R\_{\mathrm{BG}}(M) in the decomposition R(M)=R_BG(M)+R_PVR(M)=R\_{\mathrm{BG}}(M)+R\_{\mathrm{PV}}, and R(M_Bayes)R(M\_{\mathrm{Bayes}}) corresponds to their Posterior Variance component R_PVR\_{\mathrm{PV}}.

The full non-asymptotic bounds for the Bayes Gap and Posterior Variance are given in Wakayama and Suzuki [25]; here we only use that M_BayesM\_{\mathrm{Bayes}} is the normative target of in-context prediction. This hierarchical model can be justified from a within-task exchangeability assumption via a de Finetti–type representation; see Appendix A.4.

Real transformers process ordered sequences with positional embeddings, so the order of few-shot demonstrations in the prompt can affect predictions. Our exchangeability assumption applies at the level of the data-generating process: within a task, the examples (x_i,y_i)(x\_{i},y\_{i}) are assumed to form an exchangeable sample from an underlying task distribution, so the Bayes posterior P(f∣D_k)P(f\mid D\_{k}) and posterior predictive P_Bayes(y∣x_k+1,D_k)P\_{\text{Bayes}}(y\mid x\_{k+1},D\_{k}) depend only on the multiset {(x_i,y_i)}\{(x\_{i},y\_{i})\}, not on their order. Part I analyzes this ideal, order-symmetric Bayes predictor; practical in-context learners may introduce position-dependent biases, which we view as algorithmic deviations from this ideal rather than violations of the assumption.

1.3 In-context learning as amortized Bayesian inference

Section titled “1.3 In-context learning as amortized Bayesian inference”

Let M_θ(y∣x,D_k)M\_{\theta}(y\mid x,D\_{k}) denote the conditional distribution implemented by a pretrained Transformer with parameters θ\theta. Pretraining across many tasks and contexts can be abstracted as minimizing the expected log-loss

R(θ)  :=  E[−log⁡M_θ(D_k,x_k+1)(y_k+1)],R(\theta)\;:=\;\mathbb{E}\big[-\log M\_{\theta}(D\_{k},x\_{k+1})(y\_{k+1})\big],(16)

where the expectation is over the same hierarchical process as in Section 1.2.

By Theorem 1, the risk-minimizing population predictor is M_BayesM\_{\mathrm{Bayes}}. Thus, in the limit of infinite model capacity and pretraining data, any minimizer M_θ∗M\_{\theta^{\ast}} of R(θ)R(\theta) must satisfy

M_θ∗(D_k,x_k+1)  ≈  M_Bayes(D_k,x_k+1)  =  P_Bayes(⋅∣x_k+1,D_k).M\_{\theta^{\ast}}(D\_{k},x\_{k+1})\;\approx\;M\_{\mathrm{Bayes}}(D\_{k},x\_{k+1})\;=\;P\_{\mathrm{Bayes}}(\cdot\mid x\_{k+1},D\_{k}).(17)

Formally, under the assumption in Sec. 1.5 that the model class {M_θ}\{M\_{\theta}\} is rich enough to approximate M_BayesM\_{\mathrm{Bayes}}, any global minimizer (or sequence of asymptotic minimizers) of R(θ)R(\theta) can be chosen to be arbitrarily close to M_BayesM\_{\mathrm{Bayes}} in expected log-loss.

This viewpoint matches recent constructions that explicitly train Transformers as amortized Bayesian inference procedures over latent variables and datasets (e.g., [23]), where a single forward pass maps each dataset DD to an approximate posterior.

In this Bayesian picture, few-shot ICL is best viewed as learning the mapping

(D_k,x_k+1)  ⟼  P_Bayes(⋅∣x_k+1,D_k)(D\_{k},x\_{k+1})\;\longmapsto\;P\_{\mathrm{Bayes}}(\cdot\mid x\_{k+1},D\_{k})(18)

in an amortized way. The Transformer does not explicitly perform gradient descent in parameter space at test time; instead, it approximates the Bayes posterior predictive directly in its forward pass. While our exposition centers on the Bayesian view, a complementary first-order / meta-learning interpretation (ICL ≈\approx one GD step) has been studied extensively in prior work [5, 3, 14], which shows that Transformers can implement gradient-based updates in their forward passes. We do not re-derive those results here, as our goal is to foreground the Bayesian formulation.

1.4 From Bayes posterior to SFT: forward-KL projection over outputs

Section titled “1.4 From Bayes posterior to SFT: forward-KL projection over outputs”

We now connect the Bayes posterior predictive to supervised fine-tuning.

Fix a context D_kD\_{k} and query x_k+1x\_{k+1}, and write

q_Bayes(y∣x_k+1,D_k)  :=  P_Bayes(y∣x_k+1,D_k)q\_{\mathrm{Bayes}}(y\mid x\_{k+1},D\_{k})\;:=\;P\_{\mathrm{Bayes}}(y\mid x\_{k+1},D\_{k})(19)

for the ideal target distribution over outputs. Consider any parametric conditional model p_θ(y∣x)p\_{\theta}(y\mid x) (suppressing D_kD\_{k} in notation). For this fixed pair (x_k+1,D_k)(x\_{k+1},D\_{k}), the best approximation to q_Bayesq\_{\mathrm{Bayes}} within {p_θ}\{p\_{\theta}\} under log-loss is

θ∗(x_k+1,D_k)  =  arg⁡min⁡_θKL(q_Bayes(⋅∣x_k+1,D_k) ∥ p_θ(⋅∣x_k+1)),\theta^{\ast}(x\_{k+1},D\_{k})\;=\;\arg\min\_{\theta}\mathrm{KL}\big(q\_{\mathrm{Bayes}}(\cdot\mid x\_{k+1},D\_{k})\,\|\,p\_{\theta}(\cdot\mid x\_{k+1})\big),(20)

or equivalently

θ∗(x_k+1,D_k)  =  arg⁡max⁡_θ∑_yq_Bayes(y∣x_k+1,D_k) log⁡p_θ(y∣x_k+1).\theta^{\ast}(x\_{k+1},D\_{k})\;=\;\arg\max\_{\theta}\sum\_{y}q\_{\mathrm{Bayes}}(y\mid x\_{k+1},D\_{k})\,\log p\_{\theta}(y\mid x\_{k+1}).(21)

If we had direct samples y∼q_Bayes(⋅∣x_k+1,D_k)y\sim q\_{\mathrm{Bayes}}(\cdot\mid x\_{k+1},D\_{k}) for many (x_k+1,D_k)(x\_{k+1},D\_{k}), then performing SFT on those samples would be exactly the forward KL projection of the Bayes posterior predictive onto the family {p_θ}\{p\_{\theta}\}. Aggregating over contexts and queries yields the population objective

min⁡_θE_(D_k,x_k+1)KL(q_Bayes(⋅∣x_k+1,D_k) ∥ p_θ(⋅∣x_k+1)),\min\_{\theta}\mathbb{E}\_{(D\_{k},x\_{k+1})}\mathrm{KL}\big(q\_{\mathrm{Bayes}}(\cdot\mid x\_{k+1},D\_{k})\,\|\,p\_{\theta}(\cdot\mid x\_{k+1})\big),(22)

and the standard SFT objective is its empirical approximation.

Bayesian reading of “ICL ≈\approx SFT”.

Section titled “Bayesian reading of “ICL ≈\approx≈ SFT”.”

Putting Sections 1.2-1.4 together:

  • •

    The ideal in-context predictor is the Bayes posterior predictive q_Bayes(⋅∣x_k+1,D_k)q\_{\mathrm{Bayes}}(\cdot\mid x\_{k+1},D\_{k}).

  • •

    A sufficiently expressive Transformer minimizing ICL risk implements an amortized approximation M_θ(⋅∣x_k+1,D_k)M\_{\theta}(\cdot\mid x\_{k+1},D\_{k}) to q_Bayesq\_{\mathrm{Bayes}}.

  • •

    Supervised fine-tuning (SFT) learns p_θp\_{\theta} as the forward KL projection of q_Bayesq\_{\mathrm{Bayes}} (or of an empirical approximation) onto the parametric family.

Thus, in the Bayesian view,

few-shot ICL  ≈  Bayes posterior predictive  ≈  KL-projected SFT solution,\text{few-shot ICL}\;\approx\;\text{Bayes posterior predictive}\;\approx\;\text{KL-projected SFT solution},(23)

and ”ICL ≈\approx SFT” is understood as both being different approximations to the same underlying Bayesian predictor.

This distribution-level identification is the backbone for Part II, where KL-regularized RL (RLHF/RLVR) is shown to define a generalized Gibbs posterior over outputs, and reward-weighted SFT is exactly its KL projection onto {p_θ}\{p\_{\theta}\}.

Regularity for Part I (Bayesian ICL and SFT).

Section titled “Regularity for Part I (Bayesian ICL and SFT).”

We assume: (i) a well-defined hierarchical prior P(f)P(f) and data-generating mechanism as in Section 1.2 (this representation follows from a within-task exchangeability assumption; see Appendix A.4);

(ii) log-loss and finite Y\mathcal{Y} (or densities with respect to a common base measure); (iii) integrability conditions ensuring Fubini/Tonelli can be applied when exchanging expectations and logs; (iv) a model class {M_θ}\{M\_{\theta}\} rich enough that some M_θ∗M\_{\theta^{\ast}} can approximate M_BayesM\_{\mathrm{Bayes}}.

The non-asymptotic generalization guarantees (Bayes Gap bounds, posterior variance behavior under task mixtures, and out-of-distribution analyses) are from Wakayama and Suzuki [25].

We assume β>0\beta>0; rewards rr are bounded above so that exp⁡(r/β)\exp(r/\beta) is integrable; and shared support: π_ref(y∣x)>0\pi\_{\mathrm{ref}}(y\mid x)>0 whenever π(y∣x)>0\pi(y\mid x)>0. Interchange of ∇\nabla and expectation is justified by dominated convergence.

We assume a stationary MDP; well-defined QQ/AA functions; and advantage estimates (e.g., GAE) with bounded bias/variance. These are standard in KL-regularized policy optimization and RL-as-inference formulations.

Remark (Meta-learning view as complementary, not primary). The original meta-learning perspective that ICL behaves like a single small gradient step on a contextual loss can be rigorously justified under additional smoothness and linearization assumptions, and connects attention to accumulated gradient updates. We treat that interpretation as complementary (see the discussion and citations summarized in Appendix A.3), while the main text takes the Bayesian formulation as the primary conceptual and mathematical foundation.

Part II: KL-Regularized RL (RLHF/RLVR) ↔\leftrightarrow Reward-weighted SFT

Section titled “Part II: KL-Regularized RL (RLHF/RLVR) ↔\leftrightarrow↔ Reward-weighted SFT”

2.1 KL-regularized RL objective and closed-form optimum

Section titled “2.1 KL-regularized RL objective and closed-form optimum”

Fix an input xx (e.g., a prompt), a reference policy π_ref(⋅∣x)\pi\_{\mathrm{ref}}(\cdot\mid x), a reward function r(⋅∣x)r(\cdot\mid x), and a temperature β>0\beta>0. The standard KL-regularized objective is

max⁡_π    E_y∼π(⋅∣x)[r(y∣x)]  −  β KL ⁣(π(⋅∣x) ∥ π_ref(⋅∣x)).\max\_{\pi}\;\;\mathbb{E}\_{y\sim\pi(\cdot\mid x)}[r(y\mid x)]\;-\;\beta\,\mathrm{KL}\!\big(\pi(\cdot\mid x)\,\|\,\pi\_{\mathrm{ref}}(\cdot\mid x)\big).(24)

This form appears both in RLHF (human preference reward) and in RLVR (verifiable/correctness reward); the only difference is the source of r(y∣x)r(y\mid x) [19, 22, 16, 26].

In practice, many RLHF-style algorithms (e.g., PPO-style KL-penalized RL, GRPO’s effective loss, and RLVR-style updates) optimize surrogate objectives that approximate (24) rather than this exact form. In what follows we work at the level of the underlying KL-regularized objective (24) and abstract away such implementation details.

For discrete Y\mathcal{Y}, we can write the objective as

J(π)=∑_yπ(y∣x) r(y∣x)−β∑_yπ(y∣x)log⁡π(y∣x)π_ref(y∣x),J(\pi)=\sum\_{y}\pi(y\mid x)\,r(y\mid x)-\beta\sum\_{y}\pi(y\mid x)\log\frac{\pi(y\mid x)}{\pi\_{\mathrm{ref}}(y\mid x)},(25)

with the constraint ∑_yπ(y∣x)=1\sum\_{y}\pi(y\mid x)=1. Introducing a Lagrange multiplier λ\lambda for this constraint, the Lagrangian is

L(π,λ)=∑_yπ(y∣x)r(y∣x)−β∑_yπ(y∣x)log⁡π(y∣x)π_ref(y∣x)+λ(1−∑_yπ(y∣x)).\mathcal{L}(\pi,\lambda)=\sum\_{y}\pi(y\mid x)r(y\mid x)-\beta\sum\_{y}\pi(y\mid x)\log\frac{\pi(y\mid x)}{\pi\_{\mathrm{ref}}(y\mid x)}+\lambda\left(1-\sum\_{y}\pi(y\mid x)\right).(26)

Proposition 2 (KL-regularized RL ⇒\Rightarrow Gibbs posterior). The unique maximizer of (24) is

π∗(y∣x)=π_ref(y∣x)exp⁡(r(y∣x)/β)Z(x),Z(x)=∑_yπ_ref(y∣x)exp⁡(r(y∣x)/β).\pi^{\ast}(y\mid x)=\frac{\pi\_{\mathrm{ref}}(y\mid x)\exp\big(r(y\mid x)/\beta\big)}{Z(x)},\qquad Z(x)=\sum\_{y}\pi\_{\mathrm{ref}}(y\mid x)\exp\big(r(y\mid x)/\beta\big).(27)

Take derivative of L\mathcal{L} w.r.t. π(y∣x)\pi(y\mid x):

∂L∂π(y∣x)\displaystyle\frac{\partial\mathcal{L}}{\partial\pi(y\mid x)}=r(y∣x)−β(log⁡π(y∣x)π_ref(y∣x)+1)−λ.\displaystyle=r(y\mid x)-\beta\left(\log\frac{\pi(y\mid x)}{\pi\_{\mathrm{ref}}(y\mid x)}+1\right)-\lambda.(28)

Setting ∂L/∂π(y∣x)=0\partial\mathcal{L}/\partial\pi(y\mid x)=0 gives

log⁡π(y∣x)π_ref(y∣x)=1β(r(y∣x)−λ−β).\log\frac{\pi(y\mid x)}{\pi\_{\mathrm{ref}}(y\mid x)}=\frac{1}{\beta}\big(r(y\mid x)-\lambda-\beta\big).(29)

Exponentiating both sides,

π(y∣x)=π_ref(y∣x) exp⁡ ⁣(r(y∣x)β)exp⁡ ⁣(−λ+ββ).\pi(y\mid x)=\pi\_{\mathrm{ref}}(y\mid x)\,\exp\!\left(\frac{r(y\mid x)}{\beta}\right)\exp\!\left(-\frac{\lambda+\beta}{\beta}\right).(30)

The last factor does not depend on yy and is determined by normalization ∑_yπ(y∣x)=1\sum\_{y}\pi(y\mid x)=1, which yields (27) with Z(x)=∑_yπ_ref(y∣x)exp⁡(r(y∣x)/β).Z(x)=\sum\_{y}\pi\_{\mathrm{ref}}(y\mid x)\exp(r(y\mid x)/\beta).

□\square

Because the negative entropy term −∑_yπ(y∣x)log⁡π(y∣x)-\sum\_{y}\pi(y\mid x)\log\pi(y\mid x) is strictly concave in π(⋅∣x)\pi(\cdot\mid x), the objective in (24) is strictly concave with respect to π\pi, guaranteeing that the stationary point above is the unique maximizer.

Thus, KL-regularized RLHF/RLVR produces a Gibbs posterior over outputs: a generalized Bayes update with prior π_ref(⋅∣x)\pi\_{\mathrm{ref}}(\cdot\mid x) and pseudo-likelihood proportional to exp⁡(r(y∣x)/β)\exp(r(y\mid x)/\beta). This structure is classical in relative-entropy policy search and RL-as-inference formulations [21, 1, 13].

2.2 Reward-weighted SFT as KL projection of the Gibbs posterior

Section titled “2.2 Reward-weighted SFT as KL projection of the Gibbs posterior”

We now show that reward-weighted SFT is exactly the forward-KL projection of π∗\pi^{\ast} onto a parametric family {π_θ}\{\pi\_{\theta}\}.

Fix xx and write

q_Gibbs(y∣x)  :=  π∗(y∣x)=π_ref(y∣x)exp⁡(r(y∣x)/β)Z(x).q\_{\mathrm{Gibbs}}(y\mid x)\;:=\;\pi^{\ast}(y\mid x)=\frac{\pi\_{\mathrm{ref}}(y\mid x)\exp(r(y\mid x)/\beta)}{Z(x)}.(31)

(This q_Gibbsq\_{\mathrm{Gibbs}} is distinct from the teacher distribution q_trueq\_{\mathrm{true}} used in Section 1.1.) Consider a parametric policy π_θ(y∣x)\pi\_{\theta}(y\mid x) and the KL projection problem

θ∗=arg⁡min⁡_θKL(q_Gibbs(⋅∣x) ∥ π_θ(⋅∣x)).\theta^{\ast}=\arg\min\_{\theta}\mathrm{KL}\big(q\_{\mathrm{Gibbs}}(\cdot\mid x)\,\|\,\pi\_{\theta}(\cdot\mid x)\big).(32)

Throughout, when we write f(θ)∝g(θ)f(\theta)\propto g(\theta) we mean that f(θ)=c+g(θ)f(\theta)=c+g(\theta) for a constant cc independent of θ\theta; i.e., we drop additive terms that do not affect the optimizer. Expanding the KL,

KL(q_Gibbs∥π_θ)\displaystyle\mathrm{KL}\big(q\_{\mathrm{Gibbs}}\|\pi\_{\theta}\big)=∑_yq_Gibbs(y∣x)log⁡q_Gibbs(y∣x)π_θ(y∣x)\displaystyle=\sum\_{y}q\_{\mathrm{Gibbs}}(y\mid x)\log\frac{q\_{\mathrm{Gibbs}}(y\mid x)}{\pi\_{\theta}(y\mid x)}(33)
---------------
=∑_yq_Gibbs(y∣x)log⁡q_Gibbs(y∣x)⏟_indep. of θ−∑_yq_Gibbs(y∣x)log⁡π_θ(y∣x).\displaystyle=\underbrace{\sum\_{y}q\_{\mathrm{Gibbs}}(y\mid x)\log q\_{\mathrm{Gibbs}}(y\mid x)}\_{\text{indep. of }\theta}-\sum\_{y}q\_{\mathrm{Gibbs}}(y\mid x)\log\pi\_{\theta}(y\mid x).(34)

Therefore

θ∗=arg⁡max⁡_θ∑_yq_Gibbs(y∣x)log⁡π_θ(y∣x).\theta^{\ast}=\arg\max\_{\theta}\sum\_{y}q\_{\mathrm{Gibbs}}(y\mid x)\log\pi\_{\theta}(y\mid x).(35)

Substituting the Gibbs form of q_Gibbsq\_{\mathrm{Gibbs}},

∑_yq_Gibbs(y∣x)log⁡π_θ(y∣x)\displaystyle\sum\_{y}q\_{\mathrm{Gibbs}}(y\mid x)\log\pi\_{\theta}(y\mid x)=1Z(x)∑_yπ_ref(y∣x)exp⁡ ⁣(r(y∣x)β)log⁡π_θ(y∣x).\displaystyle=\frac{1}{Z(x)}\sum\_{y}\pi\_{\mathrm{ref}}(y\mid x)\exp\!\left(\frac{r(y\mid x)}{\beta}\right)\log\pi\_{\theta}(y\mid x).(36)

The normalizer Z(x)Z(x) does not depend on θ\theta, so maximizing the above is equivalent to maximizing

J_RWSFT(θ;x):=∑_yπ_ref(y∣x)exp⁡ ⁣(r(y∣x)β)log⁡π_θ(y∣x).\mathcal{J}\_{\mathrm{RWSFT}}(\theta;x):=\sum\_{y}\pi\_{\mathrm{ref}}(y\mid x)\exp\!\left(\frac{r(y\mid x)}{\beta}\right)\log\pi\_{\theta}(y\mid x).(37)

Proposition 3 (Reward-weighted SFT = forward-KL projection). For fixed xx, any minimizer of (32) can be obtained by maximizing the reward-weighted SFT objective (37), and any maximizer of (37) minimizes (32). In particular, reward-weighted SFT learns π_θ\pi\_{\theta} as the forward KL projection of the KL-regularized RL optimum π∗\pi^{\ast} (i.e., q_Gibbsq\_{\mathrm{Gibbs}}) onto the parametric family {π_θ}\{\pi\_{\theta}\}.

In practice, one does not enumerate all yy, but instead samples (x,y)(x,y) from a data distribution whose yy-marginal matches π_ref(⋅∣x)\pi\_{\mathrm{ref}}(\cdot\mid x) (e.g., rollouts from the reference model or logged data), and forms the empirical objective

max⁡_θ∑_(x,y)exp⁡ ⁣(r(y∣x)β)log⁡π_θ(y∣x),\max\_{\theta}\sum\_{(x,y)}\exp\!\left(\frac{r(y\mid x)}{\beta}\right)\log\pi\_{\theta}(y\mid x),(38)

which is the familiar reward-weighted SFT loss used in many recent RLHF / RLVR formulations.

KL-regularized RLHF/RLVR has a closed-form optimum π∗\pi^{\ast} that is a Gibbs posterior (27). Reward-weighted SFT is exactly the KL projection of this posterior onto {π_θ}\{\pi\_{\theta}\}. Thus, at the distribution level,

KL-regularized RL (RLHF/RLVR)  ≃  reward-weighted SFT.\text{KL-regularized RL (RLHF/RLVR)}\;\simeq\;\text{reward-weighted SFT}.(39)

This equivalence is meant at the level of the target Gibbs posterior q_Gibbsq\_{\mathrm{Gibbs}} and its forward-KL projection; it does not claim that all practical RLHF algorithms exactly attain the closed-form optimum π∗\pi^{\ast} in (27). This matches recent variational interpretations of RLHF that treat it as reward-weighted regression.

Part III: Reward-weighted Few-shot ICL (RW-ICL)

Section titled “Part III: Reward-weighted Few-shot ICL (RW-ICL)”

We now lift the discussion from single (x,y)(x,y) decisions to few-shot in-context prediction with rewards.

3.1 Generalized Bayesian posterior over outputs given context

Section titled “3.1 Generalized Bayesian posterior over outputs given context”

Let D_k={(x_i,y_i)}_i=1kD\_{k}=\{(x\_{i},y\_{i})\}\_{i=1}^{k} be a context, and x_k+1x\_{k+1} a query. As in Part I, the Bayes posterior predictive under a hierarchical task model is

P_Bayes(y∣x_k+1,D_k)=E_f∼P(f∣D_k)[f(y∣x_k+1)].P\_{\mathrm{Bayes}}(y\mid x\_{k+1},D\_{k})=\mathbb{E}\_{f\sim P(f\mid D\_{k})}[f(y\mid x\_{k+1})].(40)

For our RLHF/RLVR setting, we augment this with a reward signal. Assume that for each potential output yy at (x_k+1,D_k)(x\_{k+1},D\_{k}) we have a scalar score

R(y;D_k,x_k+1),R(y;D\_{k},x\_{k+1}),(41)

which aggregates the relevant reward information (from human preferences, a verifier, or a reward model) given the entire context D_kD\_{k} and query x_k+1x\_{k+1}.

We define a generalized Bayes posterior over outputs:

q_Gibbs(y∣x_k+1,D_k)  ∝  π_ref(y∣x_k+1)exp⁡ ⁣(R(y;D_k,x_k+1)β),q\_{\mathrm{Gibbs}}(y\mid x\_{k+1},D\_{k})\;\propto\;\pi\_{\mathrm{ref}}(y\mid x\_{k+1})\exp\!\left(\frac{R(y;D\_{k},x\_{k+1})}{\beta}\right),(42)

i.e., a Gibbs posterior with prior π_ref(⋅∣x_k+1)\pi\_{\mathrm{ref}}(\cdot\mid x\_{k+1}) and pseudo-likelihood proportional to exp⁡(R/β)\exp(R/\beta). This is the natural extension of Proposition 2 to the context-dependent case.

3.2 RW-ICL objective as KL projection of the generalized posterior

Section titled “3.2 RW-ICL objective as KL projection of the generalized posterior”

Let M_θ(y∣x_k+1,D_k)M\_{\theta}(y\mid x\_{k+1},D\_{k}) denote the in-context predictor implemented by a meta-trained Transformer. A natural population objective for reward-weighted ICL is

min⁡_θE_(D_k,x_k+1)KL(q_Gibbs(⋅∣x_k+1,D_k) ∥ M_θ(⋅∣x_k+1,D_k)),\min\_{\theta}\mathbb{E}\_{(D\_{k},x\_{k+1})}\mathrm{KL}\big(q\_{\mathrm{Gibbs}}(\cdot\mid x\_{k+1},D\_{k})\,\|\,M\_{\theta}(\cdot\mid x\_{k+1},D\_{k})\big),(43)

where the expectation is taken over the same hierarchical meta-distribution on tasks and contexts as in Part I, together with whatever process generates R(y;D_k,x_k+1)R(y;D\_{k},x\_{k+1}).

Expanding the KL and discarding terms independent of θ\theta, (43) is equivalent to maximizing

E_(D_k,x_k+1)E_y∼q_Gibbs(⋅∣x_k+1,D_k)[log⁡M_θ(y∣x_k+1,D_k)].\mathbb{E}\_{(D\_{k},x\_{k+1})}\mathbb{E}\_{y\sim q\_{\mathrm{Gibbs}}(\cdot\mid x\_{k+1},D\_{k})}\big[\log M\_{\theta}(y\mid x\_{k+1},D\_{k})\big].(44)

Substituting the Gibbs form of q_Gibbsq\_{\mathrm{Gibbs}} from (42),

E_(D_k,x_k+1)E_y∼q_Gibbs[log⁡M_θ(y∣x_k+1,D_k)]\displaystyle\mathbb{E}\_{(D\_{k},x\_{k+1})}\mathbb{E}\_{y\sim q\_{\mathrm{Gibbs}}}[\log M\_{\theta}(y\mid x\_{k+1},D\_{k})](45)
---------------
∝E_(D_k,x_k+1)∑_yπ_ref(y∣x_k+1)exp⁡ ⁣(R(y;D_k,x_k+1)β)log⁡M_θ(y∣x_k+1,D_k).\displaystyle\quad\propto\mathbb{E}\_{(D\_{k},x\_{k+1})}\sum\_{y}\pi\_{\mathrm{ref}}(y\mid x\_{k+1})\exp\!\left(\frac{R(y;D\_{k},x\_{k+1})}{\beta}\right)\log M\_{\theta}(y\mid x\_{k+1},D\_{k}).(46)

In practice, one approximates this expectation empirically by sampling contexts D_kD\_{k}, queries x_k+1x\_{k+1}, and candidate outputs yy from the reference model (or from a replay buffer), and forming the empirical objective

max⁡_θ∑_(D_k,x_k+1,y)exp⁡ ⁣(R(y;D_k,x_k+1)β)log⁡M_θ(y∣x_k+1,D_k),\max\_{\theta}\sum\_{(D\_{k},x\_{k+1},y)}\exp\!\left(\frac{R(y;D\_{k},x\_{k+1})}{\beta}\right)\log M\_{\theta}(y\mid x\_{k+1},D\_{k}),(47)

i.e., a reward-weighted in-context SFT objective.

Proposition 4 (RW-ICL = KL projection of generalized Gibbs posterior). Under mild regularity conditions, any minimizer M_θ∗M\_{\theta^{\ast}} of (43) is the forward KL projection of the generalized Gibbs posterior q_Gibbs(⋅∣x_k+1,D_k)q\_{\mathrm{Gibbs}}(\cdot\mid x\_{k+1},D\_{k}) onto the model family {M_θ(⋅∣x_k+1,D_k)}\{M\_{\theta}(\cdot\mid x\_{k+1},D\_{k})\}. Stochastic gradient ascent on (47) implements this projection using samples from π_ref\pi\_{\mathrm{ref}} reweighted by exp⁡(R/β)\exp(R/\beta).

Although our exposition so far has been distributional (KL projections of Gibbs posteriors), the resulting stochastic-gradient updates have exactly the reward-weighted form emphasized in meta-learning views of ICL. For example, the empirical RW-ICL objective (47) has gradient

∇_θL_RW-ICL(θ)=−∑_(D_k,x_k+1,y)exp⁡ ⁣(R(y;D_k,x_k+1)β) ∇_θlog⁡M_θ(y∣x_k+1,D_k),\nabla\_{\theta}\mathcal{L}\_{\mathrm{RW\text{-}ICL}}(\theta)=-\sum\_{(D\_{k},x\_{k+1},y)}\exp\!\Big(\tfrac{R(y;D\_{k},x\_{k+1})}{\beta}\Big)\,\nabla\_{\theta}\log M\_{\theta}(y\mid x\_{k+1},D\_{k}),(48)

so a single SGD step is a reward-weighted in-context update. The reward-weighted SFT and AWSFT losses (37) and (59) yield the same update structure with M_θM\_{\theta} replaced by π_θ\pi\_{\theta} and RR replaced by rr or AA. Thus, at the level of first-order optimization dynamics, RW-ICL, reward-weighted SFT, and KL-regularized RL share the same summed-score ∇_θlog⁡(⋅)\nabla\_{\theta}\log(\cdot) weighted by exp⁡(reward/β)\exp(\text{reward}/\beta); the meta-learning results of Dai et al. [5], Akyürek et al. [3], Li et al. [14] can be viewed as constructive realizations of such updates in a single forward pass.

Comparing (42) to (27), we see that KL-regularized RLHF/RLVR defines the same Gibbs-family posterior over outputs, with R(y;D_k,x_k+1)R(y;D\_{k},x\_{k+1}) playing the role of r(y∣x)r(y\mid x). Reward-weighted ICL meta-trains a Transformer to amortize the mapping

(D_k,x_k+1)  ⟼  q_Gibbs(⋅∣x_k+1,D_k),(D\_{k},x\_{k+1})\;\longmapsto\;q\_{\mathrm{Gibbs}}(\cdot\mid x\_{k+1},D\_{k}),(49)

just as ordinary ICL in Part I amortizes the Bayes posterior predictive. Hence, at the distribution level,

reward-weighted ICL (RW-ICL)  ≈  KL-regularized RLHF/RLVR optimum,\text{reward-weighted ICL (RW-ICL)}\;\approx\;\text{KL-regularized RLHF/RLVR optimum},(50)

up to approximation error in the KL projection.

Part IV: Process-level KL-RLVR and Advantage-weighted SFT

Section titled “Part IV: Process-level KL-RLVR and Advantage-weighted SFT”

We finally consider the full RL setting with trajectories and state-dependent policies, which is the regime of KL-RLVR and related algorithms.

4.1 Statewise KL-regularized objective and Gibbs policy

Section titled “4.1 Statewise KL-regularized objective and Gibbs policy”

Let ss be a state and π(⋅∣s)\pi(\cdot\mid s) a stochastic policy over actions aa. A typical stepwise KL-regularized objective is

max⁡_π    ∑_aπ(a∣s)Q(s,a)  −  β KL(π(⋅∣s) ∥ π_ref(⋅∣s)),\max\_{\pi}\;\;\sum\_{a}\pi(a\mid s)Q(s,a)\;-\;\beta\,\mathrm{KL}\big(\pi(\cdot\mid s)\,\|\,\pi\_{\mathrm{ref}}(\cdot\mid s)\big),(51)

where Q(s,a)Q(s,a) is an action-value function (for example, a critic or Monte Carlo return), and π_ref\pi\_{\mathrm{ref}} is a reference policy. This is the policy-improvement subproblem solved in many KL-regularized policy search methods.

By the same Lagrangian argument as in Proposition 2, the unique maximizer is

π∗(a∣s)=π_ref(a∣s)exp⁡(Q(s,a)/β)Z(s),Z(s)=∑_aπ_ref(a∣s)exp⁡(Q(s,a)/β).\pi^{\ast}(a\mid s)=\frac{\pi\_{\mathrm{ref}}(a\mid s)\exp(Q(s,a)/\beta)}{Z(s)},\qquad Z(s)=\sum\_{a}\pi\_{\mathrm{ref}}(a\mid s)\exp(Q(s,a)/\beta).(52)

This is again a Gibbs posterior, now over actions conditional on state ss, with log-likelihood Q(s,a)/βQ(s,a)/\beta.

It is often convenient to reparameterize in terms of the advantage

A(s,a):=Q(s,a)−V(s),V(s):=∑_aπ_ref(a∣s)Q(s,a),A(s,a):=Q(s,a)-V(s),\qquad V(s):=\sum\_{a}\pi\_{\mathrm{ref}}(a\mid s)Q(s,a),(53)

which only shifts QQ by a baseline independent of aa. Any such state-dependent baseline contributes a multiplicative factor exp⁡(−V(s)/β)\exp(-V(s)/\beta) that is absorbed into the partition function Z(s)Z(s), leaving the normalized policy unchanged. Hence,

π∗(a∣s)  ∝  π_ref(a∣s)exp⁡(A(s,a)/β).\pi^{\ast}(a\mid s)\;\propto\;\pi\_{\mathrm{ref}}(a\mid s)\exp(A(s,a)/\beta).(54)

4.2 Advantage-weighted SFT (AWSFT) as KL projection

Section titled “4.2 Advantage-weighted SFT (AWSFT) as KL projection”

Fix a state ss and define

q_Gibbs(a∣s)  :=  π∗(a∣s)q\_{\mathrm{Gibbs}}(a\mid s)\;:=\;\pi^{\ast}(a\mid s)(55)

given by (52) or (54). For a parametric policy π_θ(a∣s)\pi\_{\theta}(a\mid s), the KL projection problem is

θ∗(s)=arg⁡min⁡_θKL(q_Gibbs(⋅∣s) ∥ π_θ(⋅∣s)).\theta^{\ast}(s)=\arg\min\_{\theta}\mathrm{KL}\big(q\_{\mathrm{Gibbs}}(\cdot\mid s)\,\|\,\pi\_{\theta}(\cdot\mid s)\big).(56)

Expanding as before, this is equivalent to

θ∗(s)=arg⁡max⁡_θ∑_aq_Gibbs(a∣s)log⁡π_θ(a∣s).\theta^{\ast}(s)=\arg\max\_{\theta}\sum\_{a}q\_{\mathrm{Gibbs}}(a\mid s)\log\pi\_{\theta}(a\mid s).(57)

Substituting the Gibbs form with advantages,

∑_aq_Gibbs(a∣s)log⁡π_θ(a∣s)\displaystyle\sum\_{a}q\_{\mathrm{Gibbs}}(a\mid s)\log\pi\_{\theta}(a\mid s)∝∑_aπ_ref(a∣s)exp⁡ ⁣(A(s,a)β)log⁡π_θ(a∣s).\displaystyle\propto\sum\_{a}\pi\_{\mathrm{ref}}(a\mid s)\exp\!\left(\frac{A(s,a)}{\beta}\right)\log\pi\_{\theta}(a\mid s).(58)

Thus, across states ss, the population objective is equivalent to maximizing

J_AWSFT(θ):=E_s∼d(s)∑_aπ_ref(a∣s)exp⁡ ⁣(A(s,a)β)log⁡π_θ(a∣s),\mathcal{J}\_{\mathrm{AWSFT}}(\theta):=\mathbb{E}\_{s\sim d(s)}\sum\_{a}\pi\_{\mathrm{ref}}(a\mid s)\exp\!\left(\frac{A(s,a)}{\beta}\right)\log\pi\_{\theta}(a\mid s),(59)

where d(s)d(s) is some state visitation distribution (e.g., from the reference or a replay buffer).

In practice, we approximate (59) by empirical sums over state–action pairs (s_t,a_t)(s\_{t},a\_{t}) with estimated advantages A^(s_t,a_t)\hat{A}(s\_{t},a\_{t}):

max⁡_θ∑_texp⁡ ⁣(A^(s_t,a_t)β)log⁡π_θ(a_t∣s_t),\max\_{\theta}\sum\_{t}\exp\!\left(\frac{\hat{A}(s\_{t},a\_{t})}{\beta}\right)\log\pi\_{\theta}(a\_{t}\mid s\_{t}),(60)

which is exactly an advantage-weighted SFT (AWSFT) loss. This matches the advantage-weighted regression family of algorithms [20, 17] and entropy-regularized methods such as SAC [8], which all rely on exponentiated QQ/AA weighting.

Proposition 5 (AWSFT = KL projection of statewise KL-RLVR optimum). For each state ss, any minimizer of KL(q_Gibbs(⋅∣s) ∥ π_θ(⋅∣s))\mathrm{KL}(q\_{\mathrm{Gibbs}}(\cdot\mid s)\,\|\,\pi\_{\theta}(\cdot\mid s)) is a maximizer of the local AWSFT objective, and any maximizer of that objective minimizes the KL. Consequently, the global AWSFT objective (59) implements the forward KL projection of the stepwise KL-regularized RL optimum (52) onto the parametric policy family {π_θ}\{\pi\_{\theta}\}.

From the in-context perspective, a trajectory (or multi-step interaction) provides a context

D={(s_t,a_t,r_t)}_t=1T,D=\{(s\_{t},a\_{t},r\_{t})\}\_{t=1}^{T},(61)

and the goal is to predict or select future actions in-context. A reward-weighted in-context learner can be meta-trained to approximate, at each state ss, the Gibbs posterior q_Gibbs(⋅∣s)q\_{\mathrm{Gibbs}}(\cdot\mid s) defined by the (advantage-based) KL-regularized RL objective:

q_Gibbs(a∣s)  ∝  π_ref(a∣s)exp⁡ ⁣(A(s,a)β).q\_{\mathrm{Gibbs}}(a\mid s)\;\propto\;\pi\_{\mathrm{ref}}(a\mid s)\exp\!\left(\frac{A(s,a)}{\beta}\right).(62)

The corresponding RW-ICL meta-objective is the trajectory-level analogue of (43), with per-step pseudo-likelihoods proportional to exp⁡(A^(s_t,a_t)/β)\exp(\hat{A}(s\_{t},a\_{t})/\beta) and model predictions M_θ(a_t∣s_t,D)M\_{\theta}(a\_{t}\mid s\_{t},D). In particular, performing stochastic gradient ascent on this objective yields updates of exactly the same form as those obtained from the advantage-weighted SFT objective

J_AWSFT(θ):=∑_texp⁡ ⁣(A^(s_t,a_t)β)log⁡M_θ(a_t∣s_t,D),\mathcal{J}\_{\mathrm{AWSFT}}(\theta):=\sum\_{t}\exp\!\left(\frac{\hat{A}(s\_{t},a\_{t})}{\beta}\right)\log M\_{\theta}(a\_{t}\mid s\_{t},D),(63)

up to choices of state distribution and context window.

Thus, process-level RW-ICL and stepwise KL-RLVR share the same Gibbs-posterior backbone and are both realized as advantage-weighted SFT in parameter space.

4.4 Learning signals and credit assignment in SFT, RL, and ICL

Section titled “4.4 Learning signals and credit assignment in SFT, RL, and ICL”

The equivalence results in Parts II and III operate at the level of objectives and first-order updates: under a suitable Gibbs posterior, KL-regularized RL, reward-weighted SFT, and reward-weighted ICL all reduce to minimizing a forward KL KL(q\* ∥ p_θ)\mathrm{KL}(q^{\*}\,\|\,p\_{\theta}), and their stochastic gradients share the familiar “weighted score” form. Writing a generic forward-KL loss as

L(θ)  =  ∑_tw_t [−log⁡p_θ(z_t)],\mathcal{L}(\theta)\;=\;\sum\_{t}w\_{t}\,\big[-\log p\_{\theta}(z\_{t})\big],(64)

its gradient takes the form

∇^_θL(θ)  =  −∑_tw_t ∇_θlog⁡p_θ(z_t).\widehat{\nabla}\_{\theta}\mathcal{L}(\theta)\;=\;-\sum\_{t}w\_{t}\,\nabla\_{\theta}\log p\_{\theta}(z\_{t}).(65)

for appropriate choices of samples z_tz\_{t} and weights w_tw\_{t}. However, the source and granularity of the learning signal differ substantially across paradigms. In this section we disentangle these differences and show how they fit into our unified view.

Under standard supervised fine-tuning, the model is trained with a token-level cross-entropy loss. For an autoregressive language model with inputs xx and target sequence y=(t_1,…,t_n)y=(t\_{1},\dots,t\_{n}), the SFT objective can be written as

$$\mathcal{L}_{\text{SFT}}(\theta);=;-\mathbb{E}_{(x,y)}\Bigg[\sum_{i=0}^{n-1}\log p_{\theta}\big(t_{i+1},\big,x,t_{\leq i}\big)\Bigg].$$

Equivalently, SFT learns from every mapping (x,y_≤i)↦y_i+1(x,y\_{\leq i})\mapsto y\_{i+1}: each prefix within a sequence contributes a term to the loss and a gradient to the update. The learning signal is thus dense at the token level, and credit assignment is implicit in the data: human- or model-generated targets (x,y)(x,y) already specify which next-token prediction should be encouraged at each position.

KL-regularized RL: sparse rewards + explicit credit assignment.

Section titled “KL-regularized RL: sparse rewards + explicit credit assignment.”

In contrast, KL-regularized RL (including RLHF/RLVR-style objectives) typically starts from a sequence- or trajectory-level reward. In the sequence-level setting of Part II, the objective has the form

J_RL(π)  =  E_x∼D, y∼π(⋅∣x)[R(y∣x)−β KL(π(⋅∣x) ∥ π_ref(⋅∣x))],J\_{\text{RL}}(\pi)\;=\;\mathbb{E}\_{x\sim D,\,y\sim\pi(\cdot\mid x)}\Big[R(y\mid x)-\beta\,\mathrm{KL}\big(\pi(\cdot\mid x)\,\|\,\pi\_{\mathrm{ref}}(\cdot\mid x)\big)\Big],(67)

and the naive policy gradient estimator looks like

∇^_θJ_RL  ≈  E_x,y∼π_θ[R(y∣x) ∇_θlog⁡π_θ(y∣x)].\widehat{\nabla}\_{\theta}J\_{\text{RL}}\;\approx\;\mathbb{E}\_{x,y\sim\pi\_{\theta}}\Big[R(y\mid x)\,\nabla\_{\theta}\log\pi\_{\theta}(y\mid x)\Big].(68)

At first sight, this appears to support the claim that “RL can only learn once from the mapping x↦R(y)x\mapsto R(y)”: a single scalar reward per sampled sequence.

In practice, however, modern RL algorithms do not update the policy directly from (68). Instead, they introduce a credit assignment step, in which the scalar reward is decomposed into per-step signals. In the step-wise KL-regularized MDP setting of Part IV, this yields a Gibbs-optimal policy

π∗(a∣s)  ∝  π_ref(a∣s) exp⁡(A(s,a)/β),\pi\\*(a\mid s)\;\propto\;\pi\_{\mathrm{ref}}(a\mid s)\,\exp\big(A(s,a)/\beta\big),

and the corresponding forward-KL projection leads to the advantage-weighted SFT objective (cf. Eq. (59)–(60)):

L_AWSFT(θ)  =  −E_(s,a)[exp⁡(A(s,a)/β) log⁡π_θ(a∣s)].\mathcal{L}\_{\text{AWSFT}}(\theta)\;=\;-\mathbb{E}\_{(s,a)}\Big[\exp\big(A(s,a)/\beta\big)\,\log\pi\_{\theta}(a\mid s)\Big].(69)

The resulting policy gradient has exactly the weighted-score form (65):

∇^_θL_AWSFT  =  −∑_texp⁡(A^(s_t,a_t)β) ∇_θlog⁡π_θ(a_t∣s_t).\widehat{\nabla}\_{\theta}\mathcal{L}\_{\text{AWSFT}}\;=\;-\sum\_{t}\exp\Big(\frac{\widehat{A}(s\_{t},a\_{t})}{\beta}\Big)\,\nabla\_{\theta}\log\pi\_{\theta}(a\_{t}\mid s\_{t}).(70)

Thus, while the raw RL signal is a single scalar reward per trajectory, RL algorithms recover the ability to “learn from each (s_t,a_t)(s\_{t},a\_{t})” by explicitly estimating value functions V(s)V(s), action-values Q(s,a)Q(s,a), or advantages A(s,a)A(s,a) and using them as per-step weights. The final policy update becomes a form of advantage- or reward-weighted SFT. In our framework, this is precisely the AWSFT/RWSFT connection established in Parts II and IV: at the level of updates, KL-regularized RL is equivalent to a particular choice of weights w_tw\_{t} in (65).

Few-shot ICL: dense supervision in pretraining, fast learning in activations.

Section titled “Few-shot ICL: dense supervision in pretraining, fast learning in activations.”

Few-shot in-context learning sits somewhat orthogonally to this discussion. As formalized in Part I, we view a parametric ICL predictor M_θ(y∣x,D_k)M\_{\theta}(y\mid x,D\_{k}) as an amortized Bayes approximation to the posterior predictive under a task prior P(f)P(f):

P_Bayes(y∣x,D_k)  =  ∫p_f(y∣x) p(f∣D_k) df.P\_{\mathrm{Bayes}}(y\mid x,D\_{k})\;=\;\int p\_{f}(y\mid x)\,p(f\mid D\_{k})\,df.

The parameters θ\theta are learned using the same dense token-level supervision as in SFT: for example, the outer objective

L_ICL(θ)  =  E_(f,D_k,x_k+1,y_k+1)[−log⁡M_θ(y_k+1∣x_k+1,D_k)]\mathcal{L}\_{\text{ICL}}(\theta)\;=\;\mathbb{E}\_{(f,D\_{k},x\_{k+1},y\_{k+1})}\Big[-\log M\_{\theta}\big(y\_{k+1}\mid x\_{k+1},D\_{k}\big)\Big](71)

is a standard log-loss aggregated over tasks and positions. In this sense, few-shot ICL does not introduce a new type of training signal: it consumes the same token-level (possibly reward-weighted) supervision as SFT/RW-ICL in the outer loop.

The key difference is where and when adaptation happens. At test time, few-shot ICL does not take further gradients on θ\theta. Instead, given a context D_kD\_{k}, the transformer uses attention and MLP activations to construct a task-specific internal state ϕ_θ(D_k)\phi\_{\theta}(D\_{k}) in its forward pass, and the effective predictor for the query can be written schematically as

M_θ(y∣x_k+1,D_k)  ≈  f_ϕ_θ(D_k)(y∣x_k+1)M\_{\theta}(y\mid x\_{k+1},D\_{k})\;\approx\;f\_{\phi\_{\theta}(D\_{k})}(y\mid x\_{k+1})

for some implicit inner model class {f_ϕ}\{f\_{\phi}\}. Recent theoretical and mechanistic studies have shown that, in controlled settings, the fast state ϕ_θ(D_k)\phi\_{\theta}(D\_{k}) closely matches the output of explicit learning algorithms such as least squares or gradient descent on a task-specific inner objective; in this sense, ICL learning happens in activations rather than through online updates of θ\theta.

Putting these pieces together, our framework unifies SFT, KL-regularized RL, and few-shot ICL at the level of target posteriors and first-order updates: all three aim to approximate a Bayes or Gibbs posterior, and their gradients can be written as weighted score sums of the form (65). At the same time, the origin and granularity of the learning signal differ:

  • •

    SFT observes dense token-level supervision: every prefix (x,y_≤i)(x,y\_{\leq i}) has an explicit label y_i+1y\_{i+1}, and credit assignment is implicit in the data.

  • •

    KL-regularized RL starts from sparse sequence- or trajectory-level rewards R(y)R(y); it must perform explicit credit assignment via Q/AQ/A estimates, but the resulting policy update is an advantage- or reward-weighted SFT step.

  • •

    Few-shot ICL relies on dense supervision during pretraining to learn θ\theta as a meta-learner; at test time, it performs task-specific adaptation in the forward activations ϕ_θ(D_k)\phi\_{\theta}(D\_{k}) without additional gradients.

In this sense, our claimed equivalences are intentionally restricted to the level of objectives (posterior distributions) and update forms. They do not erase the very real differences in how SFT, RL, and ICL acquire and use their learning signals—differences which have important implications for sample efficiency, stability, and the kinds of structure (e.g., credit assignment and reasoning) each paradigm can readily capture.

Part V: Implications for Reasoning Models and Training Recipes

Section titled “Part V: Implications for Reasoning Models and Training Recipes”

5.1 Posterior design and practical RLHF/RLVR recipes

Section titled “5.1 Posterior design and practical RLHF/RLVR recipes”

Parts II and IV showed that a broad class of KL-regularized RLHF/RLVR objectives admits a Gibbs-posterior optimum q_Gibbs(y∣x)∝π_ref(y∣x)exp⁡(R(y;D,x)/β)q\_{\mathrm{Gibbs}}(y\mid x)\propto\pi\_{\mathrm{ref}}(y\mid x)\exp(R(y;D,x)/\beta) and that reward- or advantage-weighted SFT is exactly the forward-KL projection of this posterior onto a parametric policy family. This matches a growing line of recent work that re-formulates RLHF as reward-weighted regression or weighted SFT rather than generic policy gradient [12, 9, 6, e.g.].

From our perspective, practical RLHF/RLVR pipelines can be viewed as two-step procedures:

    Posterior design. Choose a reference model π_ref\pi\_{\mathrm{ref}} and a reward or advantage signal RR, which together define a target Gibbs posterior q_Gibbs(y∣x)∝π_ref(y∣x)exp⁡(R(y;D,x)/β)q\_{\mathrm{Gibbs}}(y\mid x)\propto\pi\_{\mathrm{ref}}(y\mid x)\exp(R(y;D,x)/\beta).

    Projection. Fit a deployable policy π_θ\pi\_{\theta} by minimizing the forward KL KL(q_Gibbs∥π_θ)\mathrm{KL}(q\_{\mathrm{Gibbs}}\|\pi\_{\theta}), either directly via reward-/advantage-weighted SFT, or indirectly via a PPO-style optimizer that approximates the same projection.

This view identifies three concrete design knobs:

  • •

    Reward shaping as likelihood design. The reward RR enters only through exp⁡(R/β)\exp(R/\beta), so shifting and scaling RR correspond to changing the effective likelihood ratio between high- and low-quality outputs. Overly sharp or poorly calibrated rewards lead to posteriors with very low support overlap with π_ref\pi\_{\mathrm{ref}}, which our framework predicts to cause instability and over-optimization.

  • •

    Temperature β\beta as posterior concentration. Small β\beta produces a highly concentrated q_Gibbsq\_{\mathrm{Gibbs}} that strongly prefers top-reward outputs; large β\beta keeps q_Gibbsq\_{\mathrm{Gibbs}} close to π_ref\pi\_{\mathrm{ref}}. In our KL-projection picture, β\beta controls how much the optimizer is allowed to move the policy away from the reference model before running into support-mismatch issues.

  • •

    Offline vs on-policy projection. When rollouts come from π_ref\pi\_{\mathrm{ref}} or an early-stage model, the reward-weighted SFT losses in Parts II and IV implement an off-policy projection to the Gibbs posterior. PPO-style RLHF instead approximates the same target distribution with on-policy samples. Our analysis suggests that both are instances of the same forward-KL projection, but they trade off exploration (on-policy) against stability and reuse of pre-generated data (offline or replay-based).

Our KL-projection view also clarifies why recent pipelines based on on-policy distillation and iterative self-training almost always include a small supervised “cold start” phase before running high-variance on-policy updates.

Empirically, several lines of work report that purely on-policy optimization from a random or weakly aligned prior tends to fail: DeepSeek-R1 distinguishes a pure-RL variant (R1-Zero) that exhibits severe style and safety issues compared to the full R1 pipeline with a small SFT warm-up; on-policy distillation methods for language and vision-language models emphasize that a “cold-start alignment” of student and teacher distributions is essential for successful online training; and recent diffusion-model distillation methods similarly cast reward-guided fine-tuning as iteratively projecting onto soft-optimal policies rather than running unconstrained RL [7, 2, 4, 27, 24, e.g.].22 2 For an accessible engineering perspective on on-policy distillation for post-training, see the blog post by Lu and Lab [15].

In our framework, these observations are natural consequences of importance-weighted KL projection. Consider a target Gibbs posterior q_Gibbs(y∣x)∝π_ref(y∣x)exp⁡(R(y;D,x)/β)q\_{\mathrm{Gibbs}}(y\mid x)\propto\pi\_{\mathrm{ref}}(y\mid x)\exp(R(y;D,x)/\beta) and a sampling distribution μ(y∣x)\mu(y\mid x) used to generate candidate outputs. The classical effective sample size of the importance weights [10], w(y)∝q_Gibbs(y∣x)μ(y∣x),ESS=(∑_yw(y))2∑_yw(y)2,w(y)\propto\tfrac{q\_{\mathrm{Gibbs}}(y\mid x)}{\mu(y\mid x)},\qquad\mathrm{ESS}=\frac{\big(\sum\_{y}w(y)\big)^{2}}{\sum\_{y}w(y)^{2}}, collapses when the support of μ\mu has little overlap with the high-reward region under q_Gibbsq\_{\mathrm{Gibbs}}. In that regime, both off-policy reward-weighted SFT and on-policy distillation degenerate: most samples receive negligible weight, and the few high-weight samples lead to unstable gradients.

A small SFT or behavior-cloning warm-up can be understood as moving π_ref\pi\_{\mathrm{ref}} (or the student policy) into the high-reward region so that μ\mu and q_Gibbsq\_{\mathrm{Gibbs}} have non-trivial overlap. On-policy distillation steps then refine the policy by repeatedly projecting the current Gibbs-approximate teacher onto the student family via forward-KL, as in Parts II and III, but now in a regime where the importance weights have reasonable variance. Our framework thus predicts a theoretical necessity of cold start for OPD-style pipelines: without sufficient support overlap, Gibbs-posterior projection is not statistically feasible, regardless of the specific optimizer used.

Recent work on reward-guided fine-tuning of diffusion models adopts an almost identical recipe: simulate soft-optimal policies under a reward, then distill them via KL minimization into the base diffusion model [24]. From our perspective, these methods are simply applying the same Gibbs-posterior projection principle to non-autoregressive generative models.

5.3 Compute allocation and reasoning models

Section titled “5.3 Compute allocation and reasoning models”

Our analysis so far has been distributional and first-order: SFT, KL-regularized RL, and reward-weighted ICL all aim to approximate a (common) Bayes or Gibbs posterior, and their updates share the same weighted-score form. An orthogonal, but increasingly important, dimension in contemporary systems is how compute is allocated between training time and inference time.

Recent “reasoning models” such as DeepSeek-R1 and OpenAI’s o1 family explicitly scale inference-time compute via long chain-of-thought traces, multi-sample search, or tree-style exploration [7, 18, 11]. At a high level, these models combine two regimes:

  • •

    Test-time inference (ICL / search). Given a fixed base policy, the model spends substantial compute per query to explore alternative reasoning paths and approximate a task-specific posterior over solutions.

  • •

    Training-time amortization (RL / OPD / SFT). RLHF, RLVR, and on-policy distillation stages then amortize this search by projecting the high-reward posterior (often defined over multi-step chain-of-thoughts) back into the base model’s weights via KL-regularized updates.

DeepSeek-R1 and related work report a somewhat surprising empirical finding: few-shot prompting often does not improve, and can even degrade, the performance of heavily RL-tuned reasoning models [7]. In our framework, this can be understood as a mismatch between the posterior that the model has been trained to amortize and the posterior implicitly defined by few-shot prompts.

During RLHF/RLVR-style training, the model is typically optimized to approximate a Gibbs posterior q_Gibbs(y∣x)q\_{\mathrm{Gibbs}}(y\mid x) under a distribution of zero-shot or lightly-structured prompts xx. In contrast, few-shot prompting at inference time replaces xx by a richer context (D_k,x)(D\_{k},x) and implicitly targets a different posterior P_Bayes(y∣x,D_k)P\_{\mathrm{Bayes}}(y\mid x,D\_{k}), as in Part I. Unless the model has been meta-trained to perform reward-weighted ICL (RW-ICL) over such contexts, the learned mapping (D_k,x)↦M_θ(⋅∣x,D_k)(D\_{k},x)\mapsto M\_{\theta}(\cdot\mid x,D\_{k}) need not approximate the desired posterior, and the additional context can act as distribution shift rather than useful information.

From this perspective, few-shot prompting “fails” on some reasoning models not because ICL is inherently weaker than RL, but because the posterior level has changed (from token-level q_Gibbs(y∣x)q\_{\mathrm{Gibbs}}(y\mid x) to in-context q_Gibbs(y∣x,D_k)q\_{\mathrm{Gibbs}}(y\mid x,D\_{k})) without a corresponding change in the training objective. Our RW-ICL formulation suggests a natural remedy: if one wants RL-tuned models to benefit from few-shot prompts, the reward signal should be defined at the contextual level R(y;D_k,x)R(y;D\_{k},x) and the meta-objective should directly train M_θM\_{\theta} to approximate the corresponding Gibbs posterior q_Gibbs(⋅∣x,D_k)q\_{\mathrm{Gibbs}}(\cdot\mid x,D\_{k}).

The Bayesian/KL framework suggests that “System 2” reasoning via test-time search and ICL, and “System 1” behavior via amortized RL/SFT, are two ways of paying for the same posterior: either spend more compute per query to approximate it explicitly, or invest more training compute to bake it into the weights. Reasoning models such as DeepSeek-R1 and o1 can be viewed as deliberately combining both, using inference-time compute to explore high-reward regions of the posterior and training-time KL projection (via RLHF/RLVR/OPD) to amortize the resulting distributions into a fast at-test-time policy.

Before concluding, we report a set of experiments on real models under matched budgets (every operator receives the same generation and optimization budget). The equivalences of Parts I–V are formal statements about objectives and first-order updates, but the framework also carries falsifiable empirical content, and we check two implications of it. Concretely, we ask whether (i) when the projection enjoys good support overlap, operators that the framework places on the same footing produce nearly identical updates, and the agreement collapses once support degrades; and (ii) a reward-weighted projection objective is at least competitive with its unweighted counterpart under a matched budget. The experiments span three operator families (SFT, KL-regularized RL, and reward-weighted context distillation) and student and teacher models of two sizes (Qwen3-4B and Qwen3-14B), with three seeds for the operator-agreement study.

E.1 Operator agreement under matched support

Section titled “E.1 Operator agreement under matched support”

Parts II and IV predict that, when the Gibbs posterior q_Gibbsq\_{\mathrm{Gibbs}} has good support overlap with the sampling distribution, a PPO-style clipped operator and a standard group-relative policy-gradient operator (GRPO) [16] approximate the same forward-KL projection and should produce nearly identical first-order updates. Using a Qwen3-4B base/instruct model pair under a matched generation budget, we construct two regimes by varying only the sampling proposal: a stable regime where the proposal is anchored to the reference model (anchor mixing coefficient 1.01.0, sampling temperature 0.70.7), and a stress regime without anchoring (coefficient 0.00.0, same temperature), which degrades the overlap between proposal and target by construction. Over three seeds (Table 1), agreement between PPO and GRPO, two operators that share the same sequence-level reward signal, is essentially perfect in the stable regime (cos⁡≈1.000\cos\approx 1.000 on all three seeds) and collapses once support degrades (0.1070.107–0.3580.358). The reward-weighted SFT direction is genuinely different even in the stable regime (cos⁡\cos between 0.10.1 and 0.20.2) and becomes erratic under stress (including negative cosines). This mirrors the granularity distinction of Section 4.4: weighted SFT realizes a token-level amortized projection rather than a sequence-level policy-gradient step, and the framework claims equivalence of targets and update forms, not identity of update directions across signal granularities. Agreement is computed on the last two transformer layers.

Table 1: Cosine similarity between update directions under matched generation budget (Qwen3-4B; last two layers only; seeds 42–44). Stable: proposal anchored to the reference model; stress: unanchored proposal.

RegimeSeedcos⁡(PPO,GRPO)\cos(\mathrm{PPO},\mathrm{GRPO})cos⁡(GRPO,RW-SFT)\cos(\mathrm{GRPO},\mathrm{RW\text{-}SFT})
stable421.0000.2030.203
stable431.0000.1060.106
stable441.0000.2030.203
stress420.1070.4410.441
stress430.219−0.477-0.477
stress440.358−0.430-0.430

E.2 Cold-start failure and rescue (controlled demonstration)

Section titled “E.2 Cold-start failure and rescue (controlled demonstration)”

Section 5.2 predicts that importance-weighted KL projection is not statistically feasible without support overlap, regardless of the optimizer. We construct a controlled demonstration with a Qwen3-4B student on a slice of a public 17K-prompt verifiable math dataset (DAPO-Math-17K). Holding the warm-start initialization and training budget fixed, we change only the generation contract (Table 2). Under the original contract the rollout reward signal is effectively dead: raw reward sum =3.0=3.0, and 99.2%99.2\% of prompt groups have zero reward variance, so any importance-weighted update receives no signal. After fixing the contract (disabling thinking mode, generation budget raised to 2048 tokens), the raw reward sum rises to 181.0181.0, the zero-signal fraction drops to 0.600.60, and parse success reaches 0.8460.846. The failure was a property of the support/signal interface, not of the projection operator — exactly the cold-start argument of Part V.

Table 2: Same initialization and training budget; only the generation contract differs (DAPO-Math-17K slice, Qwen3-4B).

Generation contractraw reward sumzero-signal group frac.parse success
original (thinking on, 1024 tokens)3.03.00.9920.9920.0060.006
fixed (thinking off, 2048 tokens)181.0181.00.6020.6020.8460.846

E.3 Reward-weighted projection vs. standard operators (matched budget)

Section titled “E.3 Reward-weighted projection vs. standard operators (matched budget)”

Finally, implication (ii): the reward-weighted projection of Parts II–III should be at least competitive with unweighted SFT and with KL-regularized RL under a matched budget. A Qwen3-4B student (teacher-bridge warm-start initialization) is trained on a DAPO-Math-17K slice (train 2000 / val 1000 / test 500) with a Qwen3-14B teacher, and all variants are evaluated under one contract (256 validation prompts, max_new_tokens =3072=3072). Table 3 reports accuracy. Reward-weighted context distillation — a direct on-policy implementation of the RW-ICL objective of Part III — scores 106106 of 256256, ahead of answer-only SFT (100100) and GRPO (9797). The paired bootstrap 95% interval for the gap between the reward-weighted model and the strongest standard baseline spans [−5.5,+6.25][-5.5,+6.25] accuracy points: at this evaluation scale the operators are statistically indistinguishable, and the reward-weighted objective performs on par with the standard operators it is theoretically tied to. A second probe at a larger generation budget (8192 tokens, 64 prompts) preserves the ordering (reward-weighted 24/6424/64, SFT 23/6423/64, warm-start and GRPO 22/6422/64, base 18/6418/64), and the reward-weighted model is the only one whose extracted answers are strictly stable within 4096 tokens, while the completed baselines require 8192.

Table 3: Matched-budget comparison on the 256-prompt validation slice (Qwen3-4B student, Qwen3-14B teacher, DAPO-Math-17K).

Model / operatoraccuracy (/256)
Qwen3-4B base8383 (0.3240.324)
warm-start (teacher bridge)9191 (0.3550.355)
GRPO (KL-regularized RL)9797 (0.3790.379)
SFT (answer-only)100100 (0.3910.391)
reward-weighted context distillation106106 (0.4140.414)

All experiments use the Qwen3 model family: E.1 uses three seeds and E.2–E.3 one; E.3 evaluates on 256 validation prompts, and operator agreement in E.1 is measured on the last two transformer layers. The section characterizes the mechanism-level behavior of post-training operators that the framework predicts, rather than benchmark-scale improvements.

Combining Parts I-IV, we obtain the following Bayesian chain:

  • •

    Few-shot ICL (Bayesian view). Under a hierarchical task model, the Bayes-optimal in-context predictor is the posterior predictive P_Bayes(y∣x_k+1,D_k)P\_{\mathrm{Bayes}}(y\mid x\_{k+1},D\_{k}). A sufficiently expressive Transformer trained on many tasks approximates this predictor in an amortized way.

  • •

    Generalized Bayes and KL-regularized RL. KL-regularized RLHF/RLVR defines a Gibbs posterior over outputs q_Gibbs(y∣x,D)∝π_ref(y∣x)exp⁡(R(y;D,x)/β),q\_{\mathrm{Gibbs}}(y\mid x,D)\propto\pi\_{\mathrm{ref}}(y\mid x)\exp(R(y;D,x)/\beta), where RR is a reward or advantage signal.

  • •

    Reward-weighted SFT / AWSFT. Reward-weighted SFT (for single-step problems) and advantage-weighted SFT (for RL) are exactly the forward KL projections of these Gibbs posteriors onto the parametric model family {p_θ}\{p\_{\theta}\} or {π_θ}\{\pi\_{\theta}\}.

  • •

    Reward-weighted ICL (RW-ICL). Meta-training a Transformer with reward-weighted in-context objectives makes its predictions M_θ(⋅∣x,D)M\_{\theta}(\cdot\mid x,D) approximate the same Gibbs posteriors q_Gibbs(⋅∣x,D)q\_{\mathrm{Gibbs}}(\cdot\mid x,D) in an amortized fashion.

In summary,

(i) Few-shot ICL  ≈  (unweighted) in-context SFT as a forward-KL/MLE projection onto P_Bayes,\displaystyle\text{(i) Few-shot ICL}\;\approx\;\text{(unweighted) in-context SFT as a forward-KL/MLE projection onto }P\_{\mathrm{Bayes}},(72)
------------
(ii) Reward-weighted ICL (RW-ICL)  ≈  reward/advantage-weighted in-context SFT,\displaystyle\text{(ii) Reward-weighted ICL (RW-ICL)}\;\approx\;\text{reward/advantage-weighted in-context SFT},(73)
------------
(iii) KL-regularized RLHF/RLVR  ≃  reward-weighted SFT on the corresponding Gibbs posterior.\displaystyle\text{(iii) KL-regularized RLHF/RLVR}\;\simeq\;\text{reward-weighted SFT on the corresponding Gibbs posterior.}(74)

Here, “≈\approx” is intended in an idealized sense at two levels: at the distribution level, as forward-KL projections onto the same posterior (Bayes or Gibbs) under our modeling assumptions; and at the first-order optimization level, as stochastic-gradient updates of the same weighted-score form described in Section 3.2. It does not claim that the corresponding practical algorithms are identical beyond these aspects.

This equivalence is deliberately confined to objectives and update forms. The source and granularity of the learning signal remain genuinely different across paradigms. Supervised fine-tuning observes dense token-level supervision from mappings (x,y_≤i)↦y_i+1(x,y\_{\leq i})\mapsto y\_{i+1}; KL-regularized RL begins with sparse sequence- or trajectory-level rewards and must perform explicit credit assignment via value/advantage estimation before reducing to an advantage-weighted SFT update; and few-shot ICL reuses dense supervision in pretraining to learn a meta-learner θ\theta, but performs task-specific adaptation at test time in the forward activations rather than via additional gradients. Our framework reconciles these methods at the level of their posterior targets and first-order dynamics, while leaving room for these process-level differences to drive distinct sample-efficiency and stability trade-offs in practice.

All of these procedures are different faces of the same underlying mechanism: a (possibly generalized) Bayesian update of a reference model that produces a target posterior (either the true Bayes posterior P_BayesP\_{\mathrm{Bayes}} or a designed Gibbs posterior q_Gibbsq\_{\mathrm{Gibbs}}), followed by a forward-KL (MLE) projection onto the parameterized policy family. Meta-learning / first-order interpretations (ICL ≈\approx one-step SFT / AWSFT) can then be seen as algorithmic realizations of these projection steps and are best viewed as complementary to the Bayesian backbone developed here.

From an information-design perspective, vanilla SFT passively assumes that the data source already supplies the optimal information structure (the true posterior q_trueq\_{\mathrm{true}}). RLHF/RLVR first designs a target posterior q_Gibbsq\_{\mathrm{Gibbs}} via the choice of reward RR and temperature β\beta, and then performs the same forward-KL/MLE projection as in SFT. In this sense, RLHF is SFT on a designed information structure: the optimization remains maximum likelihood, but the posterior being fit has been engineered to encode the desired incentives.

The experiments of the preceding section corroborate this picture at the mechanism level: operators that share their learning-signal granularity coincide almost exactly when support is good and diverge when it degrades; cold-start failure appears as a support phenomenon rather than an optimizer failure; and reward-weighted projection performs on par with its unweighted counterpart under a matched budget.

Appendix A: Bayesian ICL Results Used in the Main Text

Section titled “Appendix A: Bayesian ICL Results Used in the Main Text”

This appendix summarizes the key theoretical results from recent work on Bayesian views of in-context learning that we rely on in Part I: Wakayama and Suzuki [25] and Reuter et al. [23]. We only state what is needed for our arguments; full technical details and proofs are in the original papers.

A.1 Risk decomposition and non-asymptotic bounds (Wakayama & Suzuki)

Section titled “A.1 Risk decomposition and non-asymptotic bounds (Wakayama & Suzuki)”

Wakayama and Suzuki [25] formalize a hierarchical prompt-generating process over tasks and show that the in-context learning (ICL) risk admits an exact orthogonal decomposition under squared loss. Let MM be any in-context predictor (not necessarily a Transformer), and let R(M)R(M) denote its expected ICL risk under their meta-distribution. Then

R(M)=R_BG(M)+R_PV,R(M)=R\_{\mathrm{BG}}(M)+R\_{\mathrm{PV}},(75)

where:

  • •

    R_BG(M)R\_{\mathrm{BG}}(M) is the Bayes Gap: an excess-risk term measuring how far MM is from the Bayes-optimal in-context predictor M_BayesM\_{\mathrm{Bayes}};

  • •

    R_PVR\_{\mathrm{PV}} is the Posterior Variance: an irreducible term depending only on the task distribution and context length, not on MM.

In particular, M_BayesM\_{\mathrm{Bayes}} is the unique minimizer of R(M)R(M), and R_PVR\_{\mathrm{PV}} captures the intrinsic task uncertainty. This is exactly the content we use in Theorem 1 in Part I: the Bayes posterior predictive is the normative target for in-context prediction, and any in-context learning algorithm is judged by its Bayes Gap R_BG(M)R\_{\mathrm{BG}}(M).

For a class of uniform-attention Transformers with feature dimension mm, context length pp and number of pretraining prompts NN, Wakayama and Suzuki [25] further provide a non-asymptotic upper bound of the form

E R_BG(M_θ^)  ≲  m−2αd_eff+O~ ⁣(mpN+1N),\mathbb{E}\,R\_{\mathrm{BG}}(M\_{\hat{\theta}})\;\lesssim\;m^{-\frac{2\alpha}{d\_{\mathrm{eff}}}}+\widetilde{O}\!\left(\frac{m}{pN}+\frac{1}{N}\right),(76)

where α∈(0,1]\alpha\in(0,1] is a Hölder exponent and d_effd\_{\mathrm{eff}} is an effective dimension of the data manifold. The first term is an approximation error controlled by mm, and the second term is a pretraining generalization error depending jointly on pp and NN.

They also analyze mixtures of task types and input-distribution shift, showing that:

  • •

    In mixed-task settings, the posterior over the task index concentrates quickly as the context grows, so the Bayes-optimal meta-algorithm rapidly specializes to the true task family.

  • •

    Under input-distribution shift between pretraining and inference, only the Bayes Gap increases, with an out-of-distribution penalty proportional to a Wasserstein distance between input distributions, while the posterior variance term is intrinsic to the target domain.

We do not need these bounds explicitly, but they support our assumption in Sec. 1.3 that a sufficiently expressive Transformer, trained on many tasks, can approximate M_BayesM\_{\mathrm{Bayes}} up to a small Bayes Gap in the regimes of interest.

A.2 Transformers as amortized Bayesian inference (Reuter et al.)

Section titled “A.2 Transformers as amortized Bayesian inference (Reuter et al.)”

Reuter et al. [23] study whether in-context Transformers can approximate full Bayesian posterior inference over latent variables.

They construct several synthetic scenarios (generalized linear models, Gaussian mixture models, etc.) where the ground-truth posterior over latents is available via high-quality MCMC, and then:

  • •

    Train an in-context learner M_θM\_{\theta} that maps each dataset DD to a predictive distribution (or posterior sampler) over latent variables and responses.

  • •

    Compare the distribution of samples from M_θM\_{\theta} with those from gold-standard Bayesian methods (e.g., HMC, SGLD, variational approximations) using metrics such as C2ST, MMD, Wasserstein distance, and RMSE.

  • •

    Investigate robustness under distribution shift between training and test datasets, showing that the in-context learner often remains close to the Bayesian baseline in out-of-distribution regimes.

They find that suitably trained Transformers can act as strong amortized Bayesian inference engines in context, often matching or approaching fully Bayesian baselines on both synthetic and real-world datasets, and sometimes outperforming classical approximate methods in certain distributional metrics.

This provides empirical support for the assumption used in Sec. 1.3 that a sufficiently expressive Transformer, trained on many tasks, can approximate the Bayes posterior predictive P_Bayes(y∣x,D_k)P\_{\mathrm{Bayes}}(y\mid x,D\_{k}) via a single forward pass M_θ(y∣x,D_k)M\_{\theta}(y\mid x,D\_{k}).

A.3 Relation to the main text (and to meta-learning views)

Section titled “A.3 Relation to the main text (and to meta-learning views)”

In the main body of this note:

  • •

    Part I uses Wakayama and Suzuki [25] to justify that the Bayes posterior predictive is the canonical target for in-context prediction, and that ICL risk decomposes into a Bayes Gap plus an irreducible posterior-variance term.

  • •

    The amortized-inference perspective in Sec. 1.3 and the statement that a single Transformer forward pass can approximate a dataset-level Bayesian posterior are motivated by Reuter et al. [23].

We do not reproduce the gradient-based/meta-learning derivations in this appendix. Instead, we refer to Akyürek et al. [3], Dai et al. [5], and Li et al. [14] for rigorous analyses showing that, in linear and linearized regimes, Transformers can implement one-step gradient updates in their forward passes and that attention has an algebraic dual representation as accumulated gradient corrections. In our view, those results are best interpreted as algorithmic realizations of the Bayesian predictor described in Parts I–III, rather than as the primary conceptual foundation.

A.4 Task–prior representation under within-task exchangeability

Section titled “A.4 Task–prior representation under within-task exchangeability”

In Part I (Section 1.2), we adopted the hierarchical task–prior model

f∼P(f),(x,y)∣f∼p_f(x,y)f\sim P(f),\qquad(x,y)\mid f\sim p\_{f}(x,y)

to formalize few-shot in-context learning as Bayes posterior prediction over tasks. In this appendix, we justify that such a hierarchical representation is a canonical consequence of a much weaker and more intuitive assumption on within-task data: exchangeability. Throughout, exchangeability is an assumption on the data-generating process within a task episode, not on any particular neural architecture used to implement in-context learning.

We first recall the notion of exchangeability and then invoke a classical representation theorem of de Finetti–Hewitt–Savage to obtain the hierarchical model used in the main text.

Let X\mathcal{X} be the input space and Y\mathcal{Y} the output space (e.g., labels or next tokens). Define the sample space Z:=X×Y\mathcal{Z}:=\mathcal{X}\times\mathcal{Y}. We consider sequences

Z_i=(X_i,Y_i)∈Z,i=1,2,…Z\_{i}=(X\_{i},Y\_{i})\in\mathcal{Z},\qquad i=1,2,\dots

generated under a single “task episode”.

Definition A.4.1 (Finite and infinite exchangeability). A finite sequence Z_1,…,Z_nZ\_{1},\dots,Z\_{n} is exchangeable if for every permutation π\pi of {1,…,n}\{1,\dots,n\},

(Z_1,…,Z_n)=d(Z_π(1),…,Z_π(n)),(Z\_{1},\dots,Z\_{n})\stackrel{{\scriptstyle d}}{{=}}(Z\_{\pi(1)},\dots,Z\_{\pi(n)}),

i.e., its joint distribution is invariant under any reordering of the indices.

An infinite sequence (Z_i)_i≥1(Z\_{i})\_{i\geq 1} is exchangeable if for every n≥1n\geq 1, the finite prefix (Z_1,…,Z_n)(Z\_{1},\dots,Z\_{n}) is exchangeable.

Intuitively, for an exchangeable sequence, only the multiset {Z_1,…,Z_n}\{Z\_{1},\dots,Z\_{n}\} matters, not the order. This is a standard formalization of “order-invariant” data within a task. Note that i.i.d. sequences are a special case of exchangeable sequences, but exchangeability is strictly weaker.

In our setting, we model each task episode as inducing an exchangeable sequence of sample pairs:

Assumption A.4.2 (Within-task exchangeability). For each task episode, the (conceptual) infinite sequence of observations (Z_i)_i≥1=(X_i,Y_i)_i≥1(Z\_{i})\_{i\geq 1}=(X\_{i},Y\_{i})\_{i\geq 1} taking values in Z=X×Y\mathcal{Z}=\mathcal{X}\times\mathcal{Y} is exchangeable.

In practice, we only ever observe a finite dataset D_k={(x_i,y_i)}_i=1kD\_{k}=\{(x\_{i},y\_{i})\}\_{i=1}^{k}, but we assume it arises as a finite prefix of such an exchangeable sequence. This is the usual idealization used in probability theory: we posit that, if we were to continue sampling from the same task, the joint law of the extended sequence would remain exchangeable.

A.4.2 A de Finetti–Hewitt–Savage representation.

Section titled “A.4.2 A de Finetti–Hewitt–Savage representation.”

The sample space Z=X×Y\mathcal{Z}=\mathcal{X}\times\mathcal{Y} is a standard Borel space in typical supervised learning settings (e.g., X,Y\mathcal{X},\mathcal{Y} finite or subsets of Rd\mathbb{R}^{d}), so we can invoke the general form of de Finetti’s representation theorem as extended by Hewitt and Savage.

We state an informal version sufficient for our purposes.

Theorem A.4.3 (de Finetti–Hewitt–Savage representation; informal). Let (Z_i)_i≥1(Z\_{i})\_{i\geq 1} be an infinite exchangeable sequence of random variables taking values in a standard Borel space Z\mathcal{Z}. Then there exists a random probability measure μ\mu on Z\mathcal{Z} (a random element of P(Z)\mathcal{P}(\mathcal{Z})) such that, conditional on μ\mu, the sequence is i.i.d. with common distribution μ\mu:

(Z_i)_i≥1∣μ  i.i.d.∼μ,μ∼Π,(Z\_{i})\_{i\geq 1}\mid\mu\;\text{i.i.d.}\sim\mu,\qquad\mu\sim\Pi,

for some probability law Π\Pi on P(Z)\mathcal{P}(\mathcal{Z}). Moreover, the mixing law Π\Pi is unique.

Equivalently, the joint law of (Z_i)_i≥1(Z\_{i})\_{i\geq 1} can be written as a mixture of i.i.d. sequences.

The original versions of this theorem were proved by de Finetti for Bernoulli sequences and generalized by Hewitt, Savage, and many others to arbitrary standard Borel spaces; see, e.g., standard modern references in probability theory for precise statements and proofs.

Under Assumption A.4.2, the sequence (Z_i)(Z\_{i}) generated by a given task episode satisfies the hypotheses of Theorem A.4.3, and hence admits such a mixture-of-i.i.d. representation.

A.4.3 From a random measure to a task prior.

Section titled “A.4.3 From a random measure to a task prior.”

We now reinterpret the random measure μ\mu from Theorem A.4.3 as a task, and its mixing distribution Π\Pi as a task prior P(f)P(f).

Let F:=P(Z)\mathcal{F}:=\mathcal{P}(\mathcal{Z}) denote the space of all probability measures on Z\mathcal{Z}, equipped with the σ\sigma-algebra generated by the usual weak topology. For each realization μ∈F\mu\in\mathcal{F}, define the joint law on Z\mathcal{Z} by

p_μ(z):=μ({z}),z∈Z,p\_{\mu}(z):=\mu(\{z\}),\qquad z\in\mathcal{Z},

or more generally p_μ(z)p\_{\mu}(z) as the Radon–Nikodym density of μ\mu with respect to a suitable base measure if Z\mathcal{Z} is continuous.

We introduce the following identification:

  • •

    Tasks. Each realization of μ\mu is interpreted as a task f∈Ff\in\mathcal{F}, with joint law p_f(x,y)p\_{f}(x,y) over X×Y\mathcal{X}\times\mathcal{Y};

  • •

    Task prior. The mixing law Π\Pi over μ\mu is renamed as a prior P(f)P(f) over tasks.

Under this identification, Theorem A.4.3 can be restated as:

There exists a random task f∼P(f)f\sim P(f) and a conditional distribution (X_i,Y_i)∣f∼p_f(x,y)(X\_{i},Y\_{i})\mid f\sim p\_{f}(x,y) such that, for each task episode, the joint law of (Z_i)_i≥1=(X_i,Y_i)_i≥1(Z\_{i})\_{i\geq 1}=(X\_{i},Y\_{i})\_{i\geq 1} is the same as that of an i.i.d. sequence drawn from p_fp\_{f}.

Formally, we obtain the hierarchical representation:

f∼P(f),(X_i,Y_i)_i≥1∣f i.i.d.∼p_f(x,y).f\sim P(f),\qquad(X\_{i},Y\_{i})\_{i\geq 1}\mid f\ \text{i.i.d.}\sim p\_{f}(x,y).

This is exactly the task–prior generative model used in Section 1.2 and the main Bayesian ICL analysis.

For supervised tasks, it is often convenient to factor p_f(x,y)p\_{f}(x,y) as

p_f(x,y)=p_f(x) p_f(y∣x),p\_{f}(x,y)=p\_{f}(x)\,p\_{f}(y\mid x),

and to interpret ff primarily via its conditional component p_f(y∣x)p\_{f}(y\mid x). In that case, we may succinctly write f:X→Δ(Y)f:\mathcal{X}\to\Delta(\mathcal{Y}), with P(f)P(f) a prior over such conditional task functions, as in the main text.

We summarize this as a proposition:

Proposition A.4.4 (Task–prior representation under exchangeability). Suppose that, for each task episode, the within-task observation sequence (X_i,Y_i)_i≥1(X\_{i},Y\_{i})\_{i\geq 1} taking values in X×Y\mathcal{X}\times\mathcal{Y} is infinite and exchangeable (Assumption A.4.2). Then there exists a task space F\mathcal{F} and a prior P(f)P(f) over F\mathcal{F} such that the joint distribution over data induced by a task episode admits the hierarchical representation

f∼P(f),(X_i,Y_i)∣f i.i.d.∼p_f(x,y).f\sim P(f),\qquad(X\_{i},Y\_{i})\mid f\ \text{i.i.d.}\sim p\_{f}(x,y).

In particular, the existence of a task prior P(f)P(f) is not an additional modeling assumption beyond within-task exchangeability; it is a canonical hierarchical reparameterization of the same joint law guaranteed by the de Finetti–Hewitt–Savage theorem.

Proof sketch. Apply Theorem A.4.3 to the exchangeable sequence (Z_i)_i≥1=(X_i,Y_i)_i≥1(Z\_{i})\_{i\geq 1}=(X\_{i},Y\_{i})\_{i\geq 1} on Z=X×Y\mathcal{Z}=\mathcal{X}\times\mathcal{Y} to obtain a random measure μ\mu on Z\mathcal{Z} and a mixing law Π\Pi such that (Z_i)∣μ(Z\_{i})\mid\mu are i.i.d. with common distribution μ\mu, and μ∼Π\mu\sim\Pi. Define F:=P(Z)\mathcal{F}:=\mathcal{P}(\mathcal{Z}), identify each μ∈F\mu\in\mathcal{F} with a task ff, and set P(f):=ΠP(f):=\Pi. Let p_f(x,y)p\_{f}(x,y) denote the joint law induced by ff on X×Y\mathcal{X}\times\mathcal{Y}. Then

f∼P(f),(X_i,Y_i)∣f i.i.d.∼p_f(x,y)f\sim P(f),\qquad(X\_{i},Y\_{i})\mid f\ \text{i.i.d.}\sim p\_{f}(x,y)

is exactly the hierarchical generative process whose marginal law over (X_i,Y_i)_i≥1(X\_{i},Y\_{i})\_{i\geq 1} coincides with the original exchangeable sequence. □\square

(1) What is the real modeling assumption? Proposition A.4.4 shows that the only substantive structural assumption we make at the task level is within-task exchangeability (Assumption A.4.2). Given this, the existence of a hierarchical task prior P(f)P(f) is a representation theorem, not an extra ad hoc assumption.

(2) Finite sequences and approximate exchangeability. In practice, we only observe finite datasets D_k={(x_i,y_i)}_i=1kD\_{k}=\{(x\_{i},y\_{i})\}\_{i=1}^{k}. The infinite-sequence formulation assumes that these finite datasets can be extended to an infinite exchangeable sequence. There also exist “finite de Finetti” theorems which provide approximate mixture representations for finitely exchangeable sequences; we do not rely on their technical details here, but conceptually they support the view that approximately exchangeable finite datasets are well-approximated by such hierarchical models.

(3) Connection to Wakayama & Suzuki’s hierarchical model. Wakayama and Suzuki [14] start directly from a hierarchical task prior f∼P(f)f\sim P(f) and derive non-asymptotic generalization bounds and a Bayes-optimal ICL risk decomposition. Our use of de Finetti–type representations clarifies that this hierarchical structure is not arbitrary: it is the canonical form of the joint distribution under within-task exchangeability. This provides a principled foundation for adopting their model in Part I.

(4) Empirical plausibility. Whether within-task exchangeability is a good approximation for real pretraining corpora is ultimately an empirical question. In the main text, we view the task–prior model as an effective theory of the latent task structure in natural data and discuss experimental designs (e.g., shuffling document structure, mixing tasks within prompts) that can probe the degree to which such a model is appropriate.

(5) Order effects in practical in-context learners. Assumption A.4.2 and Proposition A.4.4 concern the joint law of within-task data (X_i,Y_i)_i≥1(X\_{i},Y\_{i})\_{i\geq 1} under an exchangeable data-generating process. Real transformer models process ordered prompts with positional embeddings, and the order of demonstrations can affect predictions (e.g., via position-dependent attention weights). As discussed in Section 1.2, we treat such order effects as implementation-level deviations from the exchangeable Bayes benchmark characterized here, rather than violations of the underlying exchangeability assumption.