0

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!

asked Jan 3, 2022 at 20:08

1 Answer 1

0

Tensorflow has no attribute called defun.

If you are using tf 1.x, use

tf.contrib.eager.defun
answered Jan 25, 2022 at 5:46
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.