NaN¶
NaN-valued Byzantine gradient attack.
This attack generates gradients filled with NaN (Not a Number) values in order to test whether an aggregation rule detects, rejects, or propagates non-finite inputs.
Use Case¶
Simple baseline attack for evaluating aggregation-rule robustness against non-finite values.
Properties¶
Generates newly allocated gradients filled with NaN values.
Reuses the same Byzantine tensor object for all returned gradients.
Does not alias any honest input gradient.
No parameters beyond gradient count.
Example:¶
>>> import torch
>>> from attacks import nan
>>> grad_honests = [torch.tensor([1., 2., 3.]), torch.tensor([4., 5., 6.])]
>>> byzantine_grads = nan(grad_honests=grad_honests, f_real=1)
>>> byzantine_grads[0]
tensor([nan, nan, nan])
- attacks.nan.attack(grad_honests: list[Tensor], f_real: int, **kwargs) list[Tensor][source]¶
Generate NaN-valued Byzantine gradients.
- Parameters:
grad_honests (list of torch.Tensor) – Non-empty list of honest gradients. The first gradient is used as the shape, dtype, and device template for the generated Byzantine tensor.
f_real (int) – Number of Byzantine gradients to generate.
**kwargs (object) – Additional keyword arguments, ignored by this attack.
Returns
-------
torch.Tensor (list of) – List containing
f_realreferences to the same newly allocated NaN-valued Byzantine tensor. The returned tensor does not alias any honest input gradient.
- attacks.nan.check(grad_honests: list[Tensor], f_real: int, **kwargs) str | None[source]¶
Check parameter validity for the NaN attack.
- Parameters:
grad_honests (list of torch.Tensor) – Non-empty list of honest gradients.
f_real (int) – Number of Byzantine gradients to generate.
**kwargs (object) – Additional keyword arguments, ignored by this check.
Returns
-------
None (str or) –
Nonewhen parameters are valid, otherwise a user-facing error message.
See also
For direction-based identical attacks, see Identical.