Minimize python code in supporting TF_Function.
After this change when C API is enabled, function support in Python is done with minimal use of Python code. In particular, we don't create or store FunctionDef in Python. Small changes include: - We don't use _hash_str for function comparisons in Python. Instead, we delegate this logic to TF_GraphCopyFunction in C API. - We checking for duplication function additions from _DefinedFunction.add_to_graph(graph) to Graph._add_function in all cases. This is more logical and make it easier to support both modes. - We change some error messages to be same in both modes. - Since we don't store FunctionDef in C API mode in Python but get it on demand, access to common attributes like name or signature can become expensive. To mitigate this, we cache the signature (OpDef) of the function in Python. Signatures are generally much smaller than whole definitions. - Add context manager for creating and destroying TF_Buffers. - Allow zero output tensorflow functions in Python The C API and C++ runtime support functions without outputs, but Python APIs explicitly disallowed them before this change. This change allows zero output functions in Python and cleans some hacks that were added to side-step regular Python function APIs before. PiperOrigin-RevId: 171201162
Loading
Please sign in to comment