【发布时间】:2020-01-06 17:27:43
【问题描述】:
如果我在初始化 tf.Variable 后尝试更改 TensorFlow 2 中的并行度,
import tensorflow as tf
_ = tf.Variable([1])
tf.config.threading.set_inter_op_parallelism_threads(1)
我收到一个错误
RuntimeError:初始化后无法修改 Inter op 并行度。
我理解为什么会这样,但它(以及可能的其他因素)导致我的测试相互干扰。例如
def test_model(): # this test
v = tf.Variable([1])
...
def test_threading(): # is breaking this test
tf.config.threading.set_inter_op_parallelism_threads(1)
...
如何重置 TensorFlow 状态以便设置线程?
【问题讨论】:
标签: python tensorflow pytest tensorflow2.0