Skip to content

Unexpected Gradient error (No gradient defined for op: OnesLike) #14

@jvanecek

Description

@jvanecek

I intend to write the second example in the GradientTape tutorial

x = tf.constant(3.0)
with tf.GradientTape() as g:
  g.watch(x)
  with tf.GradientTape() as gg:
    gg.watch(x)
    y = x * x
  dy_dx = gg.gradient(y, x)     # Will compute to 6.0
d2y_dx2 = g.gradient(dy_dx, x)  # Will compute to 2.0

in TensorFlowCAPITest>>#testNestedGradient but the got the following error

NOT_FOUND: No gradient defined for op: OnesLike. Please see https://www.tensorflow.org/code/tensorflow/cc/gradients/README.md for instructions on how to add C++ gradients.

It seems gradientsOf:respectTo: in VAST is not doing the same as the gradient in python.

  • gradientsOf:respectTo: ends up calling the C++ api TF_AddGradients
  • while gradient in python calls tensorflow.python.eager.imperative_grad.imperative_grad, which calls tensorflow.python.pywrap_tensorflow.TFE_Py_TapeGradient, which is a C++ function calling ComputeGradient.

(Case reproduced in this commit)

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions