The returned federated TFF computation is a polymorphic computation that
accepts unfinalized client metrics, and returns finalized, summed metrics
placed at the server. Invoking the polymorphic computation will initiate
tracing on the argument and will raise a ValueError if the keys (i.e.,
metric names) in metric_finalizers are not the same as those of the argument
the polymorphic method is invoked on.
The computation is intended to be invoked on the output of
tff.learning.models.VariableModel.report_local_unfinalized_metrics() when
placed at CLIENTS, and the
first output (aggregated_metrics) is computed by first securely summing the
unfinalized metrics from CLIENTS, followed by applying the finalizers at
SERVER. The second output (secure_sum_measurements) is an OrderedDict
that maps from factory_keys to the secure summation measurements (e.g. the
number of clients gets clipped. See tff.aggregators.SecureSumFactory for
details). A factory_key is uniquely defined by three scalars: lower bound,
upper bound, and tensor dtype (denoted as datatype enum). Metric values of the
same factory_key are grouped and aggegrated together (and hence, the
secure_sum_measurements are also computed at a group level).
Since secure summation works in fixed-point arithmetic space, floating point
numbers must be encoding using integer quantization. By default, each tensor
in from the clients unfinalized metrics will be clipped to [0, 2**20 - 1]
and encoded to integers inside tff.aggregators.SecureSumFactory. Callers can
change this range by setting metric_value_ranges, which may be a partial
tree matching the structure of the argument to metrics_finalizers.
Unused, will be removed from the API in the
future.
metric_value_ranges
A collections.OrderedDict that matches the structure
of the input arguments of metric_finalizers. Each leaf in the tree
should have a 2-tuple that defines the range of expected values for that
variable in the metric. If the entire structure is None, a default range
of [0.0, 2.0**20 - 1] will be applied to all variables. Each leaf may
also be None, which will also get the default range; allowing partial
user sepcialization. At runtime, values that fall outside the ranges
specified at the leaves, those values will be clipped to within the range.
Returns
A federated TFF computation that securely sums the unfinalized metrics from
CLIENTS, and applies the correponding finalizers at SERVER.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.learning.metrics.secure_sum_then_finalize\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [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) |\n\nCreates a TFF computation that aggregates metrics using secure summation. \n\n tff.learning.metrics.secure_sum_then_finalize(\n metric_finalizers: Union[../../../tff/learning/metrics/MetricFinalizersType, ../../../tff/learning/metrics/FunctionalMetricFinalizersType],\n local_unfinalized_metrics_type: Optional[../../../tff/types/StructWithPythonType] = None,\n metric_value_ranges: Optional[sum_aggregation_factory.UserMetricValueRangeDict] = None\n ) -\u003e ../../../tff/Computation\n\nThe returned federated TFF computation is a polymorphic computation that\naccepts unfinalized client metrics, and returns finalized, summed metrics\nplaced at the server. Invoking the polymorphic computation will initiate\ntracing on the argument and will raise a `ValueError` if the keys (i.e.,\nmetric names) in `metric_finalizers` are not the same as those of the argument\nthe polymorphic method is invoked on.\n| **Note:** invoking this computation outside of a federated context (a method decorated with [`tff.federated_computation`](../../../tff/federated_computation)) will require first wrapping it in a concrete, non-polymorphic [`tff.Computation`](../../../tff/Computation) with appropriate federated types.\n\nThe computation is intended to be invoked on the output of\n[`tff.learning.models.VariableModel.report_local_unfinalized_metrics()`](../../../tff/learning/models/VariableModel#report_local_unfinalized_metrics) when\nplaced at `CLIENTS`, and the\nfirst output (`aggregated_metrics`) is computed by first securely summing the\nunfinalized metrics from `CLIENTS`, followed by applying the finalizers at\n`SERVER`. The second output (`secure_sum_measurements`) is an `OrderedDict`\nthat maps from `factory_key`s to the secure summation measurements (e.g. the\nnumber of clients gets clipped. See [`tff.aggregators.SecureSumFactory`](../../../tff/aggregators/SecureSumFactory) for\ndetails). A `factory_key` is uniquely defined by three scalars: lower bound,\nupper bound, and tensor dtype (denoted as datatype enum). Metric values of the\nsame `factory_key` are grouped and aggegrated together (and hence, the\n`secure_sum_measurements` are also computed at a group level).\n\nSince secure summation works in fixed-point arithmetic space, floating point\nnumbers must be encoding using integer quantization. By default, each tensor\nin from the clients unfinalized metrics will be clipped to `[0, 2**20 - 1]`\nand encoded to integers inside [`tff.aggregators.SecureSumFactory`](../../../tff/aggregators/SecureSumFactory). Callers can\nchange this range by setting `metric_value_ranges`, which may be a partial\ntree matching the structure of the argument to `metrics_finalizers`.\n\nExample partial value range specification: \n\n finalizers = ...\n value_ranges = collections.OrderedDict(\n b=(0.0, 1.0),\n c=[None, (0.0, 1.0)])\n aggregator = tff.learning.metrics.secure_sum_then_finalize(\n finalizers, value_ranges)\n\nThis sets the range of the *second* tensor of `b` in the dictionary, using the\nrange for the first tensor, and the `a` tensor.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `metric_finalizers` | Either the result of [`tff.learning.models.VariableModel.metric_finalizers`](../../../tff/learning/models/VariableModel#metric_finalizers) (an `OrderedDict` of callables) or the [`tff.learning.models.FunctionalModel.finalize_metrics`](../../../tff/learning/models/FunctionalModel#finalize_metrics) method (a callable that takes an `OrderedDict` argument). If the former, the keys must be the same as the `OrderedDict` returned by [`tff.learning.models.VariableModel.report_local_unfinalized_metrics`](../../../tff/learning/models/VariableModel#report_local_unfinalized_metrics). If the later, the callable must compute over the same keyspace of the result returned by [`tff.learning.models.FunctionalModel.update_metrics_state`](../../../tff/learning/models/FunctionalModel#update_metrics_state). |\n| `local_unfinalized_metrics_type` | Unused, will be removed from the API in the future. |\n| `metric_value_ranges` | A `collections.OrderedDict` that matches the structure of the input arguments of `metric_finalizers`. Each leaf in the tree should have a 2-tuple that defines the range of expected values for that variable in the metric. If the entire structure is `None`, a default range of `[0.0, 2.0**20 - 1]` will be applied to all variables. Each leaf may also be `None`, which will also get the default range; allowing partial user sepcialization. At runtime, values that fall outside the ranges specified at the leaves, those values will be clipped to within the range. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A federated TFF computation that securely sums the unfinalized metrics from `CLIENTS`, and applies the correponding finalizers at `SERVER`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|---------------------------------------|\n| `TypeError` | If the inputs are of the wrong types. |\n\n\u003cbr /\u003e"]]