View source on GitHub
|
AggregationProcess factory for securely summing values under a modulus.
Inherits From: UnweightedAggregationFactory
tff.aggregators.SecureModularSumFactory(
modulus: Union[int, np.ndarray], symmetric_range: bool = False
)
The created tff.templates.AggregationProcess uses the
tff.backends.mapreduce.federated_secure_modular_sum operator for movement of
values from tff.CLIENTS to tff.SERVER.
The aggregator requires integer types, and values in range [0, modulus-1]
(if symmetric_range is False) or in range [-(modulus-1), +(modulus-1)]
(if symmetric_range is True). In the latter case, additional computation
is needed for correct reduction to the
tff.backends.mapreduce.federated_secure_modular_sum with 2*modulus-1 as
the modulus for actual secure summation.
The aggregator always returns a value in those ranges, implemented as a modular summation, regardless of input values. That is, if an input value at runtime is outside of the specified range an error will not be raised, rather the value will "wrap around", according to modular arithmetic.
For example, if symmetric_range is False, given client values [1, 3, 6]
and modulus 4, the sum will be
((1 % 4) + (3 % 4) + (6 % 4)) % 4 = (1 + 3 + 2) % 4 = 6 % 4 = 2.
If symmetric_range is True, given client values [1, 3, 6] and modulus
4, the sum will be
((1 %s 4) + (3 %s 4) + (6 %s 4)) %s 4 = (1 + 3 + (-3)) %s 4 = 1.
The * %s x operator symbolizes modular "wrap around" to range [-x, x].
The implementation of the case of symmetric_range is True is by delegation
to tff.backends.mapreduce.federated_secure_modular_sum with modulus
2*modulus-1 is, which is equivalent to modular clip to range [-(modulus-1),
+(modulus-1)], and then representing x in that range as (x + 2*modulus-1)
% 2*modulus-1, which is congruent with x under the desired modulus, thus
compatible with secure aggregation. This is reverted after summation by
modular clip to the initial range [-(modulus-1), +(modulus-1)].
Args | |
|---|---|
modulus
|
An integer modulus for the summation. |
symmetric_range
|
A bool indicating whether the summation is on symmetric
range around 0 or not.
|
Raises | |
|---|---|
TypeError
|
If modulus is not an int or Numpy scalar, or
symmetric_range is not a bool.
|
ValueError
|
If modulus is not positive.
|
Methods
create
create(
value_type
)
Creates a tff.aggregators.AggregationProcess without weights.
The provided value_type is a non-federated tff.Type, that is, not a
tff.FederatedType.
The returned tff.aggregators.AggregationProcess will be created for
aggregation of values matching value_type placed at tff.CLIENTS.
That is, its next method will expect type
<S@SERVER, {value_type}@CLIENTS>, where S is the unplaced return type of
its initialize method.
| Args | |
|---|---|
value_type
|
A non-federated tff.Type.
|
| Returns | |
|---|---|
A tff.templates.AggregationProcess.
|
View source on GitHub