Implicit Federated In-context Learning For Task-Specific LLM Fine-Tuning

Dongcheng Li, Junhan Chen, Aoxiang Zhou, Chunpei Li, Youquan Xian, Peng Liu, Xianxian LiarXiv 2025 · DOI

Abstract

Implicit Federated In-context Learning (IFed-ICL) is a novel framework designed to fine-tune Large Language Models (LLMs) on distributed private data without the prohibitive costs of traditional federated fine-tuning. By representing private examples as implicit vectors and optimizing a minimal set of injection coefficients, IFed-ICL achieves high performance with a 10,000x reduction in communication overhead compared to methods like FedAvg-LoRA. Experimental results on LLaMA-3 and Qwen2.5 across multiple benchmarks demonstrate superior accuracy and robustness to data heterogeneity.

Introduction

As Large Language Models (LLMs) exhaust high-quality public data, the next frontier for performance gains lies in private, domain-specific datasets held by organizations. However, two major hurdles exist for standard fine-tuning in these environments:

  1. Privacy: Traditional In-Context Learning (ICL) requires sending raw data examples to a model, which violates data locality and risks leaking sensitive information.
  2. Efficiency: Federated Learning (FL) methods that fine-tune model parameters (even parameter-efficient ones like LoRA) require transmitting and computing massive weight matrices. For a model like LLaMA-3-405B, transmitting weights over a standard network could take days.

IFed-ICL bridges this gap, offering a way to collaboratively learn from private data without sharing raw text or heavy model weights.

Methodology

IFed-ICL replaces traditional parameter updates with a three-stage "vector injection" process, as illustrated in Figure 1.

The three-stage workflow of IFed-ICL: Context Vector Extraction, Collaborative Calibration, and Task-Specific Inference.
  1. Context Vector Extraction: Instead of sending raw text, each client uses a frozen local LLM to process their private data. They extract intermediate activation vectors from the Multi-Head Attention (MHA) and Multi-Layer Perceptron (MLP) modules. These are averaged into a compact local context vector and sent to the server.
  2. Collaborative Calibration: The server aggregates these into a global context vector. Clients then perform a lightweight training process to optimize injection coefficients ($\Lambda$). These coefficients determine how much of the global context should be injected into the LLM’s residual stream at each layer during inference.
  3. Task-Specific Inference: Once calibrated, the server distributes the global coefficients. When a client runs a query, they use the raw LLM and "inject" the global context vector using the learned coefficients, transforming the general-purpose LLM into a task-specific one through a single linear operation.

Experimental Setup

The framework was evaluated using LLaMA-3-8B and Qwen2.5-7B across three standard text classification benchmarks: SUBJ (subjectivity), Emotion (twitter-based detection), and AG News (topic classification). To simulate real-world conditions, data was partitioned using a Dirichlet distribution ($\alpha=0.5$) to create a Non-IID (non-independent and identically distributed) environment where different clients hold heterogeneous data.

Key Results and Insights

IFed-ICL demonstrates significant improvements over baseline methods in terms of accuracy, speed, and communication efficiency.

Global model accuracy across federated learning rounds for AG News, Emotion, and SUBJ datasets.
  • Superior Accuracy: IFed-ICL consistently outperformed Zero-Shot, Local ICL, and FedAvg-LoRA. On the SUBJ dataset with LLaMA-3, it achieved 91.20% accuracy, significantly higher than FedAvg-LoRA's 66.00%.
  • Communication Efficiency: By exchanging context vectors and scalar coefficients rather than weight matrices, the framework achieved a 10,000x reduction in data transmitted compared to LoRA. During the core training phase, IFed-ICL required only 1.8 KB of communication per round, versus over 13 MB for FedAvg-LoRA.
  • Computational Speedup: Client-side computation was 20 to 40 times faster than traditional federated fine-tuning.
  • Robustness to Heterogeneity: The method is more robust to Non-IID data because it leverages global knowledge through the aggregated context vector while using local calibration to prevent overfitting.

Limitations and Future Work

While effective for classification, the current study's scope is limited to text classification tasks. Future research is needed to determine how well "implicit injection" scales to complex generative tasks like long-form summarization. Additionally, the method requires "white-box" access to internal model activations, meaning it cannot currently be used with API-only models like GPT-4. Future directions include exploring more complex injection architectures and testing on larger-scale distributed systems like mobile and IoT devices.

Summary updated

BibTeX
@misc{li2025implicit,
  author = {Dongcheng Li and Junhan Chen and Aoxiang Zhou and Chunpei Li and Youquan Xian and Peng Liu and Xianxian Li},
  title = {{Implicit Federated In-context Learning For Task-Specific LLM Fine-Tuning}},
  year = {2025},
  eprint = {2511.06757},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.06757},
}
Figure