TL;DR
This paper introduces "context distillation," a method to make large language models (LLMs) internalize knowledge and skills learned from context tokens (like instructions or scratchpads). By training the LLM to predict its own output based on a simplified prompt after it has already learned from a detailed prompt, the model can retain these gains without needing the full context during inference, leading to more efficient and capable models.
What Problem Does This Paper Address?
Large language models (LLMs) show impressive performance improvements when provided with context, such as detailed instructions, explanations, or step-by-step reasoning examples (often called "scratchpads"). However, these performance gains are transient; they disappear once the context tokens are removed. This means that for every inference, the full, often lengthy, context must be re-processed, which is computationally expensive and limits the complexity of tasks LLMs can handle if the context exceeds their window size. The authors liken this to human learning, where repeated practice leads to internalized skills that don't require conscious effort. They aim to bridge this gap by enabling LLMs to "internalize" these context-derived benefits.
Methods
The core idea is "context distillation," which adapts the concept of knowledge distillation to LLMs using contextual information. The process involves two stages:
- Teacher Stage: A language model (the "teacher") is given a raw task input augmented with a detailed "teacher template." This template includes comprehensive instructions, explanations, and potentially examples. The teacher model then generates a completion, which might include a "scratchpad" (intermediate reasoning) and the final answer.
- Student Stage: The same language model (now acting as the "student") is then fine-tuned. The student is given the raw task input but with a simplified "student template." This template contains minimal instructions, omitting the detailed explanations and scratchpad from the teacher stage. The student is trained to predict only the final answer extracted from the teacher's output.
This process effectively "distills" the knowledge or skill learned from the rich context into the student model's parameters, allowing it to perform the task without the original detailed context. The authors also introduce variations like simultaneous distillation (combining multiple distillation tasks) and sequential distillation (overwriting previous learned information).
Datasets
The paper utilizes several datasets for training and evaluation:
- Natural-Instructions-V2: A large dataset of diverse language tasks used for internalizing abstract instructions and natural language explanations.
- SPIDER: A dataset for Text-to-SQL tasks, used to evaluate the internalization of concrete training examples.
- 8-digit addition problems: Synthetically generated problems used to test the internalization of step-by-step reasoning.
Key Insights and Ideas
- Internalizing Skills: The most significant insight is that LLMs can indeed internalize complex skills and knowledge from contextual examples, moving beyond simply performing well with context to performing well because of internalized learning.
- Generalizability of Context Distillation: The method proves effective across diverse learning signals: abstract instructions, concrete examples, and step-by-step reasoning.
- Efficiency Gains: Distilled models are significantly more efficient, requiring far fewer tokens during inference (up to 11x fewer in some cases), which translates to substantial computational savings.
- Overwriting Knowledge: Sequential distillation allows for updating or overwriting previously learned information, enabling iterative refinement of the model's capabilities.
- Beyond Context Window Limits: Simultaneous distillation allows models to learn from more training examples than can fit within the standard context window, by effectively combining multiple distillation operations.
Key Results
- Abstract Instructions: Context distillation improved a student model's performance from 9.0 to 34.7 Rouge-L on abstract task instructions, internalizing them effectively.
- Text-to-SQL: On the SPIDER dataset, context distillation outperformed direct gradient descent by 8.6% for 4-example learning and further improved with more examples, even exceeding context window limits.
- Step-by-Step Reasoning: For 8-digit addition, context distillation boosted direct addition accuracy from 0% to 94.7%, demonstrating successful internalization of reasoning skills. This internalized skill also transferred to related reasoning tasks.
- Efficiency: Inference time token usage was reduced by up to 11 times compared to the teacher model.
Limitations and Future Work
- Model Responsiveness: The paper notes that not all tasks benefit equally from natural language explanations, and future improvements depend on LLMs becoming more responsive to such explanations.
- Neighborhood Prompts in Fact Editing: In the fact editing application, the prompted teacher model performed poorly on "neighborhood prompts" (unrelated facts that should not be edited), which also impacted the distilled student. The authors expect larger, more capable models to resolve this.
- Computational Resources: While context distillation is computationally efficient at inference, the training process itself still requires significant resources.
- Future Work: The authors anticipate that context distillation will become increasingly useful as LLMs develop stronger in-context learning capabilities and tackle more complex tasks requiring longer reasoning chains. They suggest future models will be better at learning from context, making this method even more impactful.
Summary updated