This project contains all python code for the PHT-Medic Federated Learning project grouped into several packages.
protocols
: contains the cryptographic functionality required for the supported protocolsaggregator
: contains the aggregator REST API implementation, and server side storage for running protocolsclient
: implements a client to be used with the aggregator APItrainer
: contains the code for the client side training of modelsClone the repository and navigate into the root folder. Run
pip install -e .
Install poetry and run
poetry install --with dev --all-extras
to install the development dependencies.
to spin up all services run docker compose up -d
in the root folder.
docker compose up -d
If you want to start a specific service run docker compose up -d <service_name>
, with the name defined in the compose file.
Start the fastapi aggregator service with hot reloading using uvicorn:
When using the postgres db defined in the compose file, two databases are created. One to use for development and a
separate one for testing. The databases are created with the name aggregator
and aggregator_test
respectively.
The creation of these database is defined in the /scripts/init.sql
file.
The aggregator can be started in development mode with hot reloading using the following command:
poetry run uvicorn pht_federated.aggregator.app:app --reload --port 8000 --host 0.0.0.0
Create a branch/fork the repository and create a pull request to the main
branch to contribute to the project.
The CI pipeline will run all tests and checks on the code, before it can be merged.
To ensure a consistent code style and to prevent common mistakes, we use pre-commit hooks.
To install the hooks run poetry run pre-commit install
in the root folder of the project with the virtual environment activated
and the dev dependencies installed.
This project uses black for code formatting. Run to format your code before pushing it to the remote repository.
poetry run black .
Linting is done with ruff
poetry run ruff . --fix
Mask based secure aggregation protocol. Implementation and extension of the paper Practical Secure Aggregation for Privacy-Preserving Machine Learning