MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / func_graph_from_py_func

Function func_graph_from_py_func

tensorflow/python/framework/function.py:880–967  ·  view source on GitHub ↗

Returns a _FuncGraph generated from `func`. Args: func: A Python callable which constructs a TF function body. The arguments must correspond to `arg_types`. Returns a value or list/tuple of values. No returned value can be None. arg_names: A sequence of strings for the functio

(func,
                            arg_names,
                            arg_types,
                            name=None,
                            capture_by_value=False,
                            device=None,
                            colocation_stack=None,
                            container=None,
                            collections_ref=None,
                            arg_shapes=None,
                            whitelisted_stateful_ops=None,
                            capture_resource_var_by_value=True)

Source from the content-addressed store, hash-verified

878
879
880def func_graph_from_py_func(func,
881 arg_names,
882 arg_types,
883 name=None,
884 capture_by_value=False,
885 device=None,
886 colocation_stack=None,
887 container=None,
888 collections_ref=None,
889 arg_shapes=None,
890 whitelisted_stateful_ops=None,
891 capture_resource_var_by_value=True):
892 """Returns a _FuncGraph generated from `func`.
893
894 Args:
895 func: A Python callable which constructs a TF function body. The arguments
896 must correspond to `arg_types`. Returns a value or list/tuple of values.
897 No returned value can be None.
898 arg_names: A sequence of strings for the function argument names.
899 arg_types: A sequence of the function's argument types.
900 name: The function name. If None, the name is derived from `func`.
901 capture_by_value: boolean. If True, captured values will be copied into the
902 function body.
903 device: device name or function.
904 colocation_stack: A colocation stack (list) the _FuncGraph should use.
905 container: A container name the _FuncGraph should start with.
906 collections_ref: A reference to a collections dict the _FuncGraph should
907 use internally.
908 arg_shapes: A sequence of the function's argument shapes.
909 whitelisted_stateful_ops: A set of ops that if stateful we ignore and
910 re-create.
911 capture_resource_var_by_value: Boolean (defaults to True). If False,
912 captured resource variable returns the handle instead of value.
913
914 Returns:
915 A _FuncGraph.
916
917 Raises:
918 ValueError: if func returns None.
919 """
920 if not name:
921 name = function_utils.get_func_name(func)
922 func_graph = _FuncGraph(name, capture_by_value, whitelisted_stateful_ops,
923 capture_resource_var_by_value)
924
925 with func_graph.as_default(), ops.device(device):
926 # pylint: disable=protected-access
927 if collections_ref is not None:
928 func_graph._collections = collections_ref
929 if container is not None:
930 func_graph._container = container
931 if colocation_stack is not None:
932 func_graph._colocation_stack = colocation_stack
933 # pylint: enable=protected-access
934
935 if arg_shapes is None:
936 arg_shapes = [None] * len(arg_types)
937

Callers 1

Calls 9

_FuncGraphClass · 0.85
anyFunction · 0.85
variable_scopeMethod · 0.80
funcFunction · 0.50
as_defaultMethod · 0.45
deviceMethod · 0.45
placeholderMethod · 0.45
appendMethod · 0.45
captureMethod · 0.45

Tested by

no test coverage detected