krum 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. krum-0.9.0/LICENSE +21 -0
  2. krum-0.9.0/PKG-INFO +188 -0
  3. krum-0.9.0/README.md +146 -0
  4. krum-0.9.0/krum/__init__.py +22 -0
  5. krum-0.9.0/krum/orchestration/__init__.py +684 -0
  6. krum-0.9.0/krum/orchestration/execution.py +274 -0
  7. krum-0.9.0/krum/orchestration/hashing.py +572 -0
  8. krum-0.9.0/krum/orchestration/metrics.py +498 -0
  9. krum-0.9.0/krum/orchestration/storage.py +670 -0
  10. krum-0.9.0/krum/orchestration/tracing.py +177 -0
  11. krum-0.9.0/krum/primitives/__init__.py +6 -0
  12. krum-0.9.0/krum/primitives/aggregators/__init__.py +57 -0
  13. krum-0.9.0/krum/primitives/aggregators/aksel.py +74 -0
  14. krum-0.9.0/krum/primitives/aggregators/average.py +48 -0
  15. krum-0.9.0/krum/primitives/aggregators/brute.py +87 -0
  16. krum-0.9.0/krum/primitives/aggregators/bulyan.py +117 -0
  17. krum-0.9.0/krum/primitives/aggregators/geometric_median.py +99 -0
  18. krum-0.9.0/krum/primitives/aggregators/krum.py +57 -0
  19. krum-0.9.0/krum/primitives/aggregators/median.py +54 -0
  20. krum-0.9.0/krum/primitives/aggregators/medoid.py +80 -0
  21. krum-0.9.0/krum/primitives/aggregators/multikrum.py +137 -0
  22. krum-0.9.0/krum/primitives/aggregators/nearest_neighbor_average.py +70 -0
  23. krum-0.9.0/krum/primitives/aggregators/trimmed_mean.py +64 -0
  24. krum-0.9.0/krum/primitives/attacks/__init__.py +59 -0
  25. krum-0.9.0/krum/primitives/attacks/alie.py +157 -0
  26. krum-0.9.0/krum/primitives/attacks/full_gradient_negation.py +86 -0
  27. krum-0.9.0/krum/primitives/attacks/gaussian.py +71 -0
  28. krum-0.9.0/krum/primitives/attacks/sign_flip.py +75 -0
  29. krum-0.9.0/krum/primitives/attacks/small_perturbation.py +400 -0
  30. krum-0.9.0/krum/primitives/data_partitioners/__init__.py +86 -0
  31. krum-0.9.0/krum/primitives/data_partitioners/dirichlet.py +128 -0
  32. krum-0.9.0/krum/primitives/data_partitioners/iid.py +57 -0
  33. krum-0.9.0/krum/primitives/data_partitioners/mixing.py +94 -0
  34. krum-0.9.0/krum/primitives/data_partitioners/per_labels.py +128 -0
  35. krum-0.9.0/krum/primitives/models/__init__.py +299 -0
  36. krum-0.9.0/krum/primitives/models/cnn.py +188 -0
  37. krum-0.9.0/krum/primitives/models/mlp.py +122 -0
  38. krum-0.9.0/krum/simulations/__init__.py +12 -0
  39. krum-0.9.0/krum/simulations/centralised/__init__.py +495 -0
  40. krum-0.9.0/krum/simulations/centralised/hidden_vulnerability_icml_2018.py +102 -0
  41. krum-0.9.0/krum/simulations/centralised/krum_nips_2017.py +72 -0
  42. krum-0.9.0/krum/simulations/decentralised/__init__.py +475 -0
  43. krum-0.9.0/krum/simulations/decentralised/monna_icml_2023.py +358 -0
  44. krum-0.9.0/krum.egg-info/PKG-INFO +188 -0
  45. krum-0.9.0/krum.egg-info/SOURCES.txt +48 -0
  46. krum-0.9.0/krum.egg-info/dependency_links.txt +1 -0
  47. krum-0.9.0/krum.egg-info/requires.txt +21 -0
  48. krum-0.9.0/krum.egg-info/top_level.txt +1 -0
  49. krum-0.9.0/pyproject.toml +135 -0
  50. krum-0.9.0/setup.cfg +4 -0
krum-0.9.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Distributed Computing Laboratory, EPFL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
krum-0.9.0/PKG-INFO ADDED
@@ -0,0 +1,188 @@
1
+ Metadata-Version: 2.4
2
+ Name: krum
3
+ Version: 0.9.0
4
+ Summary: Byzantine-resilient aggregation rules for distributed machine learning.
5
+ Author-email: Sébastien Rouault <sebastien.rouault@alumni.epfl.ch>, Arthur Danjou <arthur.danjou@dauphine.eu>, Mohamad Ammar Said <mohamad-ammar.said@polytechnique.edu>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/calicarpa/krum
8
+ Project-URL: Documentation, https://calicarpa.github.io/krum/
9
+ Project-URL: Repository, https://github.com/calicarpa/krum
10
+ Project-URL: Issues, https://github.com/calicarpa/krum/issues
11
+ Keywords: byzantine-fault-tolerance,distributed-machine-learning,federated-learning,robust-aggregation
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: <3.15,>=3.12
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: torch>=2.13.0
23
+ Requires-Dist: torchvision>=0.28.0
24
+ Provides-Extra: experiments
25
+ Requires-Dist: matplotlib>=3.10.0; extra == "experiments"
26
+ Requires-Dist: numpy>=2.0.0; extra == "experiments"
27
+ Requires-Dist: pandas>=2.2.0; extra == "experiments"
28
+ Requires-Dist: seaborn>=0.13.0; extra == "experiments"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pandas>=2.2.0; extra == "dev"
31
+ Requires-Dist: pandas-stubs~=3.0.2; extra == "dev"
32
+ Requires-Dist: pre-commit>=4.0.0; extra == "dev"
33
+ Requires-Dist: ruff>=0.15.22; extra == "dev"
34
+ Requires-Dist: ty>=0.0.61; extra == "dev"
35
+ Requires-Dist: sphinx>=8.1.3; extra == "dev"
36
+ Requires-Dist: sphinx-copybutton>=0.5.2; extra == "dev"
37
+ Requires-Dist: sphinx-favicon>=1.0.1; extra == "dev"
38
+ Requires-Dist: sphinx-togglebutton>=0.3.2; extra == "dev"
39
+ Requires-Dist: sphinx-contributors>=0.3.0; extra == "dev"
40
+ Requires-Dist: shibuya>=2026.7.12; extra == "dev"
41
+ Dynamic: license-file
42
+
43
+ # Krum
44
+
45
+ **Byzantine-resilient aggregation rules for distributed machine learning.**
46
+
47
+ Krum provides a modular framework for implementing, comparing, and evaluating
48
+ Byzantine-resilient Gradient Aggregation Rules (GARs) for distributed learning.
49
+ It ships with state-of-the-art aggregation rules, attack strategies, and
50
+ IID/non-IID data partitioning.
51
+
52
+ ## Documentation
53
+
54
+ The reference documentation is available at
55
+ [calicarpa.github.io/krum](https://calicarpa.github.io/krum/).
56
+
57
+ ## Quickstart
58
+
59
+ ```python
60
+ import torch
61
+ from krum.primitives.aggregators.average import Average
62
+ from krum.primitives.aggregators.krum import Krum
63
+ from krum.primitives.attacks.gaussian import GaussianAttack
64
+
65
+ # Simulate gradients from 10 workers (8 honest, 2 Byzantine)
66
+ honest = torch.randn(8, 100)
67
+ byzantine = GaussianAttack.generate(honest, f=2, std=10.0)
68
+ gradients = torch.cat([honest, byzantine], dim=0)
69
+
70
+ # Compare robust vs naive aggregation
71
+ robust = Krum.aggregate(gradients, n=10, f=2)
72
+ naive = Average.aggregate(gradients)
73
+
74
+ print(f"Krum result norm: {robust.norm().item():.4f}")
75
+ print(f"Average result norm: {naive.norm().item():.4f}")
76
+ ```
77
+
78
+ ## Installation
79
+
80
+ ### Supported Python versions
81
+
82
+ This project supports Python **3.12 through 3.14**.
83
+
84
+ ### From PyPI
85
+
86
+ ```bash
87
+ pip install krum
88
+ ```
89
+
90
+ This installs **PyTorch**, **torchvision**, and **pandas**. Additional
91
+ dependencies (``matplotlib``, ``numpy``, ``seaborn``) are required for running experiments
92
+ and visualisations:
93
+
94
+ ```bash
95
+ pip install "krum[experiments]"
96
+ ```
97
+
98
+ With `uv` (Recommended):
99
+
100
+ ```bash
101
+ uv pip install krum
102
+ # or directly in a uv project
103
+ uv add krum
104
+ uv add "krum[experiments]" # with optional experiment deps
105
+ ```
106
+
107
+ ### From source
108
+
109
+ For development or if you want to modify the source, clone the repository and
110
+ install in editable mode with the development dependencies:
111
+
112
+ ```bash
113
+ git clone https://github.com/calicarpa/krum.git
114
+ cd krum
115
+ pip install -e ".[dev,experiments]"
116
+ ```
117
+
118
+ With `uv` (Recommended):
119
+
120
+ ```bash
121
+ git clone https://github.com/calicarpa/krum.git
122
+ cd krum
123
+ uv sync --all-extras --all-groups
124
+ ```
125
+
126
+ This installs all linting, type-checking, and documentation tools.
127
+
128
+ ## Features
129
+
130
+ - **11 aggregation rules**: Average, Median, Trimmed Mean, Krum, MultiKrum,
131
+ Bulyan, Brute, GeometricMedian, Medoid, Aksel, Nearest Neighbor Average
132
+ - **5 attack strategies**: SignFlip, ALIE, Gaussian, FullGradientNegation,
133
+ SmallPerturbation
134
+ - **Data partitioning**: IID and non-IID per-worker splits via a single
135
+ `DataPartitioner` interface — `IidPartitioner`, `DirichletPartitioner`,
136
+ `PerLabelsPartitioner`, `MixingPartitioner` — returning one
137
+ `Sequence[Dataset]` per worker from a stateless `partition()` classmethod
138
+ - **Zero-copy model wrapper**: Flat parameter/gradient views via
139
+ `krum.primitives.Model`
140
+ - **Stateless design**: Aggregators, attacks, and partitioners are
141
+ classmethods, no instantiation needed
142
+
143
+ ## Contributing
144
+
145
+ ### Linting, formatting, and type-checking
146
+
147
+ This project uses [Ruff](https://docs.astral.sh/ruff/) for unified linting and
148
+ formatting, and [ty](https://github.com/astral-sh/ty) for type-checking.
149
+
150
+ ```bash
151
+ ruff format .
152
+ ruff check --fix .
153
+ ty check
154
+ ```
155
+
156
+ ### Pre-commit hooks
157
+
158
+ ```bash
159
+ pre-commit install
160
+ ```
161
+
162
+ ### Running tests
163
+
164
+ Tests use [pytest](https://docs.pytest.org/) and are located under `tests/`.
165
+
166
+ ```bash
167
+ uv run pytest tests/ -v
168
+ uv run pytest tests/primitives/aggregators/ -v
169
+ ```
170
+
171
+ Tests run automatically on every push and pull request via GitHub Actions
172
+ (Python 3.12–3.14).
173
+
174
+ ### Documentation
175
+
176
+ Build the documentation locally:
177
+
178
+ ```bash
179
+ cd docs
180
+ make html # Build HTML documentation
181
+ make watch # Watch for changes and auto-rebuild
182
+ make serve # Build and serve on port 8000
183
+ make clean # Remove generated files
184
+ ```
185
+
186
+ ## License
187
+
188
+ MIT License — see [LICENSE](LICENSE).
krum-0.9.0/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # Krum
2
+
3
+ **Byzantine-resilient aggregation rules for distributed machine learning.**
4
+
5
+ Krum provides a modular framework for implementing, comparing, and evaluating
6
+ Byzantine-resilient Gradient Aggregation Rules (GARs) for distributed learning.
7
+ It ships with state-of-the-art aggregation rules, attack strategies, and
8
+ IID/non-IID data partitioning.
9
+
10
+ ## Documentation
11
+
12
+ The reference documentation is available at
13
+ [calicarpa.github.io/krum](https://calicarpa.github.io/krum/).
14
+
15
+ ## Quickstart
16
+
17
+ ```python
18
+ import torch
19
+ from krum.primitives.aggregators.average import Average
20
+ from krum.primitives.aggregators.krum import Krum
21
+ from krum.primitives.attacks.gaussian import GaussianAttack
22
+
23
+ # Simulate gradients from 10 workers (8 honest, 2 Byzantine)
24
+ honest = torch.randn(8, 100)
25
+ byzantine = GaussianAttack.generate(honest, f=2, std=10.0)
26
+ gradients = torch.cat([honest, byzantine], dim=0)
27
+
28
+ # Compare robust vs naive aggregation
29
+ robust = Krum.aggregate(gradients, n=10, f=2)
30
+ naive = Average.aggregate(gradients)
31
+
32
+ print(f"Krum result norm: {robust.norm().item():.4f}")
33
+ print(f"Average result norm: {naive.norm().item():.4f}")
34
+ ```
35
+
36
+ ## Installation
37
+
38
+ ### Supported Python versions
39
+
40
+ This project supports Python **3.12 through 3.14**.
41
+
42
+ ### From PyPI
43
+
44
+ ```bash
45
+ pip install krum
46
+ ```
47
+
48
+ This installs **PyTorch**, **torchvision**, and **pandas**. Additional
49
+ dependencies (``matplotlib``, ``numpy``, ``seaborn``) are required for running experiments
50
+ and visualisations:
51
+
52
+ ```bash
53
+ pip install "krum[experiments]"
54
+ ```
55
+
56
+ With `uv` (Recommended):
57
+
58
+ ```bash
59
+ uv pip install krum
60
+ # or directly in a uv project
61
+ uv add krum
62
+ uv add "krum[experiments]" # with optional experiment deps
63
+ ```
64
+
65
+ ### From source
66
+
67
+ For development or if you want to modify the source, clone the repository and
68
+ install in editable mode with the development dependencies:
69
+
70
+ ```bash
71
+ git clone https://github.com/calicarpa/krum.git
72
+ cd krum
73
+ pip install -e ".[dev,experiments]"
74
+ ```
75
+
76
+ With `uv` (Recommended):
77
+
78
+ ```bash
79
+ git clone https://github.com/calicarpa/krum.git
80
+ cd krum
81
+ uv sync --all-extras --all-groups
82
+ ```
83
+
84
+ This installs all linting, type-checking, and documentation tools.
85
+
86
+ ## Features
87
+
88
+ - **11 aggregation rules**: Average, Median, Trimmed Mean, Krum, MultiKrum,
89
+ Bulyan, Brute, GeometricMedian, Medoid, Aksel, Nearest Neighbor Average
90
+ - **5 attack strategies**: SignFlip, ALIE, Gaussian, FullGradientNegation,
91
+ SmallPerturbation
92
+ - **Data partitioning**: IID and non-IID per-worker splits via a single
93
+ `DataPartitioner` interface — `IidPartitioner`, `DirichletPartitioner`,
94
+ `PerLabelsPartitioner`, `MixingPartitioner` — returning one
95
+ `Sequence[Dataset]` per worker from a stateless `partition()` classmethod
96
+ - **Zero-copy model wrapper**: Flat parameter/gradient views via
97
+ `krum.primitives.Model`
98
+ - **Stateless design**: Aggregators, attacks, and partitioners are
99
+ classmethods, no instantiation needed
100
+
101
+ ## Contributing
102
+
103
+ ### Linting, formatting, and type-checking
104
+
105
+ This project uses [Ruff](https://docs.astral.sh/ruff/) for unified linting and
106
+ formatting, and [ty](https://github.com/astral-sh/ty) for type-checking.
107
+
108
+ ```bash
109
+ ruff format .
110
+ ruff check --fix .
111
+ ty check
112
+ ```
113
+
114
+ ### Pre-commit hooks
115
+
116
+ ```bash
117
+ pre-commit install
118
+ ```
119
+
120
+ ### Running tests
121
+
122
+ Tests use [pytest](https://docs.pytest.org/) and are located under `tests/`.
123
+
124
+ ```bash
125
+ uv run pytest tests/ -v
126
+ uv run pytest tests/primitives/aggregators/ -v
127
+ ```
128
+
129
+ Tests run automatically on every push and pull request via GitHub Actions
130
+ (Python 3.12–3.14).
131
+
132
+ ### Documentation
133
+
134
+ Build the documentation locally:
135
+
136
+ ```bash
137
+ cd docs
138
+ make html # Build HTML documentation
139
+ make watch # Watch for changes and auto-rebuild
140
+ make serve # Build and serve on port 8000
141
+ make clean # Remove generated files
142
+ ```
143
+
144
+ ## License
145
+
146
+ MIT License — see [LICENSE](LICENSE).
@@ -0,0 +1,22 @@
1
+ """Krum — Byzantine-resilient aggregation rules for distributed machine learning.
2
+
3
+ The package is organized in two layers:
4
+
5
+ * :mod:`krum.primitives.aggregators` exposes stateless, classmethod-based
6
+ Gradient Aggregation Rules (GARs).
7
+ * :mod:`krum.primitives.attacks` exposes gradient attacks that simulate Byzantine
8
+ workers when evaluating the robustness of an aggregator.
9
+ * :mod:`krum.primitives.models` provides a :class:`~krum.primitives.models.Model`
10
+ wrapper that exposes a ``torch.nn.Module``'s parameters and gradients as
11
+ zero-copy flat tensors, which is the data layout the aggregators consume.
12
+
13
+ The :mod:`krum.simulations` package ships the original training simulations
14
+ from the papers that introduced each rule.
15
+ """
16
+
17
+ from importlib.metadata import PackageNotFoundError, version
18
+
19
+ try:
20
+ __version__ = version("krum")
21
+ except PackageNotFoundError:
22
+ __version__ = "0.0.0" # Running from source without installation