Part 10 of 15 in LLM fine-tuning techniques

Federated tuning fine-tunes one language model across many data owners, such as phones, hospitals or banks, without collecting their data in one place: each owner trains locally and sends back only a model update. It applies federated learning, introduced by Google researchers in 2016 with the FedAvg algorithm, to LLMs, and is usually paired with LoRA so that only small adapter weights travel.

10-100x
fewer communication rounds than synchronized SGD
McMahan et al., 2016
0.26%
of LLaMA-7B's parameters trained per client in FedIT
Zhang et al., 2023, Table 2
0.832 vs 0.731
finance accuracy, FedAvg-tuned Llama2-7B vs GPT-4
Ye et al., 2024, Table 5

What is federated tuning?

Federated tuning is fine-tuning a shared model on data that stays on many separate clients. A central server coordinates; "each client has a local training dataset which is never uploaded to the server. Instead, each client computes an update to the current global model", and only that update is sent (McMahan et al., 2016, Sec. 1).

For LLMs, the term covers two jobs that the papers below test:

  • Federated instruction tuning (FedIT): clients hold instruction-response pairs and jointly instruction-tune a model (Zhang et al., 2023). See instruction tuning for the non-federated version.
  • Federated value alignment: clients hold preference data and jointly align the model; OpenFedLLM does this with DPO on each client, which it calls FedDPO (Ye et al., 2024, Sec. 3). See DPO.

How does federated tuning work?

Federated tuning works in rounds. The server sends the current weights to a sample of clients, each client trains on its own data for a few local steps, and the server replaces the global weights with a weighted average of what comes back. This is the FederatedAveraging (FedAvg) algorithm (McMahan et al., 2016, Algorithm 1).

Diagram: a server sends global weights to four clients holding private data; each trains locally and sends updates back; the server averages them weighted by data size

One FedAvg round, step by step

  1. Select clients. The server picks m = max(C × K, 1) of its K clients at random, where C is the fraction of clients used per round.
  2. Broadcast. Each selected client receives the current global weights w_t.
  3. Train locally. Each client runs E local epochs of SGD over its own data in minibatches of size B, then returns its new weights w_k.
  4. Average. The server sets w_{t+1} = Σ_k (n_k / m_t) · w_k, where n_k is client k's number of examples and m_t is the total held by that round's clients. (arXiv version 4 of the paper, January 2023, fixed a typo in this line of the pseudocode.)

Setting B to the full local dataset and E = 1 gives FedSGD, the one-gradient-step baseline the paper compares against (Sec. 2).

What changes for LLMs

Sending a full 7B model every round is the main cost. FedIT and OpenFedLLM both freeze the base model and train LoRA adapters, so clients upload only adapter weights and the server averages only those. FedIT says model aggregation combines "only the trainable parameters specified by the LoRA configuration instead of all the parameters" to cut computation and communication (Zhang et al., 2023, Sec. 3.4).

Worked example from OpenFedLLM's setup. Llama2-7B has 6,738M parameters; with LoRA rank 32 the trainable and communicated part is 4.194M, which the paper reports as 0.06% of the total, sent per round (Ye et al., 2024, Sec. 4.1, Table 3). OpenFedLLM also quantizes the base model to int8 so training runs on one consumer GPU, an NVIDIA RTX 3090.

When was federated tuning introduced, and by whom?

Federated learning came first, and its application to LLM fine-tuning followed about seven years later:

PaperAuthorsFirst on arXivVenue
Communication-Efficient Learning of Deep Networks from Decentralized Data (FedAvg)H. Brendan McMahan, Eider Moore, Daniel Ramage, Seth Hampson, Blaise Agüera y Arcas (Google)Feb. 17, 2016AISTATS 2017
Towards Building the Federated GPT: Federated Instruction Tuning (FedIT)Jianyi Zhang, Saeed Vahidian, Martin Kuo, Chunyuan Li, Ruiyi Zhang, Tong Yu, Yufan Zhou, Guoyin Wang, Yiran Chen (Duke, Microsoft Research, Adobe Research, Amazon)May 9, 2023Condensed version at ICASSP 2024
OpenFedLLM: Training Large Language Models on Decentralized Private Data via Federated LearningRui Ye, Wenhao Wang, Jingyi Chai, Dihan Li, Zexi Li, Yinda Xu, Yaxin Du, Yanfeng Wang, Siheng Chen (Shanghai Jiao Tong Univ., Zhejiang Univ., Shanghai AI Lab)Feb. 10, 2024KDD 2024 (ACM DOI)

FedIT calls itself "the first exploration of FL-based instruction tuning for LLMs" (abstract).

What results did the federated tuning papers report?

FedAvg (2016): far fewer rounds than synchronized SGD. Across five model architectures and four datasets, the method was "robust to the unbalanced and non-IID data distributions" and cut the communication rounds needed by 10-100x compared with synchronized SGD (McMahan et al., abstract). One example: on CIFAR-10, a centralized SGD baseline reached 86% accuracy after 197,500 minibatch updates, each of which would be a communication round in the federated setting, while FedAvg reached 85% after 2,000 rounds (Sec. 3). A large-scale next-word test used 10 million public social-network posts grouped into over 500,000 clients.

FedIT (2023): beat local training, trailed centralized training. Setup: 100 clients built from Databricks-dolly-15k, 20 rounds, 5 clients (5%) per round, one local epoch each, LLaMA-7B with LoRA rank 8 on all linear layers (Zhang et al., Sec. 4.1). Per client: 17.9M trainable parameters (0.26%), 2 hours of training and 23GB of GPU memory on one NVIDIA Titan RTX (Table 2). The resulting model, Shepherd-7B, was scored by GPT-4 on 20 unseen Vicuna questions (Table 3):

BaselineBaseline scoreShepherd-7B scoreRelative score
Centralized tuning on all instructions142.2130.70.919
LLaMA-7B, no instruction tuning114.0131.71.155
Local-1 (brainstorming only)120.0131.01.092
Local-2 (closed QA only)116.1129.01.111
Local-3 (classification + brainstorming)121.3131.81.087

The authors write that the gap to centralized training is "partly attributed" to clients training on very different instruction distributions.

OpenFedLLM (2024): every FL algorithm beat local training. The framework covers federated instruction tuning and federated value alignment, 7 FL algorithms (FedAvg, FedProx, SCAFFOLD, FedAvgM, FedAdagrad, FedYogi, FedAdam), 8 training datasets and 30+ evaluation metrics (Ye et al., Sec. 3-4). Selected numbers, all with Llama2-7B:

TestLocal trainingFedAvgBest FL algorithmGPT-4
General instruction tuning, MMLU (Table 4)38.7045.1345.79 (FedYogi)not reported
General instruction tuning, MT-Bench avg (Table 4)2.8443.3463.488 (SCAFFOLD)not reported
Finance sentiment, avg accuracy over FPB, FiQA-SA, TFNS (Table 5)0.7220.8320.854 (SCAFFOLD)0.731

The paper also reports that training "only requires one single GPU and takes 1 - 2 hours per client for 100 communication rounds", and that "no FL algorithm can guarantee the best performance in all scenarios" (Sec. 1). It calls the finance result "the first time in the literature showing that FL can outperform GPT-4 at any dimension".

How is federated tuning different from multi-task and instruction tuning?

Federated tuning changes where training happens; multi-task tuning and instruction tuning change what data is trained on. They combine: FedIT is instruction tuning run federated, and FedIT's authors say client heterogeneity "can be a beneficial factor" because it diversifies the instructions (Zhang et al., Sec. 4.2).

Centralized fine-tuningFederated tuning
Where data livesPooled on the trainer's machinesStays with each client
What movesDataModel weights or updates (often LoRA only)
Main costComputeCommunication rounds (FedAvg's focus)
Data distributionCan be shuffled into IID batchesUnbalanced and non-IID by default
Result in FedITUpper bound (score 142.2)130.7, relative score 0.919

Which libraries support federated tuning?

Three maintained open-source frameworks document federated LLM fine-tuning, plus the papers' own code:

  • Flower (flwr, docs v1.45.x). Its FlowerTune LLM example "conducts federated instruction tuning with pretrained OpenLLaMA models on Alpaca-GPT4 dataset", using PEFT with bitsandbytes, 20 virtual clients and by default 2 clients per round for 100 rounds.
  • NVIDIA FLARE documents federated SFT and PEFT, including LoRA. Its Hugging Face integration patches a Transformers Trainer or TRL SFTTrainer "so existing trainer.evaluate() and trainer.train() calls can participate in FL rounds"; it also supports NVIDIA NeMo.
  • FATE-LLM describes itself as "a framework to support federated learning for large language models(LLMs) and small language models(SLMs)", with parameter-efficient training, FedIPR for model IP protection, and tutorials for methods such as Offsite-Tuning and FedKSeed.
  • Paper code: FedIT's Shepherd and OpenFedLLM.

How do you use federated tuning in code?

This is the server side of a federated LoRA run with Flower's current Message API. Names are checked against Flower's FedAvg, ArrayRecord and flwr.app reference pages (v1.45.x) and PEFT's get_peft_model_state_dict (v0.22.0).

from flwr.app import ArrayRecord, Context
from flwr.serverapp import Grid, ServerApp
from flwr.serverapp.strategy import FedAvg
from peft import LoraConfig, get_peft_model, get_peft_model_state_dict
from transformers import AutoModelForCausalLM

app = ServerApp()

@app.main()
def main(grid: Grid, context: Context) -> None:
    base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-0.6B")
    lora = LoraConfig(r=8, target_modules="all-linear", task_type="CAUSAL_LM")  # FedIT: rank 8, all linear layers
    model = get_peft_model(base, lora)

    # Only the LoRA adapter weights are sent out and averaged
    arrays = ArrayRecord(get_peft_model_state_dict(model))
    strategy = FedAvg(fraction_train=0.05)      # 5% of clients per round, as in FedIT
    strategy.start(grid=grid, initial_arrays=arrays, num_rounds=20)

Each client is a ClientApp whose @app.train() function loads the received weights (msg.content["arrays"].to_torch_state_dict()), trains on local data, and replies with a RecordDict holding "arrays" and "metrics", as in Flower's Hugging Face quickstart. By default FedAvg weights each client by the "num-examples" metric it reports (weighted_by_key), which matches the n_k weighting in the paper. Runs start with flwr run ..

Common pitfalls

  • Non-IID data hurts the averaged model. FedIT's federated model scored 0.919 relative to centralized training; the authors attribute part of the gap to clients learning "different representations" from very different instruction sets (Zhang et al., Sec. 4.2).
  • Too much local training. "For very large numbers of local epochs, FedAvg can plateau or diverge"; the authors suggest decaying the amount of local computation later in training (McMahan et al., Sec. 3).
  • No single best aggregator. OpenFedLLM found FedYogi and SCAFFOLD best for general data, SCAFFOLD for finance, and FedYogi below GPT-4 on FPB accuracy (0.820 vs 0.834) (Tables 4-5).
  • Federated is not the same as private. FedAvg's authors say "some trust of the server coordinating the training is still required", and list differential privacy and secure multi-party computation as ways to get "stronger guarantees" (Sec. 1 and Conclusions).

FAQ

What is the difference between federated learning and federated tuning?

Federated learning trains a model across clients that keep their data local (FedAvg, 2016). Federated tuning applies the same loop to fine-tuning a pretrained LLM, usually updating only adapter weights such as LoRA, as FedIT and OpenFedLLM do.

Does federated tuning keep data private?

Raw data never leaves a client, and only model updates are sent. FedAvg's authors note that the server must still be trusted to some degree and point to differential privacy and secure multi-party computation for stronger guarantees.

Is federated tuning as good as centralized fine-tuning?

Not in FedIT's test: its federated model scored 130.7 against 142.2 for a model trained on all the data centrally (relative score 0.919). It did beat every model trained on a single client's data.

Can a federated Llama 2 7B beat GPT-4?

On OpenFedLLM's financial sentiment benchmark, yes: FedAvg reached 0.832 average accuracy over three datasets against 0.731 for GPT-4. Locally trained models scored 0.722. This is one domain, not general ability.

Which framework should I use for federated LLM fine-tuning?

Flower, NVIDIA FLARE and FATE-LLM all document federated LLM fine-tuning with parameter-efficient methods. Flower's FlowerTune example and FLARE's Hugging Face integration both build on PEFT; FATE-LLM adds methods such as Offsite-Tuning and FedIPR.

Why use LoRA in federated tuning?

It shrinks what each round sends. In OpenFedLLM only 4.194M of Llama2-7B's 6,738M parameters (0.06%) were trained and communicated per round; in FedIT each client trained 17.9M parameters (0.26%).

Sources

Series: ← Prev: Multi-Task Tuning · All 15 techniques · Next: RLHF →

  • #llm-fine-tuning
  • #federated-learning
  • #federated-tuning
  • #data-strategy
  • #fedavg