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

Method _variable_creator_scope

tensorflow/python/framework/ops.py:2932–2963  ·  view source on GitHub ↗

Scope which defines a variable creation function. Args: creator: A callable taking `next_creator` and `kwargs`. See the `tf.variable_creator_scope` docstring. priority: Creators with a higher `priority` are called first. Within the same priority, creators are called

(self, creator, priority=100)

Source from the content-addressed store, hash-verified

2930 # frozen, and this functionality is still not ready for public visibility.
2931 @tf_contextlib.contextmanager
2932 def _variable_creator_scope(self, creator, priority=100):
2933 """Scope which defines a variable creation function.
2934
2935 Args:
2936 creator: A callable taking `next_creator` and `kwargs`. See the
2937 `tf.variable_creator_scope` docstring.
2938 priority: Creators with a higher `priority` are called first. Within the
2939 same priority, creators are called inner-to-outer.
2940
2941 Yields:
2942 `_variable_creator_scope` is a context manager with a side effect, but
2943 doesn't return a value.
2944
2945 Raises:
2946 RuntimeError: If variable creator scopes are not properly nested.
2947 """
2948 # This step keeps a reference to the existing stack, and it also initializes
2949 # self._thread_local._variable_creator_stack if it doesn't exist yet.
2950 old = self._variable_creator_stack
2951 new = list(old)
2952 new.append((priority, creator))
2953 # Sorting is stable, so we'll put higher-priority creators later in the list
2954 # but otherwise maintain registration order.
2955 new.sort(key=lambda item: item[0])
2956 self._thread_local._variable_creator_stack = new # pylint: disable=protected-access
2957 try:
2958 yield
2959 finally:
2960 if self._thread_local._variable_creator_stack is not new: # pylint: disable=protected-access
2961 raise RuntimeError(
2962 "Exiting variable_creator_scope without proper nesting.")
2963 self._thread_local._variable_creator_stack = old # pylint: disable=protected-access
2964
2965 # Note: this method is private because the API of tf.Graph() is public and
2966 # frozen, and this functionality is still not ready for public visibility.

Callers 4

variable_creator_scopeFunction · 0.80
wrapped_fnMethod · 0.80
_recreate_variableMethod · 0.80

Calls 2

appendMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected