View source on GitHub
|
Base class for polymorphic graph functions.
Inherits From: Callable
Graph functions are Python callable objects that dispatch calls to a TensorFlow graph. Polymorphic graph functions can be backed by multiple TF graphs, and automatically select the appropriate specialization based on the type of input they were called with. They may also create specializations on the fly if necessary, for example by tracing.
Also see tf.function.
Methods
experimental_get_compiler_ir
experimental_get_compiler_ir(
*args, **kwargs
)
Returns compiler IR for the compiled function.
This API is intended only for debugging as there are no guarantees on
backwards compatibility of returned IR or the allowed values of stage.
| Args | |
|---|---|
*args
|
Arguments used for compilation; same arguments as used for calling the function. Need to be eager tensors. |
**kwargs
|
Keyword arguments used for compilation. |
| Returns | |
|---|---|
Function callable with the following kwargs:
For example, for the output is: |
| Raises | |
|---|---|
ValueError
|
If an invalid stage is selected or if applied to a function
which is not compiled (jit_compile=True is not set).
|
TypeError
|
When called with input in graph mode. |
get_concrete_function
get_concrete_function(
*args, **kwargs
) -> tf.types.experimental.ConcreteFunction
Returns a ConcreteFunction specialized to input types.
The arguments specified by args and kwargs follow normal function call
rules. The returned ConcreteFunction has the same set of positional and
keyword arguments as self, but their types are compatible to the types
specified by args and kwargs (though not neccessarily equal).
@tf.functiondef f(x):return xf_concrete = f.get_concrete_function(tf.constant(1.0))f_concrete = f.get_concrete_function(x=tf.constant(1.0))
Unlike normal calls, get_concrete_function allow type specifiers instead
of TensorFlow objects, so for example tf.Tensors may be replaced with
tf.TensorSpecs.
@tf.functiondef f(x):return xf_concrete = f.get_concrete_function(tf.TensorSpec([], tf.float64))
If the function definition allows only one specialization, args and
kwargs may be omitted altogether.
@tf.function(input_signature=[tf.TensorSpec(None, tf.float32)])def f(x):return xf_concrete = f.get_concrete_function()
The returned ConcreteFunction can be called normally:
f_concrete(tf.constant(1.0))<tf.Tensor: shape=(), dtype=float32, numpy=1.0>f_concrete(x=tf.constant(1.0))<tf.Tensor: shape=(), dtype=float32, numpy=1.0>
| Args | |
|---|---|
*args
|
inputs to specialize on. |
**kwargs
|
inputs to specialize on. |
| Returns | |
|---|---|
A ConcreteFunction.
|
__call__
__call__(
*args, **kwargs
)
Executes this callable.
This behaves like a regular op - in eager mode, it immediately starts
execution, returning results. In graph mode, it creates ops which return
symbolic TensorFlow values (like tf.Tensor, tf.data.Dataset,
etc.). For example, tf.function callables typically generate a
tf.raw_ops.PartitionedCall op, but not always - the
exact operations being generated are an internal implementation detail.
| Args | |
|---|---|
*args
|
positional argument for this call |
**kwargs
|
keyword arguments for this call |
| Returns | |
|---|---|
| The execution results. |
View source on GitHub