Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility in 'tf.GradientTape.watch' of TensorFlow 2.17 in Keras 3.4.1 #20274

Open
yajuna opened this issue Sep 20, 2024 · 0 comments
Open
Assignees

Comments

@yajuna
Copy link

yajuna commented Sep 20, 2024

I read the issue 19155 (#19155), but still have problem

I am trying to perform gradient descent on the model.trainable variables, but have errors regarding model.trainable_variables

Tensorflow version is 2.17.0
keras version is 3.4.1

def get_grad(model, X_train, data_train):

with tf.GradientTape(persistent=True) as tape:
# This tape is for derivatives with
# respect to trainable variables
tape.watch(model.trainable_variables.value) ###added .value from issue 19155
loss = compute_loss(model, X_train, data_train)

g = tape.gradient(loss, model.trainable_variables.value) #
del tape

return loss, g

###################
Error:

AttributeError: in user code:

File "", line 7, in train_step *
loss, grad_theta = get_grad(model, X_train, data_train)
File "", line 6, in get_grad *
tape.watch(model.trainable_variables.value)

AttributeError: 'list' object has no attribute 'value'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants