Missed TensorFlow World? Check out the recap. Learn more

tff.framework.EagerExecutor

View source on GitHub

Class EagerExecutor

The eager executor only runs TensorFlow, synchronously, in eager mode.

Inherits From: Executor

TODO(b/134764569): Add support for data as a building block.

This executor understands the following TFF types: tensors, sequences, named tuples, and functions. It does not understand placements, federated, or abstract types.

This executor understands the following kinds of TFF computation building blocks: tensorflow computations, and external data. It does not understand lambda calculus or any compositional constructs. Tuples and selections can only be created using create_tuple() and create_selection() in the API.

The arguments to be ingested can be Python constants of simple types, nested structures of those, as well as eager tensors and eager datasets.

The external data references must identify files available in the executor's filesystem. The exact format is yet to be documented.

The executor will be able to place work on specific devices (e.g., on GPUs). In contrast to the reference executor, it handles data sets in a pipelined fashion, and does not place limits on the data set sizes. It also avoids marshaling TensorFlow values in and out between calls.

It does not deal with multithreading, checkpointing, federated computations, and other concerns to be covered by separate executor components. It runs the operations it supports in a synchronous fashion. Asynchrony and other aspects not supported here should be handled by composing this executor with other executors into a complex executor stack, rather than mixing in all the logic.

NOTE: This component is only available in Python 3.

__init__

View source

__init__(device=None)

Creates a new instance of an eager executor.

Args:

  • device: An optional name of the device that this executor will schedule all of its operations to run on. It is the caller's responsibility to select a correct device name. For example, the list of physical devices can be obtained using tf.config.experimental.list_physical_devices().

Raises:

  • RuntimeError: If not executing eagerly.
  • TypeError: If the device name is not a string.
  • ValueError: If there is no device device.

Methods

create_call

View source

create_call(
    comp,
    arg=None
)

Creates a call to comp with optional arg.

Args:

  • comp: As documented in executor_base.Executor.
  • arg: As documented in executor_base.Executor.

Returns:

An instance of EagerValue representing the result of the call.

Raises:

  • RuntimeError: If not executing eagerly.
  • TypeError: If the arguments are of the wrong types.

create_selection

View source

create_selection(
    source,
    index=None,
    name=None
)

Creates a selection from source.

Args:

  • source: As documented in executor_base.Executor.
  • index: As documented in executor_base.Executor.
  • name: As documented in executor_base.Executor.

Returns:

An instance of EagerValue that represents the constructed selection.

Raises:

  • TypeError: If arguments are of the wrong types.
  • ValueError: If either both, or neither of name and index are present.

create_tuple

View source

create_tuple(elements)

Creates a tuple of elements.

Args:

  • elements: As documented in executor_base.Executor.

Returns:

An instance of EagerValue that represents the constructed tuple.

create_value

View source

create_value(
    value,
    type_spec=None
)

Embeds value of type type_spec within this executor.

Args:

  • value: An object that represents the value to embed within the executor.
  • type_spec: The tff.Type of the value represented by this object, or something convertible to it. Can optionally be None if value is an instance of typed_object.TypedObject.

Returns:

An instance of EagerValue.

Raises:

  • RuntimeError: If not executing eagerly.
  • TypeError: If the arguments are of the wrong types.
  • ValueError: If the type was not specified and cannot be determined from the value.