Skip to content

Latest commit

Β 

History

History
96 lines (70 loc) Β· 3.23 KB

File metadata and controls

96 lines (70 loc) Β· 3.23 KB

DAGFed: A Dual-Perturbation and Adaptive Graph Framework for Secure and Robust Distributed Learning

This repository contains the official implementation of DAG_Fed, a federated learning framework integrating Dynamic Adaptive Gradient Clipping (DAGC) and Hierarchical Differential Privacy (HDP) to improve both privacy protection and model utility under heterogeneous (non-IID) data distributions.


πŸ“Œ Features

  • Dynamic Client Selection & Adaptive Gradient Clipping β€” Mitigates statistical heterogeneity by adaptively tuning gradient norms per client.
  • Hierarchical Differential Privacy (HDP) β€” Multi-level noise injection for balanced privacy–utility trade-off.
  • Modular Aggregator β€” Supports FedAvg, SCAFFOLD, and custom aggregation strategies.
  • Flexible Data Partitioning β€” IID and non-IID splits via Dirichlet sampling.
  • Reproducible Experiments β€” Unified config file and logging system.

πŸ“‚ Project Structure

DAGC_HDP_Federated_Learning/
β”‚
β”œβ”€β”€ config.py                 # Global configuration: hyperparameters, DP budget, scenarios
β”œβ”€β”€ main.py                   # Main entry: training orchestration, global loop
β”‚
β”œβ”€β”€ clients/
β”‚   β”œβ”€β”€ client.py             # Client base class: data loading, local training, DAGC
β”‚   β”œβ”€β”€ dp_utils.py           # DP utilities: gradient clipping, noise injection
β”‚   β”œβ”€β”€ noise_scheduler.py    # Dynamic noise scheduling
β”‚
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ aggregator.py         # Aggregators (FedAvg, SCAFFOLD, etc.)
β”‚   β”œβ”€β”€ privacy_accountant.py # DP budget tracking, RDP accounting
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ model_cnn.py          # CNN model for vision datasets (CIFAR-10, MNIST)
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ data_loader.py        # Dataset loading & non-IID partitioning
β”‚   β”œβ”€β”€ datasets/             # Dataset storage
β”‚
β”œβ”€β”€ experiments/
β”‚   β”œβ”€β”€ logger.py             # Logging utilities
β”‚   β”œβ”€β”€ metrics.py            # Accuracy, F1, MSE calculation
β”‚   β”œβ”€β”€ attack_test.py        # Privacy attack evaluation scripts
β”‚
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ helper.py             # General utilities (seed, save/load, etc.)
β”‚   β”œβ”€β”€ plots.py              # Visualization of results
β”‚
β”œβ”€β”€ README.md                 # Project documentation
└── requirements.txt          # Python dependencies

βš™οΈ Installation

1. Clone the repository

git clone https://github.com/dxpython/DAG_Fed.git
cd DAG_Fed

2. Create a Python environment

conda create -n DAG_Fed python=3.9
conda activate DAG_Fed

πŸš€ Usage

Run a CIFAR-10 experiment with 10 clients, 100 rounds, and a privacy budget of Ξ΅ = 1.0:

python main.py --dataset cifar10 --rounds 100 --clients 10 --epsilon 1.0

Key Arguments:

  • --dataset : cifar10, cifar100, mnist, fashionmnist
  • --rounds : Number of global communication rounds
  • --clients : Number of participating clients
  • --epsilon : Privacy budget for DP
  • Additional parameters can be set in config.py