diff --git a/ivy/functional/backends/tensorflow/gradients.py b/ivy/functional/backends/tensorflow/gradients.py index da688a2dd71f5..c1e2b848e78cd 100644 --- a/ivy/functional/backends/tensorflow/gradients.py +++ b/ivy/functional/backends/tensorflow/gradients.py @@ -76,6 +76,16 @@ def execute_with_gradients( _get_required_float_variables(xs, xs_grad_idxs) ) + # Conversion of KerasVariable to tf.Variable within xs_required container, so they can be watched + if ivy.is_ivy_container(xs_required): + ivy.nested_map( + lambda x: x._value + if "keras.src.backend.tensorflow.core.Variable" in str(x.__class__) + else x, + xs_required, + include_derived=True, + ) + # Creating a tape to record operations with tf.GradientTape(persistent=True, watch_accessed_variables=False) as tape: tape.watch(xs_required)