Commit a6924e6a authored by Mingsheng Hong's avatar Mingsheng Hong Committed by TensorFlower Gardener
Browse files

Added tracing support to the eager C++ layer, where we can create a graph by

symbolically executing a sequence of eager ops. This involves the following
changes:

1. Extended the eager C++ layer with symbolic tensor support, where a
tensorflow::TensorHandle represents a graph node, whose execution yields the
"concrete" tensor value. In contrast, the existing tensor handles are conrete
tensors.

Symbolic tensors can be created from a graph node (represented as TF_Output) via
TFE_NewTensorHandleFromTFOutput(). The associated graph node can be retrieved
from a symbolic tensor via TFE_GetTFOutputFromTensorHandle().

2. Added another experimental C API TFE_AddEagerOpToGraph() for symbolic
execution of a TFE_Op, which converts the op to a graph node, and the graph is
associated with a newly added TFE_TraceContext object to be passed into the C
API call.

3. If an eager op OP takes any concrete tensors as input,
TFE_AddEagerOpToGraph() will create symbolic tensors for them, to serve as input
to the converted graph node from OP. When executing that graph, those concrete
tensors will be fed as input.

Here's an example tracing use case illustrated by Swift code:
let x = Tensor<Float>(1.0)
let y = x + x

The first statement is executed on the host, yielding a concrete tensor value
for x.

The second statement is first symbolically executed to create a
graph (containing the "Add" node). Next, the graph is executed to compute y.

During this symbolic execution, TFE_AddEagerOpToGraph() is called on the "Add"
eager op for x + x, to insert an "Add" graph node. The node takes as input a
symbolic tensor (a PlaceHolder graph node) corresponding to x. When executing
the graph, the concrete tensor of x is then fed as the input.

TFE_AddEagerOpToGraph() does not yet support TF op attributes.

An example call-site code of this feature is Swift for TensorFlow at
https://github.com/apple/swift/pull/21589 (where some of the above C APIs are
subject to name changes).

PiperOrigin-RevId: 230018312
parent f631a565
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment