![]() |
A stateful process that aggregates values.
Inherits From: MeasuredProcess
, IterativeProcess
tff.templates.AggregationProcess(
initialize_fn: tff.Computation
,
next_fn: tff.Computation
)
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 aggregatred.
The result
field of returned tff.templates.MeasuredProcessOutput
must have
type signature equal to this value, but placed at SERVER
.
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 astff.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 atCLIENTS
.
Args | |
---|---|
initialize_fn
|
A no-arg tff.Computation that creates the initial state
of the aggregation process.
|
next_fn
|
A tff.Computation that defines an iterated function. If
initialize_fn returns a type S@SERVER , then next_fn must return a
MeasuredProcessOutput where the state attribute matches the type
S@SERVER , and accepts at least two argument of types S@SERVER
and V@CLIENTS , or more arguments where the first two argument must be
of types S@SERVER and V@CLIENTS . The result attribute of output
returned by next_fn must be of type V@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.
|
AggregationValueTypeMismatchError
|
If the second input argument of
next_fn does not have the same non-federated type as the "result"
attribute of the returned value.
|
Attributes | |
---|---|
initialize
|
A no-arg tff.Computation that returns the initial state.
|
next
|
A tff.Computation that runs one iteration of the process.
Its first argument should always be the current state (originally produced
by the |
state_type
|
The tff.Type of the state of the process.
|