啟用/禁用 tf.function
的即刻執行。
用法
tf.config.run_functions_eagerly(
run_eagerly
)
參數
-
run_eagerly
布爾值。是否即刻地運行函數。
調用tf.config.run_functions_eagerly(True)
將使tf.function
的所有調用立即運行,而不是作為跟蹤圖函數運行。
這對於調試很有用。
def my_func(a):
print("Python side effect")
return a + a
a_fn = tf.function(my_func)
# A side effect the first time the function is traced
a_fn(tf.constant(1))
Python side effect
<tf.Tensor:shape=(), dtype=int32, numpy=2>
# No further side effect, as the traced function is called
a_fn(tf.constant(2))
<tf.Tensor:shape=(), dtype=int32, numpy=4>
# Now, switch to eager running
tf.config.run_functions_eagerly(True)
# Side effect, as the function is called directly
a_fn(tf.constant(2))
Python side effect
<tf.Tensor:shape=(), dtype=int32, numpy=4>
# Turn this back off
tf.config.run_functions_eagerly(False)
注意:此標誌對作為參數傳遞給 tf.data 轉換的函數沒有影響。 tf.data 函數永遠不會即刻地執行,並且始終作為已編譯的 Tensorflow Graph 執行。
相關用法
- Python tf.config.list_logical_devices用法及代碼示例
- Python tf.config.experimental.get_memory_usage用法及代碼示例
- Python tf.config.list_physical_devices用法及代碼示例
- Python tf.config.get_logical_device_configuration用法及代碼示例
- Python tf.config.experimental.get_memory_info用法及代碼示例
- Python tf.config.experimental.enable_tensor_float_32_execution用法及代碼示例
- Python tf.config.experimental_connect_to_cluster用法及代碼示例
- Python tf.config.experimental.set_memory_growth用法及代碼示例
- Python tf.config.experimental_connect_to_host用法及代碼示例
- Python tf.config.set_visible_devices用法及代碼示例
- Python tf.config.set_logical_device_configuration用法及代碼示例
- Python tf.config.experimental.enable_op_determinism用法及代碼示例
- Python tf.config.get_visible_devices用法及代碼示例
- Python tf.config.experimental.get_device_details用法及代碼示例
- Python tf.config.experimental.ClusterDeviceFilters用法及代碼示例
- Python tf.config.experimental.reset_memory_stats用法及代碼示例
- Python tf.config.experimental.get_memory_growth用法及代碼示例
- Python tf.concat用法及代碼示例
- Python tf.convert_to_tensor用法及代碼示例
- Python tf.constant_initializer.from_config用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.config.run_functions_eagerly。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。