STT-tensorflow/tensorflow/cc/gradients
2020-03-19 15:49:42 +03:30
..
array_grad_test.cc Add gradient for tensorflow::ops::Fill 2018-07-18 08:35:54 -07:00
array_grad.cc Temporary rollback of QuantizeAndDequantizeV2Grad. 2020-02-21 14:06:30 -08:00
data_flow_grad_test.cc
data_flow_grad.cc
grad_testutil.cc Remove using directives. Test appertaining to ops have been moved into namespace tensorflow::ops; all other tests now use explicit using-declarations. 2018-01-02 10:49:13 -08:00
grad_testutil.h
image_grad_test.cc
image_grad.cc Adds python gradients for ScaleAndTranslate ops, which are now used internal by tf.resize_images_v2 op. 2019-03-14 21:08:05 -07:00
manip_grad_test.cc Implement manip gradient in cc. 2020-03-19 15:49:42 +03:30
manip_grad.cc Implement manip gradient in cc. 2020-03-19 15:49:42 +03:30
math_grad_test.cc
math_grad.cc Define _USE_MATH_DEFINES for windows builds. 2019-12-20 14:43:49 -08:00
nn_grad_test.cc disabling subtests that test 3D pooling ops, and removing the no_rocm tag from //tensorflow/cc:gradients_nn_grad_test 2019-12-24 20:49:51 -08:00
nn_grad.cc minor spelling tweaks 2020-01-16 14:36:52 +09:00
README.md

C++ gradients

Gradients are currently being ported from python to C++ (in this directory).

Contributions are welcome and much appreciated; please follow the instructions below.

  1. Create the op gradient function in foo_grad.cc corresponding to the foo_grad.py file where the op originated (i.e. array_grad.py op gradients should be written in array_grad.cc).

  2. Write the op gradient with the following naming scheme:

    Status OpNameGrad(const Scope& scope, const Operation& op,
                      const std::vector<Output>& grad_inputs,
                      std::vector<Output>* grad_outputs) {
      ...
      return scope.status();
    }
    REGISTER_GRADIENT_OP("OpName", OpNameGrad);
    
  3. Ops gradients are implemented by using the C++ API.

  4. Tests should be included in foo_grad_test.cc. Please see array_grad_test.cc for an many examples. Tests are as simple as, creating a placeholder input for the op's inputs and calling RunTest (RunTest uses a gradient checker to verify that the theoretical gradient matches the numeric gradient). For example:

    TEST_F(ArrayGradTest, IdentityGrad) {
      TensorShape shape({5, 2});
      auto x = Placeholder(scope_, DT_FLOAT, Placeholder::Shape(shape));
      auto y = Identity(scope_, x);
      RunTest(x, shape, y, shape);
    }
    

NOTE: There are some ops that require features from the C++ API that are not yet implemented.

  • Ops that require PartialTensorShape information cannot yet be implemented.

  • Ops that require SparseTensor or IndexSlices (currently only in python) cannot yet be implemented.

  • Maybe more.

For questions: Please create an issue assigned to suharshs.