keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
62.07k stars 19.48k forks source link

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

Closed yajuna closed 3 weeks ago

yajuna commented 1 month ago

I read the issue 19155 (https://github.com/keras-team/keras/issues/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 commented 1 month ago

Hi @yajuna -

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

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] commented 3 weeks ago

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.

google-ml-butler[bot] commented 3 weeks ago

Are you satisfied with the resolution of your issue? Yes No