I am currently working with NeuralODE on google CoLab, and I tried to use a command, 'defun', without success. I am using Tensorflow version 1.x which is a requirement for NeuralODE, but when I try to use tf.defun, I get the error "AttributeError: module 'tensorflow' has no attribute 'defun'. How can I actually get to defun?
This is the particular bit of code I need it for
def compute_gradients_and_update():
with tf.GradientTape() as g:
hN = neural_ode.forward(h0_var)
g.watch(hN)
loss = tf.reduce_sum((hN_target - hN)**2)
dLoss = g.gradient(loss, hN) # same what 2 * (hN_target - hN)
h0_reconstruction, dfdh0, dWeights = neural_ode.backward(hN, dLoss)
optimizer.apply_gradients([(dfdh0, h0_var)])
return loss
compute_gradients_and_update = tf.defun(compute_gradients_and_update)
I have seen similar questions on stackoverflow, but the solutions are all very specficic and I haven't seen any about 'defun' specifically. I hope this makes sense, I am a beginner.
Thanks!
1 Answer 1
Tensorflow has no attribute called defun.
If you are using tf 1.x, use
tf.contrib.eager.defun