NanoFed - Federated Learning Library

GitHub Actions Workflow Status Read the Docs GitHub License PyPI - Python Version PyPI - Status

Beta Release

NanoFed is currently in beta. APIs may change in future versions.

Overview

NanoFed is a lightweight, modular federated learning library. Built on PyTorch, it enables distributed model training while preserving data privacy.

Quick Installation
pip install nanofed
poetry install nanofed  # Using poetry

Key Features

🔒 Privacy First
  • Client data never leaves local devices

  • Secure model update transmission

  • Privacy-preserving aggregation

🚀 Easy to Use
  • Simple, intuitive API

  • PyTorch integration

  • Clear documentation

🔧 Flexible
  • Custom model support

  • Pluggable aggregation strategies

  • Extensible architecture

💻 Production Ready
  • Async communication

  • Robust error handling

  • Comprehensive logging

Quick Example

Train a model using federated learning in just a few lines of code:

Basic Training Setup
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import asyncio
from pathlib import Path

from nanofed import HTTPClient
from nanofed import TorchTrainer, TrainingConfig

async def run_client(client_id: str, server_url: str):
   training_config = TrainingConfig(
      epochs=1,
      batch_size=256,
      learning_rate=0.1
   )
   async with HTTPClient(server_url, client_id) as client:
      model_state, _ = await client.fetch_global_model()
      await client.submit_update(model, metrics)


if __name__ == "__main__":
   asyncio.run(run_client("client1", "http://localhost:8080"))

Components

The client component handles local training and server communication:

  • Local model training

  • Secure update submission

  • Data privacy preservation

  • Training metrics collection

The server coordinates the federated process:

  • Global model distribution

  • Update aggregation

  • Training coordination

  • Client synchronization

The coordinator manages the overall training process:

  • Round management

  • Client tracking

  • Progress monitoring

  • Checkpointing

Installation

Basic Installation

Install using pip:

pip install nanofed
Development Installation

For development:

git clone https://github.com/camille-004/nanofed.git
cd nanofed
make install

Requirements

Required Dependencies

  • Python >=3.10

  • PyTorch

  • aiohttp

  • pydantic

Getting Help

🐛 Issue Tracker

Report bugs and request features on our GitHub issue tracker.

https://github.com/camille-004/nanofed/issues
📚 Documentation

Read our comprehensive documentation and guides.

https://nanofed.readthedocs.io
📖 Source Code

Browse the source code on GitHub.

https://github.com/camille-004/nanofed

Warning

This is a beta release. While the core functionality is stable, APIs may change in future versions. Please report any issues you encounter.

License

NanoFed is available under the GPL-3.0 License.