Skip to main content

Krum

Byzantine-resilient aggregation rules for distributed machine learning.

Krum provides a modular framework for implementing, comparing, and evaluating Byzantine-resilient Gradient Aggregation Rules (GARs) for distributed learning. It ships with state-of-the-art aggregation rules, attack strategies, and IID/non-IID data partitioning.

Documentation

The reference documentation is available at calicarpa.github.io/krum.

Quickstart

import torch
from krum.primitives.aggregators.average import Average
from krum.primitives.aggregators.krum import Krum
from krum.primitives.attacks.gaussian import GaussianAttack

# Simulate gradients from 10 workers (8 honest, 2 Byzantine)
honest = torch.randn(8, 100)
byzantine = GaussianAttack.generate(honest, f=2, std=10.0)
gradients = torch.cat([honest, byzantine], dim=0)

# Compare robust vs naive aggregation
robust = Krum.aggregate(gradients, n=10, f=2)
naive = Average.aggregate(gradients)

print(f"Krum result norm:   {robust.norm().item():.4f}")
print(f"Average result norm: {naive.norm().item():.4f}")

Installation

Supported Python versions

This project supports Python 3.12 through 3.14.

From PyPI

pip install krum

This installs PyTorch, torchvision, and pandas. Additional dependencies (matplotlib, numpy, seaborn) are required for running experiments and visualisations:

pip install "krum[experiments]"

With uv (Recommended):

uv pip install krum
# or directly in a uv project
uv add krum
uv add "krum[experiments]"  # with optional experiment deps

From source

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

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

With uv (Recommended):

git clone https://github.com/calicarpa/krum.git
cd krum
uv sync --all-extras --all-groups

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

Features

  • 11 aggregation rules: Average, Median, Trimmed Mean, Krum, MultiKrum, Bulyan, Brute, GeometricMedian, Medoid, Aksel, Nearest Neighbor Average
  • 5 attack strategies: SignFlip, ALIE, Gaussian, FullGradientNegation, SmallPerturbation
  • Data partitioning: IID and non-IID per-worker splits via a single DataPartitioner interface — IidPartitioner, DirichletPartitioner, PerLabelsPartitioner, MixingPartitioner — returning one Sequence[Dataset] per worker from a stateless partition() classmethod
  • Zero-copy model wrapper: Flat parameter/gradient views via krum.primitives.Model
  • Stateless design: Aggregators, attacks, and partitioners are classmethods, no instantiation needed

Contributing

Linting, formatting, and type-checking

This project uses Ruff for unified linting and formatting, and ty for type-checking.

ruff format .
ruff check --fix .
ty check

Pre-commit hooks

pre-commit install

Running tests

Tests use pytest and are located under tests/.

uv run pytest tests/ -v
uv run pytest tests/primitives/aggregators/ -v

Tests run automatically on every push and pull request via GitHub Actions (Python 3.12–3.14).

Documentation

Build the documentation locally:

cd docs
make html  # Build HTML documentation
make watch # Watch for changes and auto-rebuild
make serve # Build and serve on port 8000
make clean # Remove generated files

License

MIT License — see LICENSE.

Metadata

Release files for krum 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for krum 0.9.1
File Size Uploaded Provenance Actions
krum-0.9.1.tar.gz 85.4 kB With provenance Details for krum-0.9.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for krum 0.9.1
File Interpreter ABI Platform Actions
krum-0.9.1-py3-none-any.whl Python 3 none any Details for krum-0.9.1-py3-none-any.whl

Total release size: 196.3 kB

Release files / krum-0.9.1.tar.gz

Download URL krum-0.9.1.tar.gz
Size 85.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3f5f2af4e161d182692b2cad543092aac04696d9d9da279bc76b2c7aa4966526
BLAKE2b-256 checksum
How to use checksums
2e6f11e5d4e0bec618377cc5053f4f1f5671ecf709272f03bc2c6c4b9fbd7970
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / krum-0.9.1-py3-none-any.whl

Download URL krum-0.9.1-py3-none-any.whl
Size 110.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f19d7ad7cb802f440383f6987ca498c2e3c6596f0ccac4f64c3a500d68a5d70
BLAKE2b-256 checksum
How to use checksums
6c2d21eb97710ecd8a00c4e39ca30bf29dfcb5ee4ef3499d8ad539394d7c4042
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for krum 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for krum-0.9.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page