A privacy-preserving federated learning system with cluster shuffling, SMPC, and gradient pruning for communication-efficient, secure distributed training.
# Install
git clone https://github.com/Tanguyvans/cluster-shuffling-fl.git
cd cluster-shuffling-fl
pip3 install -r requirements.txt
# Run
python3 main.pyResult: Federated learning on CIFAR-10 with 6 clients, 10 rounds, 80% communication savings from gradient pruning!
π New to FL? β Quickstart Guide
- π Cluster Shuffling: Dynamic client reorganization prevents long-term inference
- π SMPC: Secret sharing (additive & Shamir's) protects model updates
- π‘οΈ Differential Privacy: Calibrated noise for formal privacy guarantees
- π Gradient Pruning (NEW!): 80% communication reduction via Deep Gradient Compression (DGC)
- β‘ Top-k Sparsification: Send only 10% of gradients with momentum correction
- π Compatible: Works with SMPC, DP, and all privacy mechanisms
- βοΈ Poisoning Attacks: 6 attack types (Label Flip, IPM, ALIE, Backdoor, etc.)
- π Privacy Attacks: Gradient inversion, membership inference
- π Comprehensive Metrics: PSNR, accuracy, communication overhead
- Krum, Multi-Krum
- Trimmed Mean, Median
- FLTrust - Trust-based aggregation
- Installation Guide - Setup & dependencies
- Quickstart (5 min) - First FL experiment
- Configuration - Complete config.py reference
- Gradient Pruning - 80% communication savings
- Privacy Defenses - SMPC, DP, Clustering
- Aggregation Methods - Krum, FLTrust, etc.
- Poisoning Attacks - 6 attack types
- Gradient Inversion - Privacy attacks
- Pruned Models - Attack comparison
- Communication Metrics - Measure pruning impact
# Test gradient pruning impact
"gradient_pruning": {"enabled": True, "keep_ratio": 0.1}
python3 main.py
# Compare attack resistance
python3 run_grad_inv.py --config aggressive# Enable all privacy mechanisms
"diff_privacy": True,
"clustering": True,
"type_ss": "shamir",
"gradient_pruning": {"enabled": True}# Test poisoning attacks
"poisoning_attacks": {
"enabled": True,
"malicious_clients": ["c0_1"],
"attack_type": "ipm",
"attack_intensity": 0.5
}| Method | Compression | Savings | Accuracy Impact |
|---|---|---|---|
| Baseline | 1.0x | 0% | - |
| Gradient Pruning (k=0.1) | 5.0x | 80% | <1% |
| Pruning (k=0.05) | 10.0x | 90% | ~2% |
| Defense | Gradient Inversion PSNR | Privacy Level |
|---|---|---|
| None | 28 dB | β Vulnerable |
| SMPC | 18 dB | β Moderate |
| SMPC + Pruning | 15 dB | β Strong |
| SMPC + DP | 12 dB | β β Very Strong |
| Defense | IPM Attack Impact | Label Flip Impact |
|---|---|---|
| FedAvg | -40% accuracy | -35% accuracy |
| Krum | -13% accuracy | -8% accuracy |
| Krum + Clustering | -4% accuracy | -2% accuracy |
βββββββββββββββ
β Clients β βββΊ Local Training
βββββββββββββββ
β
ββββΊ Gradient Pruning (80% reduction)
β
ββββΊ SMPC Secret Sharing
β
βΌ
βββββββββββββββ
β Aggregation β βββΊ Krum / FedAvg / FLTrust
βββββββββββββββ
β
βΌ
βββββββββββββββ
β Global Modelβ βββΊ Broadcast to Clients
βββββββββββββββ
Edit config.py for quick customization:
# Dataset & Model
"name_dataset": "cifar10", # cifar10, cifar100, ffhq128
"arch": "simplenet", # simplenet, resnet18, mobilenet
# Federated Learning
"n_rounds": 10, # Training rounds
"number_of_clients_per_node": 6,# Clients per node
# Gradient Pruning (NEW!)
"gradient_pruning": {
"enabled": True, # 80% communication savings
"keep_ratio": 0.1, # Keep 10% of gradients
}
# Privacy
"diff_privacy": True, # Enable DP
"clustering": True, # Cluster shuffling
# Aggregation
"aggregation": {
"method": "krum", # fedavg, krum, fltrust
}π Complete Configuration Guide
cluster-shuffling-fl/
βββ main.py # Main FL orchestrator
βββ config.py # Configuration settings
β
βββ docs/ # π Documentation
β βββ getting-started/ # Installation, quickstart, config
β βββ features/ # Gradient pruning, privacy, etc.
β βββ attacks/ # Poisoning, gradient inversion
β βββ measurement/ # Metrics and evaluation
β
βββ federated/ # FL implementation
β βββ client.py # Client training
β βββ server.py # Server aggregation
β βββ flower_client.py # Flower wrapper
β
βββ security/ # Privacy mechanisms
β βββ secret_sharing.py # SMPC implementation
β βββ gradient_pruning.py # DGC implementation
β
βββ attacks/poisoning/ # Attack framework
β βββ labelflip_attack.py
β βββ ipm_attack.py
β βββ ...
β
βββ models/architectures/ # Neural network models
βββ simplenet.py
βββ resnet.py
βββ ...
# Test gradient pruning
python3 test_gradient_pruning.py
# Run gradient inversion attack
python3 run_grad_inv.py --config default
# Measure communication savings
python3 measure_communication.py --keep-ratio 0.1This framework implements and evaluates:
- Deep Gradient Compression (Lin et al., ICLR 2018)
- Cluster Shuffling for federated learning
- Byzantine-robust aggregation (Krum, Trimmed Mean)
- Gradient inversion attacks (DLG, iDLG, GIAS, GIFD)
See Research Papers for full citations.
Contributions are welcome! Areas for improvement:
- Additional attack implementations
- More aggregation methods
- Enhanced privacy mechanisms
- Documentation improvements
This project is released under the MIT License. See LICENSE for details.
- Flower - Federated learning framework
- Opacus - Differential privacy library
- PyTorch - Deep learning framework
For questions or collaborations:
- GitHub Issues: Create an issue
- Email: [Your email]
π Ready to get started? β Quickstart Guide