tf.custom_gradient | TensorFlow Core v2.7.0
www.tensorflow.org › python › tftf.custom_gradient ( f=None ) Used in the notebooks Used in the guide Advanced automatic differentiation This decorator allows fine grained control over the gradients of a sequence for operations. This may be useful for multiple reasons, including providing a more efficient or numerically stable gradient for a sequence of operations.
python - tensorflow: gradients for a custom loss function ...
stackoverflow.com › questions › 46606633Oct 06, 2017 · @tf.custom_gradient def loss_function(y_true, y_pred, peak_value=3, weight=2) ## your code def grad(dy): return dy * partial_derivative return loss, grad Where partial_derivative is the analytically evaluated partial derivative with respect to your loss function. If your loss function is a function of more than one variable, it will require a partial derivative respect to each variable, I believe.