Learning to Decode Collaboratively with Multiple Language Models

Shannon Zejiang Shen, Hunter Lang, Bailin Wang, Yoon Kim, David A. Sontag · OpenReview

Abstract

We propose a method to teach multiple large language models (LLM) to collaborate by interleaving their generations at the token level. We model the decision of which LLM generates the next token as a latent variable. By optimizing the marginal likelihood of a training set under our latent variable model, the base LLM automatically learns when to generate itself and when to call on one of the "assistant" language models to generate, all without direct supervision. Token-level collaboration during decoding allows for a fusion of each model's expertise in a manner tailored to the specific task at hand. Our collaborative decoding is especially useful in cross-domain settings where a generalist base LLM learns to invoke domain expert models. On instruction-following, domain-specific QA, and reasoning tasks, we show that the performance of the joint system exceeds that of the individual models. Through qualitative analysis of the learned latent decisions, we show models trained with our method exhibit several interesting collaboration patterns, e.g., template-filling.

Introduction

The current landscape of Large Language Models (LLMs) features a divide between massive general-purpose models and smaller, domain-specific "experts." While both have unique strengths, effectively combining them remains a challenge. Existing strategies often rely on computationally expensive logit fusion or require labor-intensive human-annotated data for tool-use API calls.

Researchers from MIT have introduced Co-LLM, a framework that enables multiple LLMs to collaborate token-by-token during text generation. By treating the choice of which model to use as a latent variable, a small base model automatically learns when to generate text itself and when to "defer" to a more powerful or specialized assistant model.

Methods: The Latent-Variable Framework

The core of Co-LLM is a latent-variable framework that facilitates unsupervised learning of collaboration patterns. The setup involves a finetunable base model (e.g., Llama-7B) and one or more assistant models (e.g., Llama-70B or a specialized math model).

A simple linear classification head is added to the base model's last layer to predict the probability of deferral: "Should I generate the next token, or should the assistant?" The system is trained by maximizing the marginal likelihood of the correct text. Crucially, the base model is not given explicit labels for when to switch. Instead, it learns that if the assistant is significantly more likely to predict the correct next token in a specific context, it should defer to minimize loss.

Visualization of the Co-LLM deferral mechanism where a base model defers to a specialized assistant for domain-specific entities.

During inference, if the predicted deferral probability exceeds a tuned threshold ($\eta$), the assistant takes over for that token. This allows for dynamic, token-level switching based on the immediate needs of the generation task.

Key Insights and Collaboration Patterns

Qualitative analysis reveals that Co-LLM models develop a "scaffolding" or "template-filling" strategy. The smaller base model typically handles the "connective tissue" of the response—phrases like "The answer is..." or "Step 1:"—while deferring to the assistant for "heavy lifting" such as factual entities, complex LaTeX formulas, or specific numerical calculations.

Examples of collaborative decoding in general knowledge and mathematical reasoning tasks.

In mathematical tasks, the base model learns to treat specialized assistants almost like a computation API, invoking them specifically when a formula needs to be solved. This synergy is architecture-agnostic; the authors successfully paired a dense Mistral-7B base with a sparse Mixtral-8x7B (MoE) assistant.

Experimental Results

The authors evaluated Co-LLM across several domains, including instruction following (AlpacaEval), mathematical reasoning (GSM8k, MATH), and biomedical QA (BioASQ).

  • Mathematical Reasoning: On the GSM8k benchmark, Co-LLM (Llama-7B + Llemma-34B) achieved a score of 43.5, significantly outperforming a standard fine-tuned Llama-7B (34.5).
  • Biomedical QA: In some BioASQ tasks, the collaborative 7B+70B system actually outperformed a 70B model that had been fully fine-tuned on the same data.
  • Efficiency: Unlike methods that require running both models for every token, Co-LLM only invokes the expensive assistant model when necessary, offering a tunable trade-off between performance and computational cost via the deferral threshold.

Conclusion and Future Work

Co-LLM demonstrates that token-level collaboration can significantly enhance model performance without the need for manual intervention or expensive labeling. However, some limitations remain. The optimal deferral threshold currently requires grid searching on a validation set, and the system lacks a mechanism for the base model to overrule assistant hallucinations. Future research will focus on scaling this approach to "routing" between a library of many specialized experts and exploring applications with proprietary models where only log-probabilities are accessible.

Code is available at https://github.com/clinicalml/co-llm.

Summary updated

BibTeX
@misc{shen2024learning,
  author = {Shannon Zejiang Shen and Hunter Lang and Bailin Wang and Yoon Kim and David A. Sontag},
  title = {{Learning to Decode Collaboratively with Multiple Language Models}},
  year = {2024},
  eprint = {2403.03870},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.03870},
}
Figure