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 · 1 comment
Open

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'

@mehtamansi29
Copy link
Collaborator

Hi @yajuna -

Thanks for reporting this issue. Can you provide more details about your compute loss function and dummy datasets to reproduce this issue ?

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

No branches or pull requests

2 participants