A statistical-physics lens

当生成变成一种
可测的动力学

一个生活在特定 context 中的 LLM agent,如何在语义状态间移动?把它的转移通道量出来,再寻找组织这些转移的有效势。

真实 IdeaSearchFitter 数据拟合得到的三维势能 landscape
01

动机

02

理论

03

实验

04

应用

05

讨论

01 / MOTIVATION

定义语义状态,
并用 MCMC 测量通道。

同一个意思,可以由许多不同的 token 序列表达。要理解 agent 的行为,就要从逐 token 的生成概率走向语义状态。

ReAct
Yao et al., ICLR 2023
拼接轨迹执行工具追加观察任务 + 轨迹思考 + 行动PromptToolObservationTask + trajectoryThought + action
Reflexion
Shinn et al., NeurIPS 2023
取出反思评估打分写出反思存入记忆任务 + 反思记忆执行者尝试PromptEvaluatorReflectionMemoryTask + memoryActor trajectory
FunSearch
Romera-Paredes et al., Nature 2024
按分数采样运行打分写回程序库程序库写新程序SamplingEvaluatorDatabasePrograms databaseNew program
Voyager
Wang et al., TMLR 2024
提出任务检索技能执行代码自检存入技能库技能库 + 世界写代码CurriculumRetrievalExecutionCriticNew skillSkill library + worldNew code
状态State ffT(g←f)\mathcal{T}(g\leftarrow f)状态State ggT(h←g)\mathcal{T}(h\leftarrow g)状态State hhT(⋅←h)\mathcal{T}(\cdot\leftarrow h)⋯

智能体的一轮循环即状态空间上的一步马尔可夫转移;下一状态只依赖当前状态,转移概率为 T(g←f)\mathcal{T}(g\leftarrow f)。One turn of an agent loop is one Markov step on its state space: the next state depends only on the current one, with transition probability T(g←f)\mathcal{T}(g\leftarrow f).

蓝色是状态,金色是这一轮的主生成,灰色是框架中的其他步骤;步骤按原论文的顺序排列,英文版用原论文的术语。Blue: the state; gold: the turn’s main generation; grey: the framework’s other steps, in each paper’s own order and terms.
MICROSCOPIC DEFINITION

T\mathcal{T} 是一整束微观轨迹的概率之和T\mathcal{T} is the probability sum over a bundle of microscopic trajectories

固定环境 ccfixed context cc
01 / 同一个输入 f→xff \to x_f 由状态 ff 与固定 context 构造 promptBuild a prompt from state ff and the fixed context
LLM 逐 token 生成:不同序列,不同概率
02 / 通向同一个 gg 的微观轨迹02 / Microscopic trajectories reaching the same gg
03 / 汇总这些轨迹的概率
轨迹 y(1)y^{(1)}Trajectory y(1)y^{(1)}p1=pθ(y(1)∣xf)p_1 = p_\theta(y^{(1)}\mid x_f)
y1(1)y_1^{(1)}→y2(1)y_2^{(1)}→⋯→EOS
语义提取gg
轨迹 y(2)y^{(2)}Trajectory y(2)y^{(2)}p2=pθ(y(2)∣xf)p_2 = p_\theta(y^{(2)}\mid x_f)
y1(2)y_1^{(2)}→y2(2)y_2^{(2)}→⋯→EOS
语义提取gg
许多不同轨迹,同一个语义状态 gg T(g←f)=p1+p2+⋯\mathcal{T}(g\leftarrow f) = p_1 + p_2 + \cdots 把所有通向 gg 的轨迹概率相加Sum the probabilities of all trajectories reaching gg
沿一条轨迹:条件概率相乘
pθ(y∣xf)=∏t=1Lpθ(yt∣y<t,xf)p_\theta(y\mid x_f) = \prod_{t=1}^{L} p_\theta(y_t\mid y_{<t},x_f)
由所有能够实现 gg 的轨迹推出Collect all trajectories that realize gg
T(g←f)=∑y: state(y)=gpθ(y∣xf)\mathcal{T}(g\leftarrow f) = \sum_{y:\,\mathrm{state}(y)=g} p_\theta(y\mid x_f)

02 / THEORY

方向由终点组织,
再让低概率边显现。

后训练按终点重排转移的倾向,通向同一状态的各条路径因此朝同一方向倾斜。再为每条转移加入微弱返回,正逆概率的强弱比就成为有效描述的入口。Post-training reorders transition tendencies by their destination, so every path into the same state tilts the same way. Add a weak return to every transition, and the forward–reverse ratio becomes the entry point for an effective description.

A

假设 A:方向只看终点,与路径无关

美丽的贝加尔湖有许多儿子,
却只有一个女儿。

——俄罗斯传说 贝加尔湖与安加拉河

后训练重排的是状态之间转移的倾向,奖励 RR 刻画这种重排。常见的奖励只取决于转移落在哪里:多步推导与一步到位,只要到达同一个正确答案,得到的奖励相同。于是通向 gg 的每条路径都朝同一个方向倾斜,方向由终点决定。Post-training reorders the tendencies of transitions between states, and the reward RR describes this reordering. Common rewards depend only on where a transition lands: a multi-step and a one-step derivation of the same correct answer earn the same reward. Every path towards gg then tilts the same way, and the destination sets the direction.

从 f 经中介状态 h₁ 或 h₂ 到达 g:两条路径通向同一终点,方向由终点决定 f h1 h2 g 多条路径,同一方向Many paths, one direction 奖励由终点 g 决定Reward set by the end g
R(g←f)≈u(g)R(g\leftarrow f) \approx u(g)
B

假设 B:每条路径都带着概率返回边

我们所有探索的终点,
将是回到出发的地方。

——艾略特《四个四重奏 · 小吉丁》

语言模型按概率采样:主导方向之外,返回转移的概率小而非零。采样与语义的不确定性为每条主导转移配上一条微弱回边;在这项假设下,正逆概率比由有效势差组织。An LLM samples from a probability distribution: beyond the dominant direction, a return transition has a small but nonzero probability. Sampling and semantic uncertainty give every dominant transition a weak return edge; under this assumption, forward–reverse ratios are organized by effective potential differences.

两个状态 f 与 g:蓝色粗箭头从 f 指向 g,金色细箭头从 g 返回 f f g 主导转移 弱概率返回
log⁡T(g←f)T(f←g)=β [V(f)−V(g)]\log\frac{\mathcal{T}(g\leftarrow f)}{\mathcal{T}(f\leftarrow g)} = \beta\,[V(f)-V(g)]
SAMPLE DATA

从真实转移中取出主导方向骨架

真实数据结构
主导路径 概率返回边 状态编号对应一个实测状态

主导方向骨架 + 概率返回边

同一组通道的 T(g←f)\mathcal{T}(g\leftarrow f) · 按势能排序T(g←f)\mathcal{T}(g\leftarrow f) for the same channels · ordered by potential

蓝色主导方向与金色返回边来自同一组真实观测;右侧矩阵按势能排序。The blue dominant directions and gold return edges come from the same observations; the matrix on the right is ordered by potential.
条件自由能 FF 和有效势 VVConditional free energy FF and effective potential VV

FF:一整束轨迹的条件自由能FF: conditional free energy of a trajectory bundle

把序列 yy 的概率写成下面的能量形式。EθE_\theta 描述这条序列的有效能量,Zθ(xf)Z_\theta(x_f) 是所有可能输出的权重总和,用于归一化。Write the probability of sequence yy in the energy form below. EθE_\theta is the effective energy of the sequence; Zθ(xf)Z_\theta(x_f) is the total weight of all possible outputs and normalizes the distribution.

pθ(y∣xf)=e−Eθ(xf,y)Zθ(xf)p_\theta(y\mid x_f) = \frac{e^{-E_\theta(x_f,y)}}{Z_\theta(x_f)}

固定输入 ff,把所有通向 gg 的序列权重加起来,再取负对数,就是 F(g∣f)F(g\mid f)。它描述转移中的整体能量差。For fixed input ff, sum the weights of all sequences reaching gg and take the negative logarithm: this is F(g∣f)F(g\mid f), the aggregate energy difference of the transition.

F(g∣f)=−log⁡∑y: state(y)=ge−Eθ(xf,y)F(g\mid f) = -\log \sum_{y:\,\mathrm{state}(y)=g} e^{-E_\theta(x_f,y)}

FF 与 T\mathcal{T}:相差一个归一化项FF and T\mathcal{T}: separated by a normalization term

−log⁡T(g←f)=F(g∣f)+log⁡Zθ(xf)-\log \mathcal{T}(g\leftarrow f) = F(g\mid f) + \log Z_\theta(x_f)

对同一个输入 ff,F(g∣f)F(g\mid f) 越低,转移到 gg 的概率越高。但 FF 并非直接等同于 −log⁡T-\log \mathcal{T},还要计入输入对应的归一化项。For the same input ff, a lower F(g∣f)F(g\mid f) means a higher probability of reaching gg. But FF is not simply −log⁡T-\log \mathcal{T}; the input-dependent normalization term must also be included.

FF 与 VV:局部方向差由全局势组织FF and VV: local directional differences organized by a global potential

在细致平衡成立时,正逆通道的条件自由能之差满足:

F(f∣g)−F(g∣f)F(f\mid g) - F(g\mid f)=β [V(f)−V(g)]= \beta\,[V(f) - V(g)]+log⁡Zθ(xf)−log⁡Zθ(xg)+ \log Z_\theta(x_f) - \log Z_\theta(x_g)

右侧是同一个状态函数 βV+log⁡Zθ\beta V+\log Z_\theta 在 ff、gg 两点的差。这表明当条件自由能 FF 满足 exact 1-form 时,存在一个全局有效势 VV,可以用来描述系统的局部行为。这就是所假设条件的微观含义。The right-hand side is the difference of one state function, βV+log⁡Zθ\beta V+\log Z_\theta, evaluated at ff and gg. When the conditional free energy FF is an exact 1-form, a global effective potential VV exists to describe local behavior. This is the microscopic meaning of the assumption.

03 / EXPERIMENT

让真实的边,
决定势能的排序。

从排序算法中抽象出一个目标:寻找让转移更倾向于“向下”的势能排列。最小作用量把这个目标变成可优化的量。保留真实数据中的局部转移通道,让状态逐渐找到对应全局有效势,看作用量如何随之下降。

S[V]=1N∑f,gT(g←f) K(V(f)−V(g))\mathcal{S}[V] = \frac{1}{N}\sum_{f,g} \mathcal{T}(g\leftarrow f)\, K\big(V(f)-V(g)\big)

K(x)=log⁡(1+e−x)K(x)=\log\left(1+e^{-x}\right)
只更新 VV,不改动任何转移计数Update VV only; do not change any transition counts

RELAXATION ON IDEASEARCHFITTER

在真实通道上寻找势能

沿同一批真实状态与转移边更新势能;点沿势能方向移动,代表转移中势能下降的绿色边增多,作用量下降。

下降 V(g)<V(f)V(g)<V(f)Downhill V(g)<V(f)V(g)<V(f) 上升 V(g)>V(f)V(g)>V(f)Uphill V(g)>V(f)V(g)>V(f) 箭头指向下一状态 · 线宽随 T\mathcal{T} 增大Arrows point to the next state · width grows with T\mathcal{T}

点击节点查看状态表达式、采样数和势能。

作用量随迭代下降

全图作用量 𝒮 —
下降边 / 总边数 —
显示状态 / 拟合总状态 —

行是目标 gg,列是源 ff。按势能重新排列状态,深色表示更强的转移,上三角对应向低势能流动。观察转移的方向性在热图中显现。Rows are target gg and columns are source ff. Reorder states by potential; darker cells are stronger transitions, and the upper triangle corresponds to downhill flow.

点击格子查看转移概率 𝒯(g←f)。

每个点连接一对状态的势差与实测正逆概率比。优化只改变势差,观察点云如何向对角线靠拢。

点击点查看势差与实测正逆概率比。

LANDSCAPE ON IDEASEARCHFITTER

用MDS度量势能景观

打开可交互三维图 ↗︎

非度量 MDS 只保留图距离 δij\delta_{ij} 的排序,把状态嵌入一维坐标 yy:Non-metric MDS keeps only the rank order of graph distances δij\delta_{ij} and embeds the states on one coordinate yy:

min⁡y, φ∑i<j[φ(δij)−∣yi−yj∣]2\min_{y,\,\varphi} \sum_{i<j} \big[\varphi(\delta_{ij}) - |y_i - y_j|\big]^2其中 φ\varphi 单调with φ\varphi monotonic

其中

δij=min⁡p: i→j∑(u,v)∈p[−log⁡Auv]\delta_{ij} = \min_{p:\,i\to j} \sum_{(u,v)\in p} \big[-\log A_{uv}\big]Auv=12[T(v←u) σ(Vv−Vu)+T(u←v) σ(Vu−Vv)]\begin{aligned} A_{uv} = \tfrac{1}{2}\big[&\mathcal{T}(v\leftarrow u)\,\sigma(V_v-V_u)\\ &+ \mathcal{T}(u\leftarrow v)\,\sigma(V_u-V_v)\big]\end{aligned}

其中 σ(z)=1/(1+e−z)\sigma(z)=1/(1+e^{-z}) 是 logistic sigmoid。Here σ(z)=1/(1+e−z)\sigma(z)=1/(1+e^{-z}) is the logistic sigmoid.

因此状态相邻时 δ\delta 较小。梯度大表示转移方向性强,适合确定性任务;梯度小则更适合探索。粗糙度表示 agent 的特征运行周期:越粗糙,运行周期越长。Thus neighboring states have smaller δ\delta. Steep gradients indicate strongly directional transitions and suit deterministic tasks; shallow gradients suit exploration. Roughness represents the agent’s characteristic operating cycle: the rougher the landscape, the longer the operating cycle.

ROBUSTNESS ACROSS TASKS AND MODELS

跨越任务和时间检验理论

从表达式到单词与数字,切换任务,看同一条势差关系如何出现在不同的生成空间中。每个任务的 Pearson rr 都在该任务的全部合格双向状态对上计算。不同任务上模型均表现出向细致平衡的趋势。Switch from expressions to words and numbers to see the same potential-difference relation across generation spaces. Pearson rr is computed on every qualified bidirectional state pair in each task. The trend toward detailed balance appears across tasks.

任务势能形状。 横轴 yy 是非度量 MDS 坐标,纵轴 VV 是势能,每个任务只使用最大的一个连通分支。Task potential shape. The horizontal axis yy is the non-metric MDS coordinate, and the vertical axis VV is the potential; each task uses only its largest connected component.

04 / APPLICATION

从描述行为,
走向设计行为。

模型容易到达的地方,未必是任务需要的地方。若有效势描述满足稳态收敛条件,π(f)∝e−βV(f)\pi(f)\propto e^{-\beta V(f)}。通过加入目标偏置重塑稳态,可以让搜索更多地到达目标区域。Where a model easily goes is not necessarily where the task requires. When the effective-potential description admits a stationary limit, π(f)∝e−βV(f)\pi(f)\propto e^{-\beta V(f)}. An external target bias reshapes the stationary distribution and can steer search toward the target region.

识别原有偏好 V(f)V(f)
→
改变外部偏置 βV(f)−β target(f)\beta V(f) - \beta\,\mathrm{target}(f)
→
引导模型行为 πh(f)\pi_h(f)
SEARCH DYNAMICS ON IDEASEARCHFITTER

外部偏置如何把随机轨迹推向目标区域?

在给定的状态空间中,逐渐增加偏置的大小,观察一个迭代智能体在状态空间上游走的轨迹如何从原本的方向向外部偏置鼓励的方向漂移。

T=∞T=\infty
最低势能所在的 MSE 全图最低 MSE 当前偏置下轨迹可达的最低 MSE
探索阶段原有偏好
当前轨迹的最低 MSE—

05 / DISCUSSION

若干讨论,
非平衡效应、方法论和意义。

势能明确生成的主要结构,并指出如何修正;它把不同视角的研究连接起来。A potential makes the dominant structure of generation explicit and shows how to correct it; it connects several levels of description.

01
THE BOUNDARY

转移路径有环时的平衡态

同一祖先经两条路径抵达同一后继 f 经 h₁ 或 h₂ 到 g 的两条路径,每条边均可反向通过,构成正、逆闭环。闭环上的正逆权重之积,检验方向是否只由终点决定。 fh1h2g 双向闭环 比较正逆权重之积 Compare the products offorward and reverse weights
主导转移弱返回
多条路径构成双向闭环;闭环上可靠的非零环流为细致平衡的描述能力画出边界。Several paths form bidirectional cycles; a reliable nonzero circulation around them marks the boundary of a detailed-balance description.
同一祖先经不同路径抵达同一后继时,方向是否只由终点决定,可以直接检验:When the same ancestor reaches the same successor by different paths, whether the destination alone sets the direction can be tested directly: log⁡(P+/P−)=0,\log(P_+/P_-) = 0,就是待检验的零假设,其中正向一周的概率乘积为 P+P_+,逆向为 P−P_-。即:这些环上的正逆概率比,能否仍由同一个势能统一描述?is the null hypothesis to test. The forward cycle has probability product P+P_+ and the reverse cycle P−P_-. Can the forward–reverse ratio around these cycles still be unified by one potential?
正文闭环检验

在当前采样误差内,
尚不能拒绝正逆对称。

可靠的非零环流将标志着需要引入非平衡修正。A reliable nonzero circulation would mark the need for a nonequilibrium correction.

02
THE METHOD

微扰论的应用

先提取主导结构,把它推进到可解的极限,再用数据判断这个极限能否描述现实。Extract the dominant structure, push it to a solvable limit, and use data to test whether that limit describes reality.

  1. 识别主导结构

    从转移中看见结构

    语言模型的生成有倾向性,生成通道稀疏。

  2. 建立自洽描述 V ↓

    由正逆概率比定义势

    基于概率模型的本质给出最小描述。

  3. 检验现实情况

    在实际通道上检验势

    比较绕现实中多路径的正逆概率乘积,检验势能描述。

03
THE BRIDGE

向微观追溯,向宏观预测

如同热力学不追踪每个粒子而刻画宏观量,势能表示把完整输出的 token 序列构成的系综压缩为可测的宏观状态关系:向下可以追溯生成过程的 token 动力学,向上可以组织稳态、响应与搜索的设计。Just as thermodynamics does not track every particle but describes macroscopic quantities, the potential representation compresses the ensemble of complete token sequences into measurable macroscopic state relations: downward it traces token dynamics; upward it organizes stationary behavior, response, and search design.

微观生成

许多 token 轨迹

研究生成过程中 token 的微观动力学

桥梁T→V\mathcal{T} \to V

用全局势能表示组织局部状态转移

宏观行为

少数可检验的量

稳态 π\piStationary π\pi响应 χ\chiResponse χ\chi⋯

研究真实 agent 的宏观行为模式

VIDEO · BILIBILI视频讲解 ↗︎在 bilibili 观看这项工作的完整讲解