Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3701d05
Restructure into krum package and add packaging
ArthurDanjou Apr 29, 2026
84c9172
Add uv.lock, pre-commit config and whitelist krum
ArthurDanjou Apr 29, 2026
80b998c
Update ci.yml
ArthurDanjou Apr 29, 2026
430f347
Update package versions in ci.yml
ArthurDanjou Apr 29, 2026
75747de
Update ci.yml
ArthurDanjou Apr 29, 2026
0e18944
Add ty, document PyPI install, fix CI branches
ArthurDanjou May 4, 2026
ff118fa
Update uv.lock
ArthurDanjou May 4, 2026
ca32684
Lint and format code
ArthurDanjou May 4, 2026
c016c28
Merge main branch into 9-feature-pip-installable
ArthurDanjou May 4, 2026
804ed17
Add docstrings, type hints, and modernize code
ArthurDanjou May 4, 2026
d25dd52
fix imports
ArthurDanjou May 4, 2026
c152b58
Fix imports
ArthurDanjou May 4, 2026
cf632a4
Refactor job runner and tidy imports
ArthurDanjou May 4, 2026
f576cb2
Format code
ArthurDanjou May 4, 2026
72b4e80
Remove checks in ci and move them to pre-commit
ArthurDanjou May 4, 2026
6fd0de9
Fix lint
ArthurDanjou May 4, 2026
49d74d3
Document native compilation and update docs tooling
ArthurDanjou May 4, 2026
7db0945
Fix typings
ArthurDanjou May 4, 2026
99883e8
Move public API imports next to __all__
ArthurDanjou May 4, 2026
404c129
Fix doc
ArthurDanjou May 4, 2026
5de9eba
Update contributors.rst
ArthurDanjou May 4, 2026
c93b91a
Update ci.yml
ArthurDanjou May 4, 2026
bd67208
Change uv sync command for doc
ArthurDanjou May 4, 2026
9571ced
Uniformisation des noms des workflows steps
ArthurDanjou May 4, 2026
6dfb23d
Update pytorch.py
ArthurDanjou May 4, 2026
8a192be
Lint docstrings
ArthurDanjou May 4, 2026
5b8324b
Update .pre-commit-config.yaml
ArthurDanjou May 4, 2026
c194577
Update .pre-commit-config.yaml
ArthurDanjou May 4, 2026
d44f380
update scripts
ArthurDanjou May 4, 2026
6577c56
update scripts
ArthurDanjou May 4, 2026
7c45efb
Update documentation.yml
ArthurDanjou May 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- name: Checkout
uses: actions/checkout@v6.0.2

- name: Install uv
uses: astral-sh/setup-uv@v8.1.0
with:
python-version: ${{ matrix.python-version }}
enable-cache: true

- name: Cache native builds
uses: actions/cache@v5.0.5
with:
path: krum/native
key: native-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('krum/native/**/*.cpp', 'krum/native/**/*.cu', 'krum/native/**/*.hpp', 'uv.lock') }}

- name: Install dependencies
run: uv sync --extra dev

- name: Check imports (no deprecation warnings)
run: |
uv run python -W error::DeprecationWarning -W error::PendingDeprecationWarning -c "from krum import tools, experiments, aggregators, attacks"
uv run python -W error::DeprecationWarning -W error::PendingDeprecationWarning -c "import krum.tools, krum.experiments, krum.aggregators, krum.attacks"
6 changes: 2 additions & 4 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Build and Deploy Documentation

on:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: read
Expand Down Expand Up @@ -32,7 +30,7 @@ jobs:
python-version-file: "pyproject.toml"

- name: Install dependencies
run: uv sync --group docs
run: uv sync --extra dev

- name: Build documentation
run: uv run sphinx-build -b html docs docs/_build/html
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish

on:
push:
tags:
- "v*"

jobs:
pypi:
name: Build & Publish to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write # Required for trusted publishing (recommended)
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Build package
run: uv build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

# Except directories, placeholders, gitignores, LICENSE, Markdown files and Python sources
!*/
!krum/*
!.placeholder
!.gitignore
!LICENSE
!*.md
!*.py
!*.toml
!.python-version
!uv.lock
!.pre-commit-config.yaml

# Except documentation files
docs/_build
!*.rst
!Makefile
!*.html
!*.css
!*.js
Expand All @@ -24,4 +28,4 @@ docs/_build
!*.yml

# IDE stuff
.idea
.idea
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.12
hooks:
- id: ruff
args: [--fix]
files: ^krum/
- id: ruff-format
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
>=3.10
>=3.10, <3.15
78 changes: 72 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,46 @@ This project implements various Byzantine-resilient Gradient Aggregation Rules (
- **Extensible**: Easy to add new aggregation rules or attacks.
- **High-performance**: Optional native C++ backend for Krum.

## Supported Python versions

This project supports Python **3.10 through 3.14**.

## Installation

This project uses `uv` for dependency management.
### From PyPI

```bash
pip install krum
```

With `uv` (Recommended):

```bash
# Clone the repository
git clone https://github.com/your-username/krum.git
uv pip install krum
# or directly in a uv project
uv add krum
```

### From source

For development or if you want to modify the source, clone the repository and install in editable mode with the development dependencies:

```bash
git clone https://github.com/calicarpa/krum.git
cd krum
pip install -e ".[dev]"
```

With `uv` (Recommended):

# Install dependencies
uv pip install -e .
```bash
git clone https://github.com/calicarpa/krum.git
cd krum
uv sync --extra dev
```

This installs all linting, type-checking, and documentation tools.

## Usage

You can run training simulations using `train.py`. The script accepts numerous arguments to configure the experiment.
Expand Down Expand Up @@ -71,6 +98,45 @@ uv run python train.py \

- *in progress*

## Contributing

### Linting, formatting, and type-checking

This project uses [Ruff](https://docs.astral.sh/ruff/) for unified linting and formatting, and [ty](https://github.com/astral-sh/ty) for type-checking.

Run the formatter and linter:

```bash
ruff format .
ruff check --fix .
```

Run the type checker:

```bash
ty check
```

### Pre-commit hooks

Install pre-commit hooks to block non-compliant commits:

```bash
pre-commit install
```

### Documentation

Build the documentation locally:

```bash
cd docs
make html #
make watch #
make serve #
make clean #
```

## License

See [LICENSE](LICENSE) for details.
MIT License — see [LICENSE](LICENSE).
11 changes: 7 additions & 4 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# Makefile for Krum documentation

.PHONY: help html clean servedocs live watch
.PHONY: help html build clean serve watch

help:
@echo "Available targets:"
@echo " html - Build HTML documentation"
@echo " build - Build HTML documentation (alias for html)"
@echo " clean - Remove generated files"
@echo " servedocs - Build and serve static documentation"
@echo " serve - Build and serve static documentation"
@echo " watch - Watch for changes and serve (auto-rebuild)"

html:
uv run sphinx-build -b html . _build/html

build: html

clean:
rm -rf _build

servedocs:
serve:
uv run sphinx-build -b html . _build/html && uv run python -m http.server 8000 -d _build/html

watch:
uv run sphinx-autobuild -b html . _build/html --port 8000 --host 127.0.0.1
uv run sphinx-autobuild -b html . _build/html --port 8000 --host 127.0.0.1
5 changes: 5 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@

.bd-toc .page-toc + .sidebar-secondary-item {
display: none;
}

/* Contributions Avatar */
.sphinx-contributors img {
border-radius: 50%;
}
14 changes: 9 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import importlib
import os
import sys

sys.path.insert(0, os.path.abspath(".."))

# Make krum submodules available as top-level imports for autodoc compatibility
for _mod in ("aggregators", "attacks", "experiments", "native", "tools"):
sys.modules[_mod] = importlib.import_module(f"krum.{_mod}")

project = "Krum, the Library"
copyright = "2026"
author = "Peva BLANCHARD, Arthur DANJOU, El-Mahdi EL-MHAMDI, Sébastien ROUAULT, Mohammed Ammar SAID"
Expand All @@ -30,9 +35,10 @@
"sphinx.ext.intersphinx",
"sphinx_favicon",
"sphinx_togglebutton",
"sphinx_contributors"
"sphinx_contributors",
]


def linkcode_resolve(domain, info):
"""Return a URL to the source code on GitHub for the given object."""
if domain != "py":
Expand Down Expand Up @@ -90,9 +96,7 @@ def linkcode_resolve(domain, info):


# Use MathJax to render math in HTML
mathjax_path = (
"https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
)
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"

exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

Expand Down Expand Up @@ -158,7 +162,7 @@ def linkcode_resolve(domain, info):
{
"title": "How to add a custom dataset",
"url": "how-to/add-custom-dataset",
}
},
],
},
{
Expand Down
8 changes: 5 additions & 3 deletions docs/contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ Contributors

The following people have contributed to Krum:

.. container:: rounded-image
.. contributors:: calicarpa/krum
:avatars:
.. contributors:: calicarpa/krum
:avatars:
:names:

We are open to all contributions. Whether it is a bug fix, a new feature, or an improvement to the documentation, feel free to open a pull request or start a discussion on GitHub.

To learn more about how to contribute, please refer to the `contribution guidelines <https://github.com/calicarpa/krum#contributing>`_.

Thank you to everyone who has helped improve this project.
2 changes: 1 addition & 1 deletion docs/how-to/add-dataset.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ batching automatically.
)

Step 3 — Export in ``__all__``
-----------------------------
------------------------------

List the builder function in ``__all__`` so the loader can discover it.

Expand Down
Loading