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

Function add_execution_callback

tensorflow/python/eager/execution_callbacks.py:243–284  ·  view source on GitHub ↗

Add an execution callback to the default eager context. An execution callback is invoked immediately after an eager operation or function has finished execution, providing access to the op's type, name input and output tensors. Multiple execution callbacks can be added, in which case the ca

(callback)

Source from the content-addressed store, hash-verified

241
242
243def add_execution_callback(callback):
244 """Add an execution callback to the default eager context.
245
246 An execution callback is invoked immediately after an eager operation or
247 function has finished execution, providing access to the op's type, name
248 input and output tensors. Multiple execution callbacks can be added, in
249 which case the callbacks will be invoked in the order in which they are
250 added. To clear all execution callbacks that have been added, use
251 `clear_execution_callbacks()`.
252
253 Example:
254 ```python
255 def print_even_callback(op_type, inputs, attrs, outputs, op_name):
256 # A callback that prints only the even output values.
257 if outputs[0].numpy() % 2 == 0:
258 print("Even output from %s: %s" % (op_name or op_type, outputs))
259 tfe.add_execution_callback(print_even_callback)
260
261 x = tf.pow(2.0, 3.0) - 3.0
262 y = tf.multiply(x, tf.add(1.0, 5.0))
263 # When the line above is run, you will see all intermediate outputs that are
264 # even numbers printed to the console.
265
266 tfe.clear_execution_callbacks()
267 ```
268
269 Args:
270 callback: a callable of the signature
271 `f(op_type, inputs, attrs, outputs, op_name)`.
272 `op_type` is the type of the operation that was just executed (e.g.,
273 `MatMul`).
274 `inputs` is the `list` of input `Tensor`(s) to the op.
275 `attrs` contains the attributes of the operation as a `tuple` of
276 alternating attribute name and attribute value.
277 `outputs` is the `list` of output `Tensor`(s) from the op.
278 `op_name` is the name of the operation that was just executed. This
279 name is set by the client who created the operation and can be `None`
280 if it is unset.
281 Return value(s) from the callback are ignored.
282 """
283 execute.execute = execute.execute_with_callbacks
284 context.context().add_post_execution_callback(callback)
285
286
287def clear_execution_callbacks():

Callers

nothing calls this directly

Calls 2

contextMethod · 0.45

Tested by

no test coverage detected