Python tensorflow概率中的急切执行在第二次迭代时停止记录梯度
不知怎的,我的火车圈里没有梯度。下面是一个简单的例子Python tensorflow概率中的急切执行在第二次迭代时停止记录梯度,python,tensorflow,tensorflow-probability,eager-execution,Python,Tensorflow,Tensorflow Probability,Eager Execution,不知怎的,我的火车圈里没有梯度。下面是一个简单的例子 import tensorflow as tf import tensorflow_probability as tfp tf.enable_eager_execution() hidden_size = 32 output_size = 1 m = tf.keras.Sequential( [ tfp.layers.DenseLocalReparameterization(hidden_size, tf.nn.le
import tensorflow as tf
import tensorflow_probability as tfp
tf.enable_eager_execution()
hidden_size = 32
output_size = 1
m = tf.keras.Sequential(
[
tfp.layers.DenseLocalReparameterization(hidden_size, tf.nn.leaky_relu),
tfp.layers.DenseLocalReparameterization(hidden_size, tf.nn.leaky_relu),
tfp.layers.DenseLocalReparameterization(output_size)
]
)
如果我运行梯度记录步骤两次,第二次不会显示任何梯度。返回类型为None
的列表
for _ in range(2):
with tf.GradientTape() as tape:
loss_value = m(tf.ones((1, 2))) * 2
print(tape.gradient(loss_value, m.trainable_variables))
如果我们用“标准”tensorflow模型替换模型m
,则情况并非如此,即
m=tf.keras.Sequential([tf.keras.layers.density(1)])
我使用的是tensorflow=1.13.1和tensorflow概率=0.6.0,这似乎是一个临时错误。我上传到了tensorflow和tensorflow probability的夜间版本,问题就解决了。我们昨天刚刚修复了这些层类中TF2渐变的一些问题,因此您最近的更新可能捕获了这些修复。如果您还有任何问题,请告诉我们!(请在github上的问题跟踪器上随时提交问题--)。干杯