Python 如何在TensorFlow中使用急切执行实现张量的自定义梯度
在本()教程中,提供了一种实现自定义渐变函数的方法Python 如何在TensorFlow中使用急切执行实现张量的自定义梯度,python,tensorflow,gradient-descent,Python,Tensorflow,Gradient Descent,在本()教程中,提供了一种实现自定义渐变函数的方法 @tfe.custom_gradient def log1pexp(x): e = tf.exp(x) def grad(dy): return dy * (1 - 1 / (1 + e)) return tf.log(1 + e), grad grad_log1pexp = tfe.gradients_function(log1pexp) # Works as before at x = 0. assert 0.5 ==
@tfe.custom_gradient
def log1pexp(x):
e = tf.exp(x)
def grad(dy):
return dy * (1 - 1 / (1 + e))
return tf.log(1 + e), grad
grad_log1pexp = tfe.gradients_function(log1pexp)
# Works as before at x = 0.
assert 0.5 == float(grad_log1pexp(0.)[0])
# But now works at x = 100 as well.
assert 1.0 == float(grad_log1pexp(100.)[0])
我想为矩阵指数实现一个梯度函数,在这种情况下,变量是张量。我尝试了直截了当的方法,但似乎失败了
我的问题是:
你能补充一些你尝试过的细节和失败的原因吗?