Support structured source in GradientTape.gradient
authorIgor Ganichev <iga@google.com>
Thu, 29 Mar 2018 03:51:01 +0000 (20:51 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Thu, 29 Mar 2018 03:53:48 +0000 (20:53 -0700)
commit3f7adc710495e1160acd956c482779247ef1f101
treeb050b53db22e8f3f382a22c13ebe558f832fd168
parentbb582f1b6fad474bc446c78a6683247a8eb6048e
Support structured source in GradientTape.gradient

Before this change, it was easy to forget [] around the source tensor.
This mistake lead to GradientTape.gradient(), returning a list of Nones.
Nones normally tell to the user that the source and the target are
not connected via differentiable operations, which is not the source
of the error in this case.

Instead of adding a check that `sources` is a list of tensors, this CL
adds ability to handle structured source (which includes a lone tensor),
similarly to many existing TensorFlow APIs.

Also, with Alex's help, it fixes a bug where repeated tensors in
`sources` were not handled correctly.

PiperOrigin-RevId: 190878583
tensorflow/c/eager/tape.h
tensorflow/python/eager/backprop.py
tensorflow/python/eager/backprop_test.py
tensorflow/python/eager/pywrap_tfe_src.cc