W3cubDocs

/TensorFlow 2.4

tf.experimental.async_scope

Context manager for grouping async operations.

Ops/function calls inside the scope can return before finishing the actual execution. When exiting the async scope, a synchronization barrier will be automatically added to ensure the completion of all async op and function execution, potentially raising exceptions if async execution results in an error state.

Users may write the following code to asynchronuously invoke train_step_fn and log the loss metric for every num_steps steps in a training loop. train_step_fn internally consumes data using iterator.get_next(), and may throw OutOfRangeError when running out of data. In the case:

try:
  with tf.experimental.async_scope():
    for _ in range(num_steps):
      # Step function updates the metric `loss` internally
      train_step_fn()
except tf.errors.OutOfRangeError:
  tf.experimental.async_clear_error()
logging.info('loss = %s', loss.numpy())
Yields
Context manager for grouping async operations.

© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.4/api_docs/python/tf/experimental/async_scope