A Flower-based federated learning framework supporting MLP, CNN, and Spiking Neural Networks (SNN) under both IID and Non-IID data distributions.
- Model Types: MLP, CNN, SNN
- Federated Strategies: FedAvg, FedProx, FedAdagrad, FedAdam
- Datasets: MNIST, CIFAR-10
- Distribution Options: IID & Non-IID
- GPU Support: CUDA acceleration available
- Advanced Features: LR scheduling, gradient clipping, automatic strategy recommendations
# Clone the repository
git clone https://github.com/RA-Nayreed/federated-multiarch-ml.git
cd federated-multiarch-ml
# Install dependencies
## CPU-only (default)
pip install -r requirements.txt
## GPU (CUDA 11.8)
1. Open `requirements.txt` and **comment out** the following lines:
torch
torchvision
torchaudio
2. Install PyTorch with CUDA 11.8:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
3. Then install the remaining dependencies:
pip install -r requirements.txt
- 4-layer fully connected network (512→256→128→classes)
- ReLU activation with dropout regularization
- Suitable for both MNIST and CIFAR-10
- MNIST: 3 convolutional blocks (2 conv layers per block) with BatchNorm + LeakyReLU; downsampling via stride=2 in blocks 2 and 3 (no MaxPooling); Dropout2d after each block; Global Average Pooling before fully connected layers
- CIFAR-10: 3 conv blocks with strided downsampling (no MaxPooling): [3→64, 64→128 (stride 2)] → [128→256, 256→256 (stride 2)] → [256→512, 1×1→256]; Adaptive Avg Pool to (1,1); 3 FC layers (256→192→128→classes) with LeakyReLU and dropout
- Batch normalization throughout; downsampling via strided conv; global/adaptive average pooling before FC
- MNIST: 3-layer fully connected SNN with Leaky Integrate-and-Fire neurons
- CIFAR-10: Convolutional SNN with temporal dynamics
- Configurable time steps (default: 25-30)
- Surrogate gradient learning with membrane potential tracking
| Strategy | Best For | Description |
|---|---|---|
fedavg |
IID data | Standard federated averaging |
fedprox |
Non-IID data | Proximal regularization for heterogeneous clients |
fedadagrad |
Adaptive learning | Adaptive gradient-based optimization |
fedadam |
Complex optimization | Adam-based federated learning |
| Argument | Default | Description |
|---|---|---|
--epochs |
40 | Number of federated rounds |
--num_users |
10 | Number of clients |
--frac |
1.0 | Fraction of clients per round |
--local_ep |
6 | Local training epochs |
--local_bs |
32 | Local batch size |
--lr |
0.01 | Learning rate (auto-adjusted per model) |
--model |
snn | Model type: mlp, cnn, snn |
--dataset |
mnist | Dataset: mnist, cifar10 |
--strategy |
fedavg | FL strategy: fedavg, fedprox, fedadagrad, fedadam |
--iid |
False | Use IID data distribution |
--gpu |
False | Enable GPU acceleration |
| Argument | Default | Description |
|---|---|---|
--snn_timesteps |
25 | SNN simulation time steps |
--fedprox_mu |
0.1 | FedProx proximal term coefficient |
--use_lr_scheduler |
False | Enable learning rate scheduling |
--warmup_epochs |
5.0 | Warmup epochs for LR scheduler |
federated-multiarch-ml/
├── main.py # Main federated learning implementation
├── models.py # Neural network model definitions
├── strategy.py # Flower client and strategy implementations
├── utils.py # Utility functions for data and model handling
├── training.py # Interactive training launcher
├── confusion_mat.py # confusion matrix and result log creator
├── requirements.txt # Python dependencies
├── README.md # This file
├── RESULTS.md # Contains result log
├── models/ # Saved models (created automatically)
├── data/ # Dataset cache (created automatically)
├── results/ # Confusion matrix & log (created automatically)
└── resources/ # Folder containing learning materials about the repo
└── Strategy.pdf # Deep understanding of stategy.py
Detailed confusion matrix and classification reports are available in RESULTS.md.
| Dataset | Model | Strategy | Clients | Rounds | Data | Accuracy | Local Epochs | Local Batch Size |
|---|---|---|---|---|---|---|---|---|
| MNIST | SNN | FedAvg | 10 | 30 | IID | 91.98% | 2 | 32 |
| MNIST | SNN | FedProx | 10 | 40 | Non-IID | 86.69% | 2 | 32 |
python training.pyChoose from 12 predefined configurations covering all model-dataset combinations.
# -----------------------------
# Basic & Quick Training Examples
# -----------------------------
# SNN on MNIST with 10 clients (IID)
python main.py --model snn --dataset mnist --epochs 15 --num_users 10 --iid --gpu
# CNN on CIFAR-10 with 16 clients (Non-IID)
python main.py --model cnn --dataset cifar10 --epochs 20 --num_users 16 --gpu
# CNN on MNIST with FedProx strategy
python main.py --model cnn --dataset mnist --strategy fedprox --fedprox_mu 0.1 --epochs 30 --gpu
# -----------------------------
# Advanced Training Examples
# -----------------------------
# FedAvg SNN on MNIST with custom timesteps and scheduler
python main.py --model snn --dataset mnist --strategy fedavg --epochs 25 --num_users 10 --iid --snn_timesteps 25 --gpu --lr 0.001 --local_ep 2 --local_bs 32 --use_lr_scheduler --warmup_epochs 3
# FedProx SNN on MNIST with strong proximal term
python main.py --model snn --dataset mnist --strategy fedprox --fedprox_mu 1.0 --epochs 30 --num_users 10 --snn_timesteps 25 --gpu --lr 0.001 --local_ep 2 --local_bs 32 --use_lr_scheduler --warmup_epochs 5
# FedAdagrad SNN on MNIST
python main.py --model snn --dataset mnist --strategy fedadagrad --epochs 30 --num_users 10 --snn_timesteps 25 --gpu --lr 0.001 --local_ep 2 --local_bs 32 --use_lr_scheduler --warmup_epochs 3
# FedAdam SNN on MNIST
python main.py --model snn --dataset mnist --strategy fedadam --epochs 30 --num_users 10 --snn_timesteps 25 --gpu --lr 0.0005 --local_ep 2 --local_bs 32 --use_lr_scheduler --warmup_epochs 3
- Python 3.8+
- PyTorch 1.9+
- Flower 1.0+
- SNNTorch (for SNN models)
- See requirements.txt for complete list
- GPU Usage: Use
--gpuflag for CUDA acceleration - Memory Optimization: Reduce
--local_bsif encountering OOM errors - Non-IID Data: Use
--strategy fedproxfor better performance - SNN Training: Lower learning rates work better (auto-adjusted)
- Convergence: Enable
--use_lr_schedulerfor better training dynamics
- CUDA Out of Memory: Reduce batch size or number of clients
- Poor Convergence: Try different strategies or enable LR scheduling
- Data Distribution Warnings: Normal for non-IID scenarios
This project is licensed under the MIT License - see the LICENSE file for details.
- Flower — for the federated learning infrastructure
- SNNTorch — for spiking neural network modeling
- PyTorch — for the deep learning backend
- OpenAI ChatGPT — for assistance in code debugging, design.
- Anthropic Claude — for research support, code suggestions, and implementation guidance
- Cursor AI — for enhanced code documentation and developer productivity
Parts of this project were developed with assistance from AI tools (ChatGPT & Claude). All code was verified, tested, and curated manually.