A backend is the composition of a compiler and a runtime in a Context used to construct, compile, and execute an AST, meaning a backend constructs environments that evaluate an AST.

The backends package contains backends which may extend the TFF compiler and/or the TFF runtime; these extensions can be found in the corresponding backend.

If the runtime of a backend is implemented as an execution stack, then the backend can construct an ExecutionContext to provide TFF with an environemnt in which to evaluate an AST. In this case, the backend is integrating with TFF using the high-level abstraction. However, if the runtime is not implemented as an execution stack, then the backend will need to construct a Context and is integrating with TFF using the low-level abstraction.

<!--#include file=""-->

The blue nodes are provided by TFF core.

The green, red, yellow, and purple nodes are provided by the native, mapreduce, iree, and reference backends respectively.

The dashed nodes are provided by an external system.

The solid arrows indicate relationship and the dashed arrows indicate inheritance.


The native backend composes of the TFF compiler and TFF runtime in order to compile and execute an AST in a way that is reasonably efficiant and debuggable.

Native Form

A native form is an AST that is topologically sorted into a directed acyclic graph (DAG) of TFF intrinsics with some optimizations to the dependency of those intrinsics.


The compiler.transform_to_native_form function compiles an AST into a native form.


The native backend does not contain backend specific extentions to the TFF runtime, instead an execution stack can be used directly.


A native context is an ExecutionContext constructed with a native compiler (or no compiler) and a TFF runtime, for example:

executor = eager_tf_executor.EagerTFExecutor()
factory = executor_factory.create_executor_factory(lambda _: executor)
context = execution_context.ExecutionContext(

However, there are some common configurations:

The execution_context.set_local_execution_context function constructs an ExecutionContext with a native compiler and a local execution stack.


The mapreduce backend contains the data structures and compiler required to construct a form that can be executed on MapReduce-like runtimes.


A canonical_form.CanonicalForm is a data structure defining the representation of logic that can be executed on MapReduce-like runtimes. This logic is organized as a collection of TensorFlow functions, see the canonical_form module for more information about the nature of these functions.


The transformations module contains Building Block and TensorFlow Computation transformations required to compile an AST to a CanonicalForm.

The canonical_form_utils module contains the compiler for the MapReduce backend and constructs a CanonicalForm.


A MapReduce runtime is not provided by TFF, instead this should be provided by an external MapReduce-like system.


A MapReduce context is not provided by TFF.


IREE is an experimental compiler backend for MLIR.

The iree backend contains the data structures, compiler, and runtime required to execute an AST.


The compiler module contains transformations required to comiple an AST to a form that can be exected using an executor.IreeExecutor.


The executor.IreeExecutor is an Executor that executes computations by delegating to an IREE runtime. This executor can be composed with other Executors from the TFF runtime in order to construct an execution stack representing an IREE runtime.


An iree context is ExecutionContext constructed with an iree compiler and an execution stack with an executor.IreeExecutor delegating to an external IREE runtime.


A reference_context.ReferenceContext is a context_base.Context that compiles and executes ASTs. Note that the ReferenceContext does not inherit from execution_context.ExecutionContext and the runtime is not implemented as an execution stack; instead the compiler and runtime are trivially implemented inline in the ReferenceContext.