Training Plug-n-Play Knowledge Modules with Deep Context Distillation

Lucas Caccia, Alan Ansell, Edoardo M. Ponti, Ivan Vulic, Alessandro Sordoni · OpenReview

Abstract

Dynamically integrating new or rapidly evolving information after (Large) Language Model pre-training remains challenging, particularly in low-data scenarios or when dealing with private and specialized documents. In-context learning and retrieval-augmented generation (RAG) face limitations, including their high inference costs and their inability to capture global document information. In this paper, we propose a way of modularizing knowledge by training document-level Knowledge Modules (KMs). KMs are lightweight components implemented as parameter-efficient LoRA modules, which are trained to store information about new documents and can be easily plugged into models on demand. We show that next-token prediction performs poorly as the training objective for KMs. We instead propose Deep Context Distillation: we learn KMs parameters such as to simulate hidden states and logits of a teacher that takes the document in context. Our method outperforms standard next-token prediction and pre-instruction training techniques, across two datasets. Finally, we highlight synergies between KMs and RAG.

Introduction

Large Language Models (LLMs) are typically static after pre-training. To reason over new or private data, practitioners often rely on In-Context Learning (ICL) or Retrieval-Augmented Generation (RAG). However, ICL incurs high inference costs due to linear KV cache growth, and RAG often suffers from "tunnel vision," focusing on local snippets while missing global document context. While fine-tuning is an option, training on single documents often leads to the "perplexity curse," where models overfit to surface patterns rather than learning underlying facts.

Methodology: Deep Context Distillation

To address these challenges, we introduce Knowledge Modules (KMs): document-specific LoRA adapters. The core innovation is Deep Context Distillation (DCD), a training objective that moves beyond standard next-token prediction (NTP).

The DCD framework uses a teacher model with full context to guide a student model equipped with a KM adapter.

In the DCD setup, a "Teacher" model processes the full document in its context window. A "Student" model (the same base LLM) attempts to mimic the Teacher’s internal hidden states and output logits without having the document in its context, relying instead on the KM adapter. To enhance the training signal, we utilize synthetic data generation, including summaries, QA pairs, and knowledge graphs. Additionally, a Knowledge Extractor (KE)—a task-specific adapter—is trained to interface with any KM, ensuring modularity and transferability.

Evaluation and Results

We evaluated our approach on QuALITY (multiple-choice QA), NarrativeQA (generative QA on long documents), and LongHealth (clinical reports).

Performance and Efficiency

DCD-based KMs significantly outperformed standard fine-tuning. For instance, on NarrativeQA using Phi-3, DCD achieved a 34.8 Rouge-L score compared to 20.7 for standard NTP. Crucially, KMs offer a superior efficiency profile.

KMs combined with RAG and KE achieve high performance with significantly lower token costs compared to standard ICL.

As shown in the figure above, the KM+KE setup matches RAG performance while using fewer context tokens, potentially halving inference costs for long-context tasks. Furthermore, the "plug-and-play" nature of KMs prevents catastrophic forgetting; testing on MMLU showed only a negligible (~1%) drop in general knowledge accuracy when a KM was active.

Key Insights

  • Dense Learning Signals: NTP is insufficient for low-data regimes. DCD provides a denser signal by supervising hidden states.
  • Global Context: Unlike RAG's local retrieval, KMs encode global document information into adapter weights.
  • Synergy with RAG: The best results were achieved by combining KMs (for global knowledge) with RAG (for local context).

Conclusion

Knowledge Modules trained via Deep Context Distillation provide a scalable, modular way to update LLMs with new information. While training KMs currently requires gradient descent—making it more expensive than RAG indexing—the inference-time efficiency and global context awareness offer significant advantages. Future work will explore faster initialization methods and automated routing for large-scale KM libraries.

Summary updated

Abstract

Dynamically integrating new or rapidly evolving information after (Large) Language Model pre-training remains challenging, particularly in low-data scenarios or when dealing with private and specialized documents. In-context learning and retrieval-augmented generation (RAG) face limitations, including their high inference costs and their inability to capture global document information. In this paper, we propose a way of modularizing knowledge by training document-level Knowledge Modules (KMs). KMs are lightweight components implemented as parameter-efficient LoRA modules, which are trained to store information about new documents and can be easily plugged into models on demand. We show that next-token prediction performs poorly as the training objective for KMs. We instead propose Deep Context Distillation: we learn KMs parameters such as to simulate hidden states and logits of a teacher that takes the document in context. Our method outperforms standard next-token prediction and pre-instruction training techniques, across two datasets. Finally, we highlight synergies between KMs and RAG.
BibTeX
@inproceedings{caccia2025training,
  author = {Lucas Caccia and Alan Ansell and Edoardo M. Ponti and Ivan Vulic and Alessandro Sordoni},
  title = {{Training Plug-n-Play Knowledge Modules with Deep Context Distillation}},
  booktitle = {MCDC @ ICLR},
  year = {2025},
  url = {https://openreview.net/forum?id=yyo54Z8VTy},
}
Figure