Abstract
Large Language Models (LLMs) demonstrate remarkable adaptability through In-Context Learning (ICL), yet the efficacy of this approach is often constrained by the availability of high-quality, task-specific examples. In many real-world scenarios, such data is distributed across private client devices and cannot be centralized due to privacy and bandwidth constraints. This paper introduces Federated In-Context Learning (Fed-ICL), a framework that enables distributed clients to collaboratively refine LLM outputs using local private data without the need for parameter transmission. By iteratively communicating only text-based queries and answers, Fed-ICL achieves significant communication savings and performance gains over traditional federated learning and parameter-free baselines.
Introduction
The success of In-Context Learning (ICL) relies heavily on the relevance and quality of the examples provided in the prompt. However, the most valuable data for specialized tasks—such as medical records or personal communications—is often siloed on edge devices. Traditional Federated Learning (FL) addresses data privacy by training models locally and aggregating weight updates. However, for modern LLMs with billions of parameters, the communication overhead of transmitting weights is prohibitively expensive.
To address this, we propose Fed-ICL, a "parameter-free" federated framework. Instead of updating model weights, Fed-ICL iteratively updates the context and the generated answers. This approach leverages the rich, private datasets on client devices while maintaining a communication footprint orders of magnitude smaller than weight-based FL.
The Fed-ICL Framework
Fed-ICL operates through an iterative, round-based process between a central server and multiple clients. The workflow is structured as follows:
- Server Query: The central server broadcasts a query (and any candidate answers from previous rounds) to the participating clients.
- Local Retrieval and Inference: Each client performs a k-Nearest Neighbors (k-NN) search against its private local dataset to identify the most relevant examples for the given query. These examples are used as context for the client's local LLM to generate a refined answer.
- Server Aggregation: Clients return only their generated text answers to the server. The server then aggregates these responses. For multiple-choice tasks, a majority voting mechanism is used; for open-ended generation, a lightweight "Fusion LLM" merges the various perspectives into a single global answer.
Handling Unlabeled Data
The authors also introduce Fed-ICL-Free, a variant designed for scenarios where clients possess relevant text but lack ground-truth labels. This demonstrates that even unlabeled local data can ground an LLM's reasoning and improve performance compared to zero-shot or centralized baselines.
Theoretical Foundation
Beyond empirical results, the paper provides theoretical guarantees for the Fed-ICL mechanism. Using a simplified linear self-attention model, the authors mathematically prove that this iterative text-based refinement converges toward an optimal answer. This provides a formal justification for why exchanging generated text can serve as a proxy for the knowledge contained within private datasets.
Experimental Evaluation
The framework was evaluated using two primary benchmarks, with data distributed across clients using a Dirichlet distribution to simulate real-world heterogeneity:
- MMLU (Massive Multitask Language Understanding): A multiple-choice benchmark covering 57 subjects. Performance was measured by accuracy.
- TruthfulQA: An open-ended task testing the model's ability to avoid common falsehoods. Performance was measured using BERTScore, BLEURTScore, and BARTScore.
Key Results
- Communication Efficiency: Fed-ICL typically converges within approximately 6 rounds. Because it only transmits text tokens rather than gigabytes of model weights, it is significantly more efficient than traditional FedAvg.
- Performance Gains: Fed-ICL consistently outperformed parameter-free baselines such as LLM-Debate, Mixture-of-Agents, and LLM-Blender. It proved particularly effective for smaller, open-source models (e.g., Llama-3-8B), suggesting that federated collaboration can help bridge the performance gap between edge-tier models and massive proprietary ones.
- Privacy and Resilience: Since raw data never leaves the client and only final answers are shared, the framework is inherently private. Testing against prompt-extraction attacks confirmed that the framework is highly resilient to adversarial attempts to recover local data from the model's output.
Discussion and Limitations
While Fed-ICL offers a robust alternative to weight-based FL, it faces challenges regarding data heterogeneity. In cases where client datasets are extremely divergent, reconciling different domain perspectives at the server level becomes more difficult, occasionally leading to performance degradation as the number of clients increases.
Furthermore, the current theoretical proofs are limited to linear transformer architectures. Extending these guarantees to the complex, non-linear architectures of modern LLMs remains a vital area for future research. Future work may also explore the application of Fed-ICL to multimodal tasks, such as federated vision-language modeling.
Conclusion
Fed-ICL represents a significant step toward practical, privacy-preserving collaborative AI. By shifting the focus from weight aggregation to iterative context refinement, the framework enables high-quality LLM inference on private data with minimal communication overhead, making federated intelligence more accessible for resource-constrained edge devices.
Summary updated