Adaptive Robust Clipping (ARC)#
- class byzfl.ARC(f=0)[source]#
Bases:
object
Description#
Apply the Adaptive Robust Clipping pre-aggregation rule [1]:
\[\mathrm{ARC}_{f} \ (x_1, \dots, x_n) = \left( \min\left\{1, \frac{x_{\pi(k)}}{\big|\big|x_1\big|\big|_2}\right\} x_1 \ \ , \ \dots \ ,\ \ \min\left\{1, \frac{x_{\pi(k)}}{\big|\big|x_n\big|\big|_2}\right\} x_n \right)\]where
\(x_1, \dots, x_n\) are the input vectors, which conceptually correspond to gradients submitted by honest and Byzantine participants during a training iteration.
\(f\) conceptually represents the expected number of Byzantine vectors.
\(\big|\big|.\big|\big|_2\) denotes the \(\ell_2\)-norm.
\(k = \lfloor 2 \cdot \frac{f}{n} \cdot (n - f) \rfloor\).
\(\pi\) denotes a permutation on \(\big[n\big]\) that sorts the \(\ell_2\)-norm of the input vectors in non-increasing order. This sorting is expressed as: \(\big|\big|x_{\pi(1)}\big|\big|_2 \leq \ldots \leq \big|\big|x_{\pi(n)}\big|\big|_2\).
- Initialization parameters:
f (int, optional) – Number of faulty vectors. Set to 0 by default.
Calling the instance
- Input parameters:
vectors (numpy.ndarray, torch.Tensor, list of numpy.ndarray or list of torch.Tensor) – A set of vectors, matrix or tensors.
- Returns:
numpy.ndarray or torch.Tensor – The data type of the output will be the same as the input.
Examples
>>> import byzfl >>> agg = byzfl.ARC(1)
Using numpy arrays
>>> import numpy as np >>> x = np.array([[1., 2., 3.], # np.ndarray >>> [4., 5., 6.], >>> [7., 8., 9.]]) >>> agg(x) array([[1. , 2. , 3. ], [4. , 5. , 6. ], [4.41004009, 5.04004582, 5.67005155]])
Using torch tensors
>>> import torch >>> x = torch.tensor([[1., 2., 3.], # torch.tensor >>> [4., 5., 6.], >>> [7., 8., 9.]]) >>> agg(x) tensor([[1.0000, 2.0000, 3.0000], [4.0000, 5.0000, 6.0000], [4.4100, 5.0400, 5.6701]])
Using list of numpy arrays
>>> import numpy as np >>> x = [np.array([1., 2., 3.]), # list of np.ndarray >>> np.array([4., 5., 6.]), >>> np.array([7., 8., 9.])] >>> agg(x) array([[1. , 2. , 3. ], [4. , 5. , 6. ], [4.41004009, 5.04004582, 5.67005155]])
Using list of torch tensors
>>> import torch >>> x = [torch.tensor([1., 2., 3.]), # list of torch.tensor >>> torch.tensor([4., 5., 6.]), >>> torch.tensor([7., 8., 9.])] >>> agg(x) tensor([[1.0000, 2.0000, 3.0000], [4.0000, 5.0000, 6.0000], [4.4100, 5.0400, 5.6701]])
References