Amortizing intractable inference in large language models

Edward J. Hu, Moksh Jain, Eric Elmoznino, Younesse Kaddar, Guillaume Lajoie, Yoshua Bengio, Esmeralda S. Whitammer

This paper, presented at ICLR 2024, introduces a powerful new way to fine-tune Large Language Models (LLMs) by treating complex reasoning and generation tasks as problems of amortized Bayesian inference. By leveraging Generative Flow Networks (GFlowNets), the authors enable LLMs to sample diverse, high-quality sequences from distributions that are typically mathematically intractable to compute.

TL;DR

Instead of training LLMs to just find the "single best" answer, this work uses GFlowNets to fine-tune models to sample a diverse set of valid reasoning chains. This approach significantly improves performance in low-data regimes and enhances out-of-distribution generalization for tasks like multi-step arithmetic and story infilling.

What Problem Does This Paper Address?

Standard LLMs are great at predicting the next token in a sequence (autoregressive sampling). However, many important tasks require "filling in the blanks" or reasoning toward a specific goal. Mathematically, these are posterior inference problems: given a question ($X$) and a desired answer ($Y$), what is the most likely reasoning chain ($Z$)?

The challenge is that the "true" distribution of these reasoning chains is intractable. You can't easily calculate the probability of a specific chain without summing over every possible sequence of words, which is impossible. Existing solutions have major flaws:

  • Maximum Likelihood (MLE): Requires massive amounts of high-quality human demonstrations.
  • Standard Reinforcement Learning (e.g., PPO): Often suffers from "mode collapse," where the model finds one "good enough" answer and stops exploring others, leading to poor diversity and brittle generalization.
  • MCMC Sampling: Too slow for real-time text generation.

Methods

The authors propose fine-tuning LLMs using GFlowNets. Unlike standard RL, which seeks to maximize a reward, GFlowNets are designed for distribution matching. They train a policy to sample objects (like a sentence or a reasoning chain) with a probability proportional to a given reward function.

Key technical components include:

  • Latent Variable Modeling: They treat the "Chain-of-Thought" ($Z$) as a hidden variable between the input ($X$) and output ($Y$).
  • Subtrajectory Balance (SubTB): A specific GFlowNet objective used to train the model to match the target distribution efficiently.
  • Amortization: By training the model on various inputs, it "learns" the inference process, allowing it to generate rationales for new, unseen questions instantly at test time.
  • LoRA (Low-Rank Adaptation): Used to make fine-tuning large models (up to 6B parameters) computationally feasible.
The authors interpret reasoning as a latent variable model where X (input) leads to Y (output) via Z (latent chain).

Datasets

The researchers evaluated their method across four distinct types of tasks:

  1. Random Number Generation: A "sanity check" task using a prompt to generate uniform integers between 0 and 100.
  2. Sentence Continuation: Using OpenWebText to generate diverse and likely next sentences.
  3. Story Infilling: Using the ROCStories corpus, where the model must generate a middle sentence that connects a given beginning and end.
  4. Reasoning & Tool Use:
    • SUBJ: A subjectivity classification dataset (movie reviews).
  5. Integer Arithmetic: A synthetic dataset of addition and subtraction problems requiring a calculator tool.

Key Insights and Ideas

  • Diversity is a Feature, Not a Bug: In Bayesian modeling, we often want to sample multiple rationales and "vote" on the final answer. GFlowNets provide the diversity needed for this "Bayesian model averaging" to work effectively.
  • Robustness to Reward Misspecification: Standard RL (PPO) can "hack" a reward function by finding weird, non-human-like sequences that technically get a high score. Because GFlowNets try to match the entire distribution of high-reward sequences, they are much more robust to these spurious modes.
  • Generalization through Diversity: By learning a diverse set of ways to solve a problem, the model generalizes better to harder, out-of-distribution (OOD) examples (e.g., solving math problems with more numbers than seen during training).
GFlowNets (c) successfully match the target uniform distribution, whereas PPO (b) remains skewed by the base model's pre-existing biases.

Key Results

  • Subjectivity Classification: With only 10 labeled examples, GFlowNet fine-tuning achieved 71.4% accuracy, a 10.9% absolute improvement over standard supervised fine-tuning (SFT).
  • Arithmetic Reasoning: On OOD problems (5 operands when trained on 3-4), GFlowNet outperformed SFT and PPO by 63%, reaching 40.7% accuracy compared to SFT's 12.8%.
  • Likelihood vs. Diversity: For sentence continuation, GFlowNet achieved a better trade-off than beam search, producing sentences with higher log-likelihood while maintaining significantly higher semantic diversity.
Figure 3: Maximum log-likelihood and diversity of con- tinuations sampled for fixed prompts. GFlowNet fine- tuning (★) samples higher log-likelihood sentences while maintaining more sample diversity than the baselines (• and ---), even when they are given 5× the compute.

Limitations and Future Work

  • Model Scale: The experiments were limited to models up to 6B parameters due to compute constraints. The authors expect the benefits to scale even further with larger models.
  • Knowledge vs. Inference: This method improves the model's ability to query its internal knowledge (inference) but doesn't necessarily add new knowledge. Issues like hallucinations stemming from the base model's training data remain.
  • Exploration: For extremely complex latent spaces, finding the initial "good" samples to start the GFlowNet training remains a challenge.

Future directions include building "universal reasoners" that share a GFlowNet policy across different tasks and extending the framework to more complex structures like tree-of-thought reasoning or program synthesis.

Summary updated

Abstract

Autoregressive large language models (LLMs) compress knowledge from their training data through next-token conditional distributions. This limits tractable querying of this knowledge to start-to-end autoregressive sampling. However, many tasks of interest -- including sequence continuation, infilling, and other forms of constrained generation -- involve sampling from intractable posterior distributions. We address this limitation by using amortized Bayesian inference to sample from these intractable posteriors. Such amortization is algorithmically achieved by fine-tuning LLMs via diversity-seeking reinforcement learning algorithms: generative flow networks (GFlowNets). We empirically demonstrate that this distribution-matching paradigm of LLM fine-tuning can serve as an effective alternative to maximum-likelihood training and reward-maximizing policy optimization. As an important application, we interpret chain-of-thought reasoning as a latent variable modeling problem and demonstrate that our approach enables data-efficient adaptation of LLMs to tasks that require multi-step rationalization and tool use.
BibTeX
@inproceedings{hu2024amortizing,
  author = {Edward J. Hu and Moksh Jain and Eric Elmoznino and Younesse Kaddar and Guillaume Lajoie and Yoshua Bengio and Esmeralda S. Whitammer},
  title = {{Amortizing intractable inference in large language models}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=Ouj6p4ca60},
}
Figure