Backward computational graph

Is there any way to create backward computational graph with gradients either in tensorflow/keras?

Can you explain a little bit more your use case?

Just wanted to check if we can build reverse graph of the actual computational group with gradient nodes?

Do you have an example?

Are you looking for: tf.gradients  |  TensorFlow Core v2.8.0 ?

def simple_graph_function(x):
  return x ** 2

# You must be in graph mode to use tf.gradients e.g. inside
# the context of a tf.function. tf.gradients will return the gradients of ys w.r.t x.
# You're returning that result here so the resulting computational graph will be
# the "Backward computational graph"
def grad_of_simple_graph_function(x):
   y = simple_graph_function(x)
   return tf.gradients([y], [x])



[<tf.Tensor: shape=(), dtype=float32, numpy=4.0>]