Keywords: federated learning, large language models, time series forecasting, privacy preservation, LLaMA, LSTM, deep learning, machine learning, edge computing, distributed AI
FedTime addresses critical challenges in centralized time series forecasting by introducing an End-to-end federated learning framework that leverages Large Language Models for privacy-preserving, collaborative time series prediction across distributed edge devices.
- Federated LLM Framework for time series forecasting
- π― K-means Clustering for intelligent client grouping and focused training
- π§ Parameter-Efficient Fine-tuning (QLoRA) reducing communication by 80%
- π Superior Performance with up to 20% improvement over state-of-the-art
- π Privacy Preservation keeping sensitive data on edge devices
- β‘ 3Γ Faster Convergence compared to centralized approaches
Figure 2: FedTime performance across different look-back window lengths L β {24, 48, 96, 192, 336, 720}
| Dataset | Method | MSE (T=720) | MAE (T=720) | Improvement |
|---|---|---|---|---|
| Traffic | LLM4TS | 0.437 | 0.292 | - |
| FedTime | 0.369 | 0.239 | π₯ 15.56% β | |
| Electricity | LLM4TS | 0.220 | 0.292 | - |
| FedTime | 0.176 | 0.288 | π₯ 20.0% β | |
| ETTm1 | LLM4TS | 0.408 | 0.419 | - |
| FedTime | 0.328 | 0.373 | π₯ 10.98% β |
Figure 3: FedTime two-phase fine-tuning strategy with (a) Supervised fine-tuning and (b) Forecasting fine-tuning
- π Channel Independence: Processes each time series variable separately for better feature preservation
- π¦ Patching Strategy: Divides time series into patches for efficient LLM processing
- π§ LLaMA-2 Backbone: Leverages pre-trained LLaMA-2-7B with 7B parameters
- β‘ QLoRA Fine-tuning: Parameter-efficient adaptation with only 1.2% trainable parameters
- π― Direct Preference Optimization: Aligns model behavior with time series patterns
- π€ Federated Aggregation: Secure model update combination across clients
Key Findings:
- β Clustering + PEFT provides optimal performance-efficiency trade-off
- β PEFT alone significantly reduces communication overhead
- β Clustering alone improves model personalization
| Before Clustering | After Clustering |
|---|---|
![]() |
![]() |
Figure 5: K-means clustering visualization showing client distribution based on cluster size and performance metrics
- π 80% Reduction in communication overhead vs. full fine-tuning
- β‘ 3Γ Faster convergence than centralized training
- π 100% Privacy preservation with local data processing
- π± Edge-Friendly deployment on resource-constrained devices
# Clone the federated learning repository
git clone https://github.com/Jagoul/FedTime-A-Federated-Large-Language-Model-for-Long-Term-Time-Series-Forecasting.git
cd FedTime
# Create conda environment for federated time series forecasting
conda create -n fedtime python=3.8
conda activate fedtime
# Install dependencies for large language model training
pip install -r requirements.txt# Download benchmark time series datasets
bash scripts/download_datasets.sh
# Verify time series dataset structure
ls dataset/ETT-small/
# Expected: ETTh1.csv ETTh2.csv ETTm1.csv ETTm2.csv# Run federated learning for time series forecasting
python run_federated.py \
--is_training 1 \
--data ETTh1 \
--model FedTime \
--seq_len 96 \
--pred_len 192 \
--num_clients 10 \
--num_rounds 100 \
--local_epochs 5 \
--use_clustering 1 \
--num_clusters 3 \
--use_peft 1 \
--peft_method qlora \
--des 'FedTime_ETTh1'# Run centralized baseline for time series forecasting comparison
python run_longExp.py \
--is_training 1 \
--data ETTh1 \
--model FedTime \
--seq_len 96 \
--pred_len 192 \
--des 'Centralized_ETTh1'# Analyze federated learning communication overhead
python analyze_communication.py \
--num_clients 10 \
--num_rounds 100 \
--output_dir ./communication_analysisποΈ Click to expand file structure
FedTime/
βββ π figures/ # Paper figures and visualizations
β βββ actual_predicted.png # Actual vs predicted results
β βββ communication_overhead.pdf # Communication analysis
β βββ communication_overhead.png # Communication analysis
β βββ Forecasting_performance.pdf # Performance comparison
β βββ Forecasting_performance.png # Performance comparison
β βββ with_clustering.pdf # Clustering impact analysis
β βββ with_clustering.png # Clustering impact analysis
β βββ no_clustering.pdf # No clustering baseline
β βββ no_clustering.png # No clustering baseline
β βββ FedTime_Framework.pdf # Framework architecture
β βββ FedTime_Framework.png # Framework architecture
β βββ LLM_Architecture.pdf # Model architecture details
β βββ LLM_Architecture.png # Model architecture details
βββ π data_provider/ # Dataset storage directory
β βββ data_factory.py
β βββ data_provider_init.py
βββ π exp/ # Experiment runners
β βββ exp_basic.py # Base experiment class
β βββ federated_experiments.py # Federated experiment handler
βββ π layers/ # Model layers and components
β βββ Transformer_EncDec.py # Transformer encoder/decoder
β βββ SelfAttention_Family.py # Attention mechanisms
β βββ layers_init.py # Attention mechanisms
β βββ Embed.py # Embedding layers
βββ π models/ # Model implementations
β βββ FedTime.py # Main FedTime model
β βββ __init__.py # Package initialization
βββ π scripts/ # Training and evaluation scripts
β βββ ablation_study_scripts.sh # Ablation study
β βββ analyze_communications.py # Communication Overhead
β βββ training_scripts.sh # Training utilities
β βββ download_datasets.sh # Dataset download automation
βββ π federated/ # Federated learning components
β βββ federated_client.py # Federated client implementation
β βββ federated_server.py # Federated server with clustering
β βββ federated_aggregation.py # FedAvg, FedAdam, FedOpt
β βββ clustering_component.py # K-means clustering utilities
βββ π utils/ # Utility functions
β βββ utils_tools.py # Training utilities and early stopping
β βββ utils_init.py # Training utilities to initiate the script
β βββ utils_metrics.py # Evaluation metrics (MSE, MAE, etc.)
β βββ utils_timefeatures.py # Time feature engineering
βββ π main/ # Core scripts
| βββ run_longExp.py # Main training script
| βββ run_federated.py # Federated training script
βββ π setup/ # Experiment Setup
| βββ requirements.txt # Dependencies
| βββ README.md # This file
# Run all benchmark experiments for federated time series forecasting
bash scripts/FedTime/federated_training.sh
# Individual time series dataset experiments
bash scripts/FedTime/ETTh1.sh # Electricity Transformer Temperature
bash scripts/FedTime/Weather.sh # Meteorological data
bash scripts/FedTime/Traffic.sh # California traffic data
bash scripts/FedTime/Electricity.sh # Power consumption data# Component ablation for federated learning
python run_federated.py --use_clustering 0 --des 'NoClustering'
python run_federated.py --use_peft 0 --des 'NoPEFT'
python run_federated.py --use_dpo 0 --des 'NoDPO'
# Hyperparameter sensitivity for large language models
python run_federated.py --num_clusters 2 --des 'Clusters2'
python run_federated.py --num_clusters 5 --des 'Clusters5'
python run_federated.py --peft_method lora --des 'LoRA'| Dataset | Features | Timesteps | Granularity | Domain |
|---|---|---|---|---|
| ETTh1/h2 | 7 | 17,420 | 1 hour | β‘ Energy |
| ETTm1/m2 | 7 | 69,680 | 15 min | β‘ Energy |
| Weather | 21 | 52,696 | 10 min | π€οΈ Weather |
| Traffic | 862 | 17,544 | 1 hour | π Transportation |
| Electricity | 321 | 26,304 | 1 hour | π Smart Grid |
# 1. Create data loader in data_provider/data_loader.py for time series data
class Dataset_Custom(Dataset):
def __init__(self, root_path, data_path, flag='train', ...):
# Your custom time series dataset implementation
pass
# 2. Register in data_provider/data_factory.py for federated learning
data_dict['your_dataset'] = Dataset_Custom
# 3. Run federated training for time series forecasting
python run_federated.py --data your_dataset --model FedTime# Add to federated/aggregation.py for federated learning
class YourAggregator(FederatedAggregator):
def aggregate(self, client_updates, client_weights, global_params):
# Your federated aggregation logic for time series models
return aggregated_params
# Use in federated training for time series forecasting
python run_federated.py --aggregation_method your_methodIf you find FedTime useful for your research, please cite our paper:
@inproceedings{abdel2024federated,
title={A federated large language model for long-term time series forecasting},
author={Abdel-Sater, Raed and Ben Hamza, A},
booktitle={ECAI 2024},
pages={2452--2459},
year={2024},
keywords={federated learning, large language models, time series forecasting, privacy preservation, LLaMA, distributed AI}
}This project is licensed under the MIT License - see the LICENSE file for details.
| Paper | Description | Link |
|---|---|---|
| PatchTST | A Time Series is Worth 64 Words | |
| LLaMA | Large Language Model Meta AI | |
| QLoRA | Efficient Finetuning of Quantized LLMs |




