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

Function invoke_op_callbacks

tensorflow/python/framework/op_callbacks.py:156–221  ·  view source on GitHub ↗

r"""Invoke the callbacks that exist in the current scope (if any). If no callbacks are present in the current scope, this method returns immediately. Args: op_type: Type of the operation (e.g., "MatMul"). inputs: Input tensors to the op. These are `EagerTensor`s in the case of

(op_type,
                        inputs,
                        attrs,
                        outputs,
                        op_name=None,
                        graph=None)

Source from the content-addressed store, hash-verified

154
155
156def invoke_op_callbacks(op_type,
157 inputs,
158 attrs,
159 outputs,
160 op_name=None,
161 graph=None):
162 r"""Invoke the callbacks that exist in the current scope (if any).
163
164 If no callbacks are present in the current scope, this method returns
165 immediately.
166
167 Args:
168 op_type: Type of the operation (e.g., "MatMul").
169 inputs: Input tensors to the op. These are `EagerTensor`s in the case of
170 eager execution of ops or `FuncGraph`s, and are non-eager `Tensor`s in the
171 case of graph construction.
172 attrs: Attributes of the op, as `tuple` of alternating keys and values.
173 outputs: Output tensors from the op. These are `EagerTensor`s in the case of
174 eager execution and are non-eager `Tensor`s in the case of graph
175 construction.
176 op_name: Name of the op. Applicable if and only if this method is invoked
177 due to the graph construction of an op or the eager execution of of a
178 `FuncGraph`.
179 graph: The graph involved (if any).
180 - In the case if the eager execution of an op or FuncGraph, this is
181 `None`.
182 - In the case of the graph construction of an op, this is the `tf.Graph`
183 object being built.
184
185 Returns:
186 `None`, or a `list` or `tuple` of output tenors that will override the
187 original (input) `outputs`.
188 """
189 if _state.callback_stack:
190 # Guards against stack overflow that can result from recursive invocation
191 # due to op constructions inside client-supplied op callbacks.
192 _state.invoking_callbacks = True
193 try:
194 if isinstance(attrs, dict):
195 attrs_list = []
196 for key in attrs:
197 attrs_list.append(key)
198 attrs_list.append(attrs[key])
199 attrs_tuple = tuple(attrs_list)
200 else:
201 attrs_tuple = attrs
202
203 new_outputs = outputs
204 for callback in reversed(_state.callback_stack):
205 new_outputs = callback(
206 op_type,
207 inputs,
208 attrs_tuple,
209 new_outputs,
210 op_name=op_name,
211 graph=graph)
212 if new_outputs is not None and len(new_outputs) != len(outputs):
213 raise ValueError(

Callers

nothing calls this directly

Calls 3

tupleFunction · 0.85
callbackFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected