Full Gradient Negation

Full-gradient negation attack.

class attacks.full_gradient_negation.FullGradientNegationAttack[source]

Bases: Attack

Full-gradient negation attack.

Each Byzantine worker sends the negation of the full-dataset gradient scaled by a factor \(\kappa\). The attack assumes knowledge of the true gradient over the entire dataset.

classmethod generate(honest_gradients: Sequence[Tensor] | Tensor, /, out: Tensor | None = None, *, f: int, full_gradient: Tensor, kappa: float = 100.0, **specialized: Any) Tensor[source]

Generate Byzantine gradients.

Parameters:
  • honest_gradients – Sequence of \(h\) gradient vectors, one per honest worker, each of shape \((d,)\).

  • out – Optional pre-allocated tensor of shape \((f, d)\) to write the result into and return.

  • f – Number of Byzantine gradients to generate.

  • full_gradient – Tensor of shape \((d,)\) containing the gradient computed over the entire dataset.

  • kappa – Scale factor applied to the negated full gradient.

  • **specialized – Additional keyword arguments.

Returns:
  • Byzantine gradients of shape `` (f, d)

  • empty tensor of shape `` (0, d)

Raises:
  • ValueError – If \(\kappa\) or \(f\) is negative, there are no honest gradients, or full_gradient is not 1-D.

  • TypeError – If the honest gradients do not use a floating-point dtype.

See also

For a simple noise-based attack, see Gaussian. For a sign-reversal attack, see SignFlip.

Note

The full-dataset gradient is passed as a keyword argument to generate():

FullGradientNegationAttack.generate(honest_gradients, f=..., full_gradient=full_grad, kappa=100.0)