tff.templates.AggregationProcess
Stay organized with collections
Save and categorize content based on your preferences.
A stateful process that aggregates values.
Inherits From: MeasuredProcess
, IterativeProcess
tff.templates.AggregationProcess(
initialize_fn: tff.Computation
,
next_fn: tff.Computation
)
Used in the notebooks
This class inherits the constraints documented by
tff.templates.MeasuredProcess
.
A tff.templates.AggregationProcess
is a tff.templates.MeasuredProcess
that formalizes the type signature of initialize_fn
and next_fn
for
aggregation.
Compared to the tff.templates.MeasuredProcess
, this class requires a second
input argument, which is a value placed at CLIENTS
and to be aggregated.
The result
field of returned tff.templates.MeasuredProcessOutput
,
representing the aggregate, must be placed at SERVER
and does not
necessarily need to have type signature equal to the type signature of the
second input argument.
The intended composition pattern for tff.templates.AggregationProcess
is
that of nesting. An aggregation will broadly consist of three logical parts:
- A pre-aggregation computation placed at
CLIENTS
.
- Actual aggregation.
- A post-aggregation computation placed at
SERVER
.
The second step can be realized by direct application of appropriate intrinsic
such as tff.federated_sum
, or by delegation to (one or more) "inner"
aggregation processes.
Both initialize
and next
must be tff.Computation
s with the following
type signatures:
- initialize:
( -> S@SERVER)
- next:
(<S@SERVER, V@CLIENTS, *> ->
<state=S@SERVER, result=V'@SERVER, measurements=M@SERVER>)
where *
represents optional other arguments placed at CLIENTS
. This can be
used for weighted aggregation, where the third parameter is the weight.
Note that while the value type to be aggregated will often be preserved
(i.e., V == V'
), it is not required. An example is sampling-based
aggregation.
Args |
initialize_fn
|
A no-arg tff.Computation that returns the initial state
of the aggregation process. The returned state must be a server-placed
federated value. Let the type of this state be called S@SERVER .
|
next_fn
|
A tff.Computation that represents the iterated function.
next_fn must accept at least two arguments, the first of which is of a
type assignable from the state type S@SERVER and the second of which
is client-placed data of type V@CLIENTS . next_fn must return a
MeasuredProcessOutput where the state attribute is assignable to the
first argument and the result is value placed at SERVER .
|
Raises |
TypeError
|
If initialize_fn and next_fn are not instances of
tff.Computation .
|
TemplateInitFnParamNotEmptyError
|
If initialize_fn has any input
arguments.
|
TemplateStateNotAssignableError
|
If the state returned by either
initialize_fn or next_fn is not assignable to the first input
argument of next_fn .
|
TemplateNotMeasuredProcessOutputError
|
If next_fn does not return a
MeasuredProcessOutput .
|
TemplateNextFnNumArgsError
|
If next_fn does not have at least two
input arguments.
|
AggregationNotFederatedError
|
If initialize_fn and next_fn are not
computations operating on federated types.
|
AggregationPlacementError
|
If the placements of initialize_fn and
next_fn are not matching the expected type signature.
|
Attributes |
initialize
|
A no-arg tff.Computation that returns the initial state.
|
is_weighted
|
True if next takes a third argument for weights.
|
next
|
A tff.Computation that runs one iteration of the process.
Its first argument should always be the current state (originally produced
by the initialize attribute), the second argument must be the input placed
at CLIENTS , and the return type must be a
tff.templates.MeasuredProcessOutput with each field placed at SERVER .
|
state_type
|
The tff.Type of the state of the process.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-20 UTC.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.templates.AggregationProcess\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\nA stateful process that aggregates values.\n\nInherits From: [`MeasuredProcess`](../../tff/templates/MeasuredProcess), [`IterativeProcess`](../../tff/templates/IterativeProcess) \n\n tff.templates.AggregationProcess(\n initialize_fn: ../../tff/Computation,\n next_fn: ../../tff/Computation\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|---------------------------------------------------------------------------------------------------------|\n| - [Implementing Custom Aggregations](https://www.tensorflow.org/federated/tutorials/custom_aggregators) |\n\nThis class inherits the constraints documented by\n[`tff.templates.MeasuredProcess`](../../tff/templates/MeasuredProcess).\n\nA [`tff.templates.AggregationProcess`](../../tff/templates/AggregationProcess) is a [`tff.templates.MeasuredProcess`](../../tff/templates/MeasuredProcess)\nthat formalizes the type signature of `initialize_fn` and `next_fn` for\naggregation.\n\nCompared to the [`tff.templates.MeasuredProcess`](../../tff/templates/MeasuredProcess), this class requires a second\ninput argument, which is a value placed at `CLIENTS` and to be aggregated.\nThe `result` field of returned [`tff.templates.MeasuredProcessOutput`](../../tff/templates/MeasuredProcessOutput),\nrepresenting the aggregate, must be placed at `SERVER` and does not\nnecessarily need to have type signature equal to the type signature of the\nsecond input argument.\n\nThe intended composition pattern for [`tff.templates.AggregationProcess`](../../tff/templates/AggregationProcess) is\nthat of nesting. An aggregation will broadly consist of three logical parts:\n\n- A pre-aggregation computation placed at `CLIENTS`.\n- Actual aggregation.\n- A post-aggregation computation placed at `SERVER`. The second step can be realized by direct application of appropriate intrinsic such as [`tff.federated_sum`](../../tff/federated_sum), or by delegation to (one or more) \"inner\" aggregation processes.\n\nBoth `initialize` and `next` must be [`tff.Computation`](../../tff/Computation)s with the following\ntype signatures:\n\n- initialize: `( -\u003e S@SERVER)`\n- next: `(\u003cS@SERVER, V@CLIENTS, *\u003e -\u003e\n \u003cstate=S@SERVER, result=V'@SERVER, measurements=M@SERVER\u003e)` where `*` represents optional other arguments placed at `CLIENTS`. This can be used for weighted aggregation, where the third parameter is the weight.\n\nNote that while the value type to be aggregated will often be preserved\n(i.e., `V == V'`), it is not required. An example is sampling-based\naggregation.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `initialize_fn` | A no-arg [`tff.Computation`](../../tff/Computation) that returns the initial state of the aggregation process. The returned state must be a server-placed federated value. Let the type of this state be called `S@SERVER`. |\n| `next_fn` | A [`tff.Computation`](../../tff/Computation) that represents the iterated function. `next_fn` must accept at least two arguments, the first of which is of a type assignable from the state type `S@SERVER` and the second of which is client-placed data of type `V@CLIENTS`. `next_fn` must return a `MeasuredProcessOutput` where the `state` attribute is assignable to the first argument and the `result` is value placed 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 `initialize_fn` and `next_fn` are not instances of [`tff.Computation`](../../tff/Computation). |\n| `TemplateInitFnParamNotEmptyError` | If `initialize_fn` has any input arguments. |\n| `TemplateStateNotAssignableError` | If the `state` returned by either `initialize_fn` or `next_fn` is not assignable to the first input argument of `next_fn`. |\n| `TemplateNotMeasuredProcessOutputError` | If `next_fn` does not return a `MeasuredProcessOutput`. |\n| `TemplateNextFnNumArgsError` | If `next_fn` does not have at least two input arguments. |\n| `AggregationNotFederatedError` | If `initialize_fn` and `next_fn` are not computations operating on federated types. |\n| `AggregationPlacementError` | If the placements of `initialize_fn` and `next_fn` are not matching the expected type signature. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `initialize` | A no-arg [`tff.Computation`](../../tff/Computation) that returns the initial state. |\n| `is_weighted` | True if `next` takes a third argument for weights. |\n| `next` | A [`tff.Computation`](../../tff/Computation) that runs one iteration of the process. \u003cbr /\u003e Its first argument should always be the current state (originally produced by the `initialize` attribute), the second argument must be the input placed at `CLIENTS`, and the return type must be a [`tff.templates.MeasuredProcessOutput`](../../tff/templates/MeasuredProcessOutput) with each field placed at `SERVER`. |\n| `state_type` | The [`tff.Type`](../../tff/types/Type) of the state of the process. |\n\n\u003cbr /\u003e"]]