Skip to content

Keras 3: Access gradients during training #20066

Answered by fchollet
ghsanti asked this question in Q&A
Discussion options

You must be logged in to vote

Do get access to gradients, you have to write a custom train_step() for your model (you can still use fit()). Like this:

https://keras.io/guides/custom_train_step_in_jax/
https://keras.io/guides/custom_train_step_in_tensorflow/
https://keras.io/guides/custom_train_step_in_torch/

Custom callbacks don't have access to gradients by default.

An alternative can also be to write a custom optimizer, since optimizers have access to gradients.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ghsanti
Comment options

Answer selected by ghsanti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants