Missed TensorFlow World? Check out the recap. Learn more

tff.utils.IterativeProcess

View source on GitHub

Class IterativeProcess

A process that includes an initialization and iterated computation.

An iterated process will usually be driven by a control loop like:

def initialize():
  ...

def next(state):
  ...

iterative_process = IterativeProcess(initialize, next)
state = iterative_process.initialize()
for round in range(num_rounds):
  state = iterative_process.next(state)

The iteration step can accept arguments in addition to state (which must be the first argument), and return additional arguments:

def next(state, item):
  ...

iterative_process = ...
state = iterative_process.initialize()
for round in range(num_rounds):
  state, output = iterative_process.next(state, round)

__init__

View source

__init__(
    initialize_fn,
    next_fn
)

Creates a tff.IterativeProcess.

Args:

  • initialize_fn: a no-arg tff.Computation that creates the initial state of the chained computation.
  • next_fn: a tff.Computation that defines an iterated function. If initialize_fn returns a type T, then next_fn must also return type T or multiple values where the first is of type T, and accept either a single argument of type T or multiple arguments where the first argument must be of type T.

Raises:

  • TypeError: initialize_fn and next_fn are not compatible function types.

Properties

initialize

A no-arg tff.Computation that returns the initial state.

next

A tff.Computation that produces the next state.

The first argument of should always be the current state (originally produced by tff.IterativeProcess.initialize), and the first (or only) returned value is the updated state.

Returns:

A tff.Computation.