AutoFedNLP: An efficient FedNLP framework

Dongqi Cai, Yaozong Wu, Shangguang Wang, Felix Xiaozhu Lin, Mengwei Xu

Abstract

Transformer-based pre-trained models have revolutionized NLP for superior performance and generality. Fine-tuning pre-trained models for downstream tasks often requires private data, for which federated learning is the de-facto approach (i.e., FedNLP). However, our measurements show that FedNLP is prohibitively slow due to the large model sizes and the resultant high network/computation cost. Towards practical FedNLP, we identify as the key building blocks adapters, small bottleneck modules inserted at a variety of model layers. A key challenge is to properly configure the depth and width of adapters, to which the training speed and efficiency is highly sensitive. To automate adapter configuration, we propose FedAdapter, a framework that enhances the existing FedNLP with two novel designs: progressive adapter upgrading and continuous online profiling. Extensive experiments show that FedAdapter can reduce FedNLP's model convergence delay to no more than several hours, which is up to 155.5× faster compared to vanilla FedNLP.

Introduction: The Bottlenecks of FedNLP

While Transformer-based models like BERT have revolutionized NLP, training them in a privacy-preserving way via Federated Learning (FedNLP) is a major challenge for mobile infrastructure. The standard approach involves fine-tuning massive pre-trained models on decentralized, private data located on mobile devices.

Overview of the FedNLP workflow, transitioning from centralized pre-training to geo-distributed fine-tuning.

Two primary bottlenecks hinder practical deployment:

  1. Communication Overhead: Syncing hundreds of millions of parameters (hundreds of MBs) every round is too slow for typical mobile uplinks.
  2. Computation Cost: Running full forward and backward passes on massive models drains mobile batteries and takes too long per round.

Existing "parameter-efficient" tricks like layer freezing often hurt accuracy or offer only modest speedups. While adapters—small bottleneck modules inserted into the model—are a promising alternative, there is no "silver bullet" configuration. The optimal depth and width of these adapters vary wildly depending on the specific task, the target accuracy, and the available hardware.

FedAdapter: Progressive and Automated Fine-Tuning

FedAdapter introduces three core innovations to automate and optimize the use of adapters in a federated setting. The central building block is the Adapter, a small module inserted into the Transformer layers that allows for parameter-efficient updates.

The Transformer block integrated with an Adapter module, the core building block of FedAdapter.

1. Progressive Training

Instead of starting with a complex model, FedAdapter begins training with very few, small adapters at the top layers (near the output). This allows the model to capture "shallow" knowledge quickly at a very low cost. As training plateaus, the system incrementally incorporates deeper and larger adapters to learn more complex features.

2. The Online Configurator (Sideline Trials)

To find the best architecture without expensive offline searching, the server uses "surplus" participant devices to run experiments. In each round, different groups of clients test the current configuration against "deeper" or "wider" versions. The server then "upgrades" the global model to whichever configuration shows the best accuracy gains, effectively turning redundant resources into a search engine for efficiency.

3. Activation Caching

Since the bottom layers of the Transformer remain frozen during adapter training, their output for a given local data sample never changes. FedAdapter caches these activations on the mobile device's storage, allowing it to skip the forward pass for those bottom layers in subsequent rounds, saving significant CPU/GPU cycles.

Key Results and Evaluation

The framework was evaluated on four classic NLP benchmarks (20NEWS, AGNEWS, SEMEVAL, and ONTONOTES) across various hardware, including NVIDIA Jetson TX2, Jetson Nano, and Raspberry Pi 4B.

  • Massive Speedups: FedAdapter reached 99% relative accuracy up to 155.5× faster than vanilla fine-tuning and 48× faster than strong baselines like model quantization or layer freezing.
  • Drastic Resource Savings: It reduced total network traffic by an average of 126.7× (e.g., from 2.1 TB down to just 9.9 GB for one task). Per-device energy consumption dropped by 18.4×.
  • Practicality: On high-end edge devices like the Jetson TX2, training sessions that previously took days were completed in under an hour.

Conclusion

FedAdapter demonstrates that large-scale NLP models can be efficiently fine-tuned in a federated manner on mobile devices. By dynamically adjusting model capacity through progressive adapters and leveraging activation caching, it overcomes the traditional communication and computation barriers of FedNLP, making privacy-preserving NLP practical for real-world mobile applications.

Summary updated

BibTeX
@misc{cai2022autofednlp,
  author = {Dongqi Cai and Yaozong Wu and Shangguang Wang and Felix Xiaozhu Lin and Mengwei Xu},
  title = {{AutoFedNLP: An efficient FedNLP framework}},
  year = {2022},
  eprint = {2205.10162},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2205.10162},
}
Figure