检查当前线程是否启用了即刻执行。
用法
tf.executing_eagerly()
返回
-
True
如果当前线程启用了即刻执行。
默认情况下启用即刻执行,并且此 API 在大多数情况下返回 True
。但是,在以下用例中,此 API 可能会返回 False
。
- 在
tf.function
内部执行,除非之前调用了tf.init_scope
或tf.config.run_functions_eagerly(True)
。 - 在
tf.dataset
的转换函数中执行。 tf.compat.v1.disable_eager_execution()
被调用。
一般情况:
print(tf.executing_eagerly())
True
tf.function
内部:
@tf.function
def fn():
with tf.init_scope():
print(tf.executing_eagerly())
print(tf.executing_eagerly())
fn()
True
False
在 tf.config.run_functions_eagerly(True)
之后的 tf.function
内部被调用:
tf.config.run_functions_eagerly(True)
@tf.function
def fn():
with tf.init_scope():
print(tf.executing_eagerly())
print(tf.executing_eagerly())
fn()
True
True
tf.config.run_functions_eagerly(False)
在 tf.dataset
的转换函数内部:
def data_fn(x):
print(tf.executing_eagerly())
return x
dataset = tf.data.Dataset.range(100)
dataset = dataset.map(data_fn)
False
相关用法
- Python tf.experimental.dlpack.from_dlpack用法及代码示例
- Python tf.experimental.numpy.iinfo用法及代码示例
- Python tf.experimental.Optional.has_value用法及代码示例
- Python tf.experimental.dispatch_for_unary_elementwise_apis用法及代码示例
- Python tf.experimental.dispatch_for_api用法及代码示例
- Python tf.experimental.unregister_dispatch_for用法及代码示例
- Python tf.experimental.tensorrt.Converter用法及代码示例
- Python tf.experimental.ExtensionType用法及代码示例
- Python tf.experimental.Optional.get_value用法及代码示例
- Python tf.experimental.numpy.issubdtype用法及代码示例
- Python tf.extract_volume_patches用法及代码示例
- Python tf.experimental.numpy.unicode_用法及代码示例
- Python tf.expand_dims用法及代码示例
- Python tf.experimental.dlpack.to_dlpack用法及代码示例
- Python tf.experimental.async_scope用法及代码示例
- Python tf.experimental.Optional.empty用法及代码示例
- Python tf.experimental.numpy.float16.as_integer_ratio用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.executing_eagerly。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。