betaFeedback

WorksComputer Science

The Asymptotics of Language Model Alignment with Memory

Abstract

Language model (LM) alignment broadly aims to perturb a given LM QQ into an aligned LM qq such that i) the outputs produced by qq and QQ are 'close' in probability, ii) qq has a higher expected reward than QQ. Two common techniques for LM alignment are: KL-constrained RL, which requires knowledge of the LM distribution and is computationally expensive, and the best-of-nn algorithm, which requires only sampling from the LM. The work of Yang et al. established asymptotic closeness between the distributions produced by the two alignment methods for an mm–length i.i.d. token sequence output by the LM, in the limit as mm increases to infinity. However, the i.i.d. assumption is not representative of practical LMs, whose output sequences often have memory. In this paper, we extend the asymptotic closeness result to the case when the mm–length token sequence outputted by the LM is Markovian. Further, for finite-length output sequences – particularly, when m=1m=1 – we provide a complete characterization of LM distributions and reward functions for which the KL-divergence between the distributions produced by the two alignment methods is zero – a question first posed in Yang et al.

Introduction

Large Language Models (LLMs) have become a central paradigm for generating natural language text and LLM-based systems are increasingly being adopted in practice [2, 3, 4]. Given a prompt xx, an autoregressive LLM defines a conditional probability distribution P(⋅∣x)\mathbb{P}(\cdot|x) over output token sequences, with P(s∣x)\mathbb{P}(s|x) denoting the probability assigned to the response ss. LLMs are pretrained on large text corpora and may subsequently be adapted through task-specific fine-tuning or preference-based post-training [5, 6].

LLMs sometimes generate unrealistic and undesirable outputs. For instance, the outputs might contain factually incorrect information or reflect biases in the training data [5, 7]. Sometimes, more specific properties of the generated output text, including fluency, linguistic style, and the avoidance of undesirable repetition, are targeted to be improved [8, 9, 10, 11]. Desirable outputs are associated with a large ‘reward’ and undesirable outputs are associated with a small ‘reward’. It is thus desirable to perturb the LLM probability distribution to an aligned distribution that has a higher expected reward.

While several techniques for LLM alignment [6, 12, 13, 14, 15, 16, 17] exist in the literature, two of the most popular techniques, which are also grounded in theory, are i) KL-constrained reinforcement learning (RL), and ii) best-of-nn alignment. KL-constrained RL returns an aligned distribution (which we sometimes call the “KL-constrained RL distribution”) whose reward is maximized while ensuring that the KL-divergence between the reference LLM distribution, i.e., the LLM distribution before alignment, and the aligned LLM distribution is small. In best-of-nn alignment, the algorithm instead samples nn times from the reference LLM distribution, picking the maximum-reward output among nn outputs generated. Unlike KL-constrained RL that returns a deterministic, analytical solution, the best-of-nn alignment returns a random response, the distribution of which we simply call the “best-of-nn distribution”.

In the light of analytical results on the best-of-nn algorithm, the work of [1] establishes a connection between the KL-constrained RL and the best-of-nn distributions in the restricted setting where: i) the LLM generates sequences consisting of mm i.i.d. tokens as the response for each prompt, and ii) the reward of the length-mm sequence can be decomposed as the sum of the reward over individual tokens. Under these assumptions, the KL-constrained RL and the best-of-nn distributions, when n=Θ(exp⁡(m))n = \Theta(\exp(m)), are asymptotically close as mm grows to infinity. In other words, the optimal KL-constrained RL policy, which requires knowledge of the reference LLM distribution, is asymptotically close to the computationally efficient best-of-nn policy, which requires no such knowledge.

While the purpose of the two assumptions is to derive analytical connections between the two alignment methods for a simple, toy setting, the assumptions are not representative of the outputs of practical LLMs, which display a Markov dependence of responses conditioned on previous contexts [18]. An interesting question to ask, in this light, is: Is the connection between the two alignment methods a consequence of the i.i.d. nature of the tokens, or does it hold even in the presence of memory among outputs? A related question about removing i.i.d. LLM output assumption in [1] was posed in the same paper. We take up this question in our work, analyzing the setting of Markov LLM output distributions.

Furthermore, the work of [1 Section 5] also observed empirically that when the LLM distribution and the reward function are both randomly generated, the KL-divergence between the distributions produced by the two alignment methods is “small” even for “small” mm values, when the LLM outputs are i.i.d. A second question to be asked in this regard, also posed in [1] is: For small mm values, what LLM distributions and reward functions give rise to small KL-divergence between the distributions returned by the two alignment methods? In particular, what is the dependence of this KL-divergence on the vocabulary size? We spend the latter part of this paper providing partial progress on this question, when m=1m=1.

Our Contributions. Our main contributions are hence an affirmative answer to the first question in the presence of memory, i.e., when the LLM outputs are Markov and when the reward function can be decomposed as the sum of local rewards of contexts, there is indeed an asymptotic closeness result between the KL-constrained RL and best-of-nn distributions. We mention that such local reward criteria arise naturally in controlled decoding and token-level objectives, including attribute control and repetition penalties [9], [11], [19]. When m=1m=1, we also identify classes of LLM reference distributions and reward functions for which the distributions produced by the two alignment methods are close in KL-divergence. In addition, for certain special classes, we characterize how the KL-divergence between the two alignment methods depends on the vocabulary size, thereby making progress on the second question as well.

Due to the paucity of space, some proofs are relegated to the appendices.

Problem Formulation and Our Results

Notation and Assumptions

Let x∈Xx \in\mathcal{X} be an input (prompt) to a language model (LM). Suppose that the vocabulary (set of possible output tokens of the language model) is VV and that the LM is restricted to output a sequence of m+1m+1 tokens. Conditioned on the input x∈Xx \in\mathcal{X}, a language model (denoted by MM) assigns a probability for each response, i.e., for each sequence zm+1=(z0,z1,…,zm)z^{m+1}=(z_0,z_1,\ldots,z_m) of length m+1m+1. In other words, an LM is characterized by the probability distribution

PM(zm+1∣x),zm+1∈Vm+1, x∈X.(1)\mathbb{P}_M(z^{m+1}\mid x), \qquad z^{m+1}\in V^{m+1},\ x\in\mathcal{X}. \tag*{(1)}

Both classical kk-gram LMs [20] and modern-day LLMs generate the next token probabilistically depending on a context consisting of the previous k−1k-1 tokens, in which case the probability of the given sequence zm+1z^{m+1} conditioned on the input xx can be decomposed as follows:

PM(zm+1∣x)=∏i=0mPM(zi∣zi−k+1,…,zi−1,x).(2)\mathbb{P}_M(z^{m+1}\mid x)=\prod_{i=0}^{m}\mathbb{P}_M(z_i\mid z_{i-k+1},\ldots,z_{i-1},x). \tag*{(2)}

where the sequence is appropriately padded with start tokens to ensure that z−1,z−2,…z_{-1},z_{-2},\ldots are well-defined.

Note that (2) essentially establishes the stationary Markov nature of LMs. Formally, for a fixed prompt xx, we absorb xx into yi−1:=(zi−k+1,…,zi−1,x)∈Yy_{i-1}:=(z_{i-k+1},\ldots,z_{i-1},x)\in\mathcal{Y}, where Y=X×Vk−1\mathcal{Y}=\mathcal{X}\times V^{k-1}, to obtain

PM(zm+1∣x)=PM(ym+1)=P(y0)∏i=1mP(yi∣yi−1),(3)\mathbb{P}_M(z^{m+1}\mid x)=\mathbb{P}_M(y^{m+1})=\mathbb{P}(y_0)\prod_{i=1}^{m}\mathbb{P}(y_i\mid y_{i-1}), \tag*{(3)}

where y0y_0 is defined to be a start token and we define Q(ym+1):=PM(ym+1)Q(y^{m+1}):=\mathbb{P}_M(y^{m+1}) since the model MM is fixed. This procedure is formally stated in Assumption II.1.

Let Δa\Delta_a denote the probability simplex on a size-aa alphabet.

Assumption II.1. We assume that the LM outputs a sequence ym+1=(y0,y1,…,ym)∈Ym+1y^{m+1}=(y_0,y_1,\ldots,y_m)\in\mathcal{Y}^{m+1} according to a Markov process with an irreducible aperiodic transition matrix P∣Y∣×∣Y∣P_{\lvert\mathcal{Y}\rvert\times\lvert\mathcal{Y}\rvert}, with stationary distribution π∈Δ∣Y∣\pi\in\Delta_{\lvert\mathcal{Y}\rvert}. We also assume that the first element of the sequence, y0y_0, is drawn from π\pi. Thus, the probability distribution of the sequence ym+1y^{m+1} is obtained as:

PM(ym+1)=Q(ym+1)=πy0∏i=1mPyi−1yi.(4)\mathbb{P}_M(y^{m+1})=Q(y^{m+1})=\pi_{y_0}\prod_{i=1}^{m}P_{y_{i-1}y_i}. \tag*{(4)}

For each sequence outputted by the LM for a given input (or prompt) xx, we assume there exists a positive-valued reward function r:(X×Vm+1)→R+r:(\mathcal{X}\times V^{m+1})\to\mathbb{R}_+. Equivalently, we write the reward as r:Ym+1→R+r:\mathcal{Y}^{m+1}\to\mathbb{R}_+.

To analyze the behavior of the distribution which maximizes the reward, we utilize Assumption II.2, corresponding to the local decomposition of the reward function discussed earlier.

Assumption II.2. The reward function decomposes as the sum of the rewards of adjacent terms, i.e.

r(ym+1)=∑i=1mr(yi−1,yi)=∑i=1mryi−1yi,(5)r(y^{m+1})=\sum_{i=1}^{m}r(y_{i-1},y_i)=\sum_{i=1}^{m}r_{y_{i-1}y_i}, \tag*{(5)}

where rabr_{ab} is a shorthand for r(a,b):Y×Y→R+r(a,b):\mathcal{Y}\times\mathcal{Y}\to\mathbb{R}_+.

Problem Formulation

KL-constrained RL: We attempt to obtain an aligned LM which is a probability distribution qq, such that i) the distance, measured by the KL-divergence (as in [21]) dKL(q,Q)d_{KL}(q,Q), between the probability distributions qq and QQ is at most mδm\delta for some δ>0\delta>0, and ii) the expected reward of qq taken over m+1m+1 samples drawn from qq, is maximized. Note that this expected reward is:

Eym+1∼q[r(Ym+1)]=∑ym+1∈Ym+1q(ym+1)r(ym+1).(6)\mathbb{E}_{y^{m+1}\sim q}[r(Y^{m+1})]=\sum_{y^{m+1}\in\mathcal{Y}^{m+1}}q(y^{m+1})r(y^{m+1}). \tag*{(6)}

We require that qq be a valid probability distribution, i.e., q∈Δ∣Y∣m+1q\in\Delta_{\lvert\mathcal{Y}\rvert^{m+1}}. Thus, the KL-constrained RL can be formally stated as finding

qRL=argmax⁡q∈Δ∣Y∣m+1∑ym+1∈Ym+1q(ym+1)r(ym+1),q_{\mathrm{RL}}=\underset{q\in\Delta_{\lvert\mathcal{Y}\rvert^{m+1}}}{\operatorname{argmax}}\sum_{y^{m+1}\in\mathcal{Y}^{m+1}}q(y^{m+1})r(y^{m+1}),

subject to dKL(q,Q)≤mδd_{KL}(q,Q)\le m\delta. \hspace{1em}(KL-RL)

Best-of-nn: Let Ym+1,i∼QY^{m+1,i}\sim Q be a length-(m+1)(m+1) sequence outputted by the LM according to the distribution QQ for some fixed ii. Now, consider a total of nn such length-(m+1)(m+1) sequences from QQ, which we call Ym+1,1,Ym+1,2,…,Ym+1,nY^{m+1,1},Y^{m+1,2},\ldots,Y^{m+1,n}. The best-of-nn algorithm sets

K∗=argmax⁡i∈[n] r(Ym+1,i)K^*=\underset{i\in[n]}{\operatorname{argmax}}\ r(Y^{m+1,i})
(Bo−n)\hspace{1em}(Bo-n)

and returns YK∗Y_{K^*}. Essentially, the algorithm outputs the highest-reward (‘best’) sequence from nn LM outputs. We let the probability distribution of this random output YK∗Y_{K^*} be denoted as qn,mbestq^{\mathrm{best}}_{n,m}.

The two questions in § 1 can be formalized as:

  1. (Q1): When the LM outputs are drawn from a Markov chain and the rewards decompose locally (Assumptions II.1 and II.2), do we still have lim⁡m→∞1mdKL(qn,mbest,qβ)=0\lim_{m \to\infty} \frac{1}{m}d_{KL}(q^{\mathrm{best}}_{n,m},q_\beta)=0?

  1. (Q2): Assume that m=1m=1. For what choice of the LM distribution QQ and reward function rr is it the case that dKL(qn,mbest,qβ)d_{KL}(q^{\mathrm{best}}_{n,m},q_\beta) either equals or is close to zero?

Our contributions towards (Q1)

We first prove the theorem below, which connects the KL-constrained RL solution with the exponentially tilted distribution studied in [22]. We define the matrix GβG_\beta of the same dimensions as PP to be such that

(Gβ)ij=Pij⋅exp⁡(βrij)(7)(G_\beta)_{ij}=P_{ij}\cdot\exp(\beta r_{ij}) \tag*{(7)}

References

  1. [1]J. Q. Yang, S. Salamatian, Z. Sun, A. T. Suresh, and A. Beirami, “Asymptotics of language model alignment,” in 2024 IEEE International Symposium on Information Theory (ISIT), pp. 2027–2032, 2024.arxiv.org/abs/2404.01730
  2. [2]A. Bick, A. Blandin, and D. Deming, “The rapid adoption of generative AI.” Federal Reserve Bank of St. Louis, On the Economy, Sept. 2024.
  3. [3]E. Brynjolfsson, D. Li, and L. Raymond, “Generative ai at work,” The Quarterly Journal of Economics, vol. 140, pp. 889–942, None 2025.
  4. [4]S. Sajaidieh, L. Fattorini, R. Perault, et al., “Artificial intelligence index report 2026,” 2026.
  5. [5]R. Bommasani, D. A. Hudson, E. Adeli, et al., “On the opportunities and risks of foundation models,” 2022.
  6. [6]L. Ouyang, J. Wu, X. Jiang, D. Almeida, C. L. Wainwright, P. Mishkin, C. Zhang, S. Agarwal, K. Slama, A. Ray, et al., “Training language models to follow instructions with human feedback,” arXiv preprint arXiv:2203.02155, 2022.
  7. [7]E. M. McDonell, T. Gebru, A. McMillan-Major, and S. Shmitchell, “On the dangers of stochastic parrots: Can language models be too big?,” in Proceedings of the 2021 ACM Conference on Fairness, Accountability, and Transparency, FAccT ’21, (New York, NY, USA), p. 610–623, Association for Computing Machinery, 2021.
  8. [8]J. Fickler and Y. Goldberg, “Controlling linguistic style aspects in neural language generation,” in Proceedings of the Workshop on Stylistic Variation, pp. 94–104, Association for Computational Linguistics, 2017.
  9. [9]S. Dathathri, A. Madotto, J. Lan, J. Hung, E. Frank, P. Molino, J. Yosinski, and R. Liu, “Plug and play language models: A simple approach to controlled text generation,” in International Conference on Learning Representations, 2020.arxiv.org/abs/1912.02164
  10. [10]A. Holtzman, J. Buys, L. Du, M. Forbes, and Y. Choi, “The curious case of neural text degeneration,” in International Conference on Learning Representations, 2020.
  11. [11]S. Welleck, I. Kulikov, S. Roller, E. Dinan, K. Cho, and J. Weston, “Neural text generation with unlikelihood training,” in International Conference on Learning Representations, 2020.
  12. [12]P. F. Christiano, J. Leike, T. Brown, M. Martic, S. Legg, and D. Amodei, “Deep reinforcement learning from human preferences,” in Advances in Neural Information Processing Systems, vol. 30, 2017.arxiv.org/abs/1706.03741
  13. [13]N. Stiennon, L. Ouyang, J. Wu, D. Ziegler, R. Lowe, C. Voss, A. Radford, D. Amodei, and P. F. Christiano, “Learning to summarize with human feedback,” in Advances in Neural Information Processing Systems, vol. 33, pp. 3008–3021, 2020.arxiv.org/abs/2009.01325
  14. [14]Y. Zhao, M. Khalman, R. Joshi, S. Narayan, M. Saleh, and P. J. Liu, “Calibrating sequence likelihood improves conditional language generation,” in The Eleventh International Conference on Learning Representations, 2022.
  15. [15]Y. Bai, A. Jones, K. Ndousse, A. Askell, A. Chen, N. DasSarma, D. Drain, S. Fort, D. Ganguli, T. Henighan, et al., “Training a helpful and harmless assistant with reinforcement learning from human feedback,” arXiv preprint arXiv:2204.05862, 2022.
  16. [16]A. Beirami, A. Agarwal, J. Berant, A. D’Amour, J. Eisenstein, C. Nagpal, and A. T. Suresh, “Theoretical guarantees on the best-of-n alignment policy,” in Proceedings of the 42nd International Conference on Machine Learning (A. Singh, M. Fazel, D. Hsu, S. Lacoste-Julien, F. Berkenkamp, T. Maharaj, K. Wagstaff, and J. Zhu, eds.), vol. 267 of Proceedings of Machine Learning Research, pp. 3580–3602, PMLR, 13–19 Jul 2025.arxiv.org/abs/2401.01879
  17. [17]A. Amini, T. Vieira, E. Ash, and R. Cotterell, “Variational best-of-n alignment,” 2025.arxiv.org/abs/2407.06057
  18. [18]O. Zekri, A. Odonnat, A. Benechehab, L. Bleistein, N. Boullé, and I. Redko, “Large language models as markov chains,” 2025.arxiv.org/abs/2410.02724
  19. [19]B. Krause, A. D. Gotmare, B. McCann, N. S. Keskar, S. Joty, R. Socher, and N. F. Rajani, “GeDi: Generative discriminator guided sequence generation,” in Findings of the Association for Computational Linguistics: EMNLP 2021, pp. 4929–4952, Association for Computational Linguistics, 2021.arxiv.org/abs/2009.06367
  20. [20]S. F. Chen and J. T. Goodman, “An empirical study of smoothing techniques for language modeling,” 1996.
  21. [21]J. Peters, K. Mülling, and Y. Altün, “Relative entropy policy search,” in Proceedings of the Twenty-Fourth AAAI Conference on Artificial Intelligence, AAAI’10, p. 1607–1612, AAAI Press, 2010.DOI
  22. [22]S. Salamatian, L. Liu, A. Beirami, and M. Médard, “Mismatched guesswork,” CoRR, vol. abs/1907.00531, 2019.arxiv.org/abs/1907.00531
  23. [23]A. Dembo and O. Zeitouni, Introduction, pp. 1–10. Berlin, Heidelberg: Springer Berlin Heidelberg, 2010.
  24. [24]Z. Rached, F. Alajaji, and L. Campbell, “The kullback-leibler divergence rate between markov sources,” IEEE Transactions on Information Theory, vol. 50, no. 5, pp. 917–921, 2004.DOI
  25. [25]C. D. Meyer, Matrix Analysis and Applied Linear Algebra. Philadelphia, PA: Society for Industrial and Applied Mathematics, 2000.
  26. [26]A. Dembo and O. Zeitouni, LDP for Finite Dimensional Spaces, pp. 11–70. Berlin, Heidelberg: Springer Berlin Heidelberg, 2010.
  27. [27]A. Dembo and O. Zeitouni, General Principles, pp. 115–174. Berlin, Heidelberg: Springer Berlin Heidelberg, 2010.
  28. [28]T. M. Cover and J. A. Thomas, Elements of Information Theory. Wiley, 2 ed., 2006.
  29. [29]V. Nawa and S. Nadarajah, “Exact expressions for kullback–leibler divergence for univariate distributions,” Entropy, vol. 26, no. 11, 2024.DOI
  30. [30]Z. Kadelburg, D. Dukić, M. Lukić, and I. Matić, “Inequalities of Karamata, Schur and Muirhead, and some applications,” The Teaching of Mathematics, pp. 31–45, 2005.
  31. [31]Y. Polyanskiy and Y. Wu, Information Theory: From Coding to Learning. Cambridge University Press, 2025.
  32. [32]D. E. Knuth, “Johann faulhaber and sums of powers,” Mathematics of Computation, vol. 61, no. 203, p. 277–294, 1993.

Paper details

vlnc:W_xxaneeuy
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

GPT-5.5 (bare), GPT 5.6

View statement
Looking for related papers…
Contents