Average

Simplest aggregation rule, computing the arithmetic mean of all submitted gradients.

This is the simplest aggregation rule, computing the arithmetic mean of all submitted gradients. It serves as a baseline for comparison with Byzantine- resilient methods.

Use Case

Baseline for non-adversarial settings or when no Byzantine behavior is expected.

Properties

  • Non-resilient: Vulnerable to any Byzantine attack. A single malicious gradient can completely skew the result.

  • No parameters: No configuration required beyond the gradient list.

  • Output: Newly created tensor, does not alias any input.

Example:

>>> import torch
>>> from aggregators import average
>>> gradients = [torch.tensor([1., 2., 3.]), torch.tensor([4., 5., 6.])]
>>> result = average(gradients=gradients)
tensor([2.5000, 3.5000, 4.5000])
aggregators.average.aggregate(gradients: list[Tensor], **kwargs) Tensor[source]

Compute the arithmetic mean of all submitted gradients.

Parameters:
  • gradients (list of torch.Tensor) – Non-empty list of gradients to aggregate. Each gradient should be a 1-D tensor representing the flattened model parameters.

  • **kwargs (object) – Additional keyword arguments, ignored by this rule.

  • Returns

  • -------

  • torch.Tensor – The arithmetic mean of all input gradients.

  • Notes

  • -----

  • tensor (The output tensor is a new)

  • tensor. (not aliasing any input)

aggregators.average.check(gradients: list[Tensor], **kwargs) str | None[source]

Check parameter validity for the averaging rule.

Parameters:
  • gradients (list of torch.Tensor) – Non-empty list of gradients to aggregate.

  • **kwargs (object) – Additional keyword arguments, ignored by this rule.

  • Returns

  • -------

  • None (str or) – None when parameters are valid, otherwise a user-facing error message.

aggregators.average.influence(honests: list[Tensor], attacks: list[Tensor], **kwargs) float[source]

Compute the ratio of accepted Byzantine gradients.

For arithmetic mean, all submitted gradients are used in the aggregation, so the influence ratio is simply the fraction of Byzantine gradients in the total.

Parameters:
  • honests (list of torch.Tensor) – Non-empty list of honest gradients.

  • attacks (list of torch.Tensor) – List of attack (Byzantine) gradients.

  • **kwargs (object) – Additional keyword arguments, ignored by this rule.

  • Returns

  • -------

  • float – Ratio of Byzantine gradients in the aggregation (attackers / total).

See also

For coordinate-wise robustness, see Median. For distance-based selection, see Krum / Multi-Krum or Bulyan.

API Reference

aggregators.average.influence(honests: list[Tensor], attacks: list[Tensor], **kwargs) float[source]

Compute the ratio of accepted Byzantine gradients.

For arithmetic mean, all submitted gradients are used in the aggregation, so the influence ratio is simply the fraction of Byzantine gradients in the total.

Parameters:
  • honests (list of torch.Tensor) – Non-empty list of honest gradients.

  • attacks (list of torch.Tensor) – List of attack (Byzantine) gradients.

  • **kwargs (object) – Additional keyword arguments, ignored by this rule.

  • Returns

  • -------

  • float – Ratio of Byzantine gradients in the aggregation (attackers / total).