# tff.backends.mapreduce.federated_secure_modular_sum

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

Computes a modular sum at [`tff.SERVER`](https://www.tensorflow.org/federated/api_docs/python/tff#SERVER) of a `value` from [`tff.CLIENTS`](https://www.tensorflow.org/federated/api_docs/python/tff#CLIENTS).

    tff.backends.mapreduce.federated_secure_modular_sum(
        value, modulus
    )

This function computes a sum such that it should not be possible for the
server to learn any clients individual value. The specific algorithm and
mechanism used to compute the secure sum may vary depending on the target
runtime environment the computation is compiled for or executed on. See
<https://research.google/pubs/pub47246/> for more information.

Not all executors support
[`tff.backends.mapreduce.federated_secure_modular_sum()`](https://www.tensorflow.org/federated/api_docs/python/tff/backends/mapreduce/federated_secure_modular_sum); consult the
documentation for the specific executor or executor stack you plan on using
for the specific of how it's handled by that executor.

The `modulus` argument is the modulus under which the client values are added.
The result of this function will be equivalent to `SUM(value) % modulus`.
*Lower values may allow for improved communication efficiency.*

#### Example:

    value = tff.federated_value(5, tff.CLIENTS)
    result = tff.backends.mapreduce.federated_secure_modular_sum(value, 3)
    # `result == (5 * num_clients % 3)@SERVER`

    value = tff.federated_value((3, 9), tff.CLIENTS)
    result = tff.backends.mapreduce.federated_secure_modular_sum(
        value, (100, 200))
    # `result == (3 * num_clients % 100, 9 * num_clients % 100)@SERVER`

> [!NOTE]
> **Note:** To sum non-integer values or to sum integers with fewer constraints and weaker privacy properties, consider using `federated_sum`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `value` | An integer or nested structure of integers placed at [`tff.CLIENTS`](https://www.tensorflow.org/federated/api_docs/python/tff#CLIENTS). Values outside of the range \[0, modulus-1\] will be considered equivalent to mod(value, modulus), i.e. they will be projected into the range \[0, modulus-1\] as part of the modular summation. |
| `modulus` | A Python integer or nested structure of integers matching the structure of `value`. If integer `modulus` is used with a nested `value`, the same integer is used for each tensor in `value`. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A representation of the modular sum of the member constituents of `value` placed on the [`tff.SERVER`](https://www.tensorflow.org/federated/api_docs/python/tff#SERVER). The resulting modular sum will be on the range \[0, modulus-1\]. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If the argument is not a federated TFF value placed at [`tff.CLIENTS`](https://www.tensorflow.org/federated/api_docs/python/tff#CLIENTS). |

<br />