Skip to content

Jagoul/FedTime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

arxiv Python 3.8+ PyTorch License: MIT Research Paper Publication DOI

Keywords: federated learning, large language models, time series forecasting, privacy preservation, LLaMA, LSTM, deep learning, machine learning, edge computing, distributed AI


Overview

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.

FedTime Federated Learning Framework for Time Series Forecasting with LLM

Figure 1: FedTime federated learning architecture with K-means clustering for EV charging stations

Key Contributions

  • 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

Performance Highlights

Time Series Forecasting Performance Comparison with Federated Learning

Figure 2: FedTime performance across different look-back window lengths L ∈ {24, 48, 96, 192, 336, 720}

πŸ“Š Quantitative Results

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% ↓

πŸ”§ Model Architecture

FedTime Large Language Model Architecture for Federated Time Series Forecasting

Figure 3: FedTime two-phase fine-tuning strategy with (a) Supervised fine-tuning and (b) Forecasting fine-tuning

πŸ— Core Components

  1. πŸ”„ Channel Independence: Processes each time series variable separately for better feature preservation
  2. πŸ“¦ Patching Strategy: Divides time series into patches for efficient LLM processing
  3. 🧠 LLaMA-2 Backbone: Leverages pre-trained LLaMA-2-7B with 7B parameters
  4. ⚑ QLoRA Fine-tuning: Parameter-efficient adaptation with only 1.2% trainable parameters
  5. 🎯 Direct Preference Optimization: Aligns model behavior with time series patterns
  6. 🀝 Federated Aggregation: Secure model update combination across clients

πŸ“ˆ Experimental Validation

🎯 Ablation Study Results

Ablation Study Results for Federated Learning Time Series Forecasting

Figure 4: Ablation study showing impact of different FedTime components on Caltech EV charging data

Key Findings:

  • βœ… Clustering + PEFT provides optimal performance-efficiency trade-off
  • βœ… PEFT alone significantly reduces communication overhead
  • βœ… Clustering alone improves model personalization

πŸ“Š Client Clustering Analysis

Before Clustering After Clustering
Time Series Forecasting Before K-means Clustering Time Series Forecasting After K-means Clustering

Figure 5: K-means clustering visualization showing client distribution based on cluster size and performance metrics


Communication Efficiency

Communication Overhead Analysis in Federated Learning for Time Series

Figure 6: Communication overhead comparison showing FedTime's superior efficiency

Efficiency 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

Quick Start

Installation

# 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

Dataset Preparation

# 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

Training & Evaluation

Federated Training (Recommended)

# 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'

πŸ“Š Centralized Baseline

# 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'

πŸ” Communication Analysis

# Analyze federated learning communication overhead
python analyze_communication.py \
  --num_clients 10 \
  --num_rounds 100 \
  --output_dir ./communication_analysis

πŸ“ Repository Structure

πŸ—‚οΈ 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

πŸ”¬ Reproducing Paper Results

Complete Experimental Suite

# 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

Comprehensive Ablation Studies

# 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'

πŸ—ƒοΈ Supported Datasets

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

πŸ› οΈ Customization & Extension

Adding Custom Datasets

# 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

Implementing New Aggregation Methods

# 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_method

πŸ“Š Citation

If 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}
}

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ”— Related Work

Paper Description Link
PatchTST A Time Series is Worth 64 Words GitHub
LLaMA Large Language Model Meta AI GitHub
QLoRA Efficient Finetuning of Quantized LLMs GitHub

⭐ Star this repository if you find it helpful!

GitHub stars GitHub forks


"Privacy-preserving collaborative intelligence for the future of time series forecasting"

Releases

No releases published

Packages

 
 
 

Contributors