View source on GitHub
|
Aggregation Factory that sums and then finalizes the metrics.
Inherits From: UnweightedAggregationFactory
tff.learning.metrics.SumThenFinalizeFactory(
metric_finalizers: tff.learning.metrics.MetricFinalizersType,
initial_unfinalized_metrics: Optional[collections.OrderedDict[str, Any]] = None,
inner_summation_factory: Optional[tff.aggregators.UnweightedAggregationFactory] = None
)
The created tff.templates.AggregationProcess uses the inner summation
process created by the inner summation factory to sum unfinalized metrics
from tff.CLIENTS to tff.SERVER, accumulates the summed unfinalized metrics
in the state, and then finalize the metrics for both current round and total
rounds. If the inner summation factory is not specified,
tff.aggregators.SumFactory is used by default. The inner summation factory
can also use SecAgg.
The accumulated unfinalized metrics across rounds are initialized to be the intial value of the unfinalized metrics, if the inital value is not specified, zero is used.
The next function of the created tff.templates.AggregationProcess takes
the state and local unfinalized metrics reported from tff.CLIENTS, and
returns a tff.templates.MeasuredProcessOutput object with the following
properties:
state: a tuple of thestateof the inner summation process and the accumulated unfinalized metrics across rounds.result: a tuple of the finalized metrics of the current round and total rounds.measurements: the measurements of the inner summation process.
Args | |
|---|---|
metric_finalizers
|
An collections.OrderedDict of metric names to
finalizers, should have same keys as the unfinalized metrics. A
finalizer is a function (typically a tf.function decorated callable or
a tff.tensorflow.computation decorated TFF Computation) that takes in
a metric's unfinalized values, and returns the finalized metric values.
This can be obtained from
tff.learning.models.VariableModel.metric_finalizers().
|
initial_unfinalized_metrics
|
Optional. An collections.OrderedDict of
metric names to the initial values of local unfinalized metrics, its
structure should match that of local_unfinalized_metrics_type. If not
specified, defaults to zero.
|
inner_summation_factory
|
Optional. A
tff.aggregators.UnweightedAggregationFactory that creates a
tff.templates.AggregationProcess to sum the metrics from clients to
server. If not specified, tff.aggregators.SumFactory is used. If the
metrics aggregation needs SecAgg, aggregation_factory.SecureSumFactory
can be used as the inner summation factory.
|
Raises | |
|---|---|
TypeError
|
If any argument type mismatches. |
Methods
create
create(
local_unfinalized_metrics_type: tff.types.StructWithPythonType
) -> tff.templates.AggregationProcess
Creates a tff.templates.AggregationProcess for metrics aggregation.
| Args | |
|---|---|
local_unfinalized_metrics_type
|
A tff.types.StructWithPythonType (with
collections.OrderedDict as the Python container) of a client's local
unfinalized metrics. For example, local_unfinalized_metrics could
represent the output type of
tff.learning.models.VariableModel.report_local_unfinalized_metrics().
|
| Returns | |
|---|---|
An instance of tff.templates.AggregationProcess.
|
| Raises | |
|---|---|
TypeError
|
If any argument type mismatches; if the metric finalizers mismatch the type of local unfinalized metrics; if the initial unfinalized metrics mismatch the type of local unfinalized metrics. |
View source on GitHub