Home | History | Annotate | only in /external/tensorflow/tensorflow/cc/gradients
Up to higher level directory
NameDateSize
array_grad.cc21-Aug-201815.5K
array_grad_test.cc21-Aug-201812.6K
data_flow_grad.cc21-Aug-20185.7K
data_flow_grad_test.cc21-Aug-20182.6K
grad_testutil.cc21-Aug-20181.3K
grad_testutil.h21-Aug-20181.3K
math_grad.cc21-Aug-201838.2K
math_grad_test.cc21-Aug-201826.2K
nn_grad.cc21-Aug-20188.4K
nn_grad_test.cc21-Aug-20187.4K
README.md21-Aug-20182K

README.md

      1 # C++ gradients
      2 
      3 Gradients are currently being ported from
      4 [python](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/python/ops)
      5 to C++ (in this directory).
      6 
      7 Contributions are welcome and much appreciated; please follow the instructions
      8 below.
      9 
     10 1.  Create the op gradient function in `foo_grad.cc` corresponding to the
     11     `foo_grad.py` file where the op originated (i.e. `array_grad.py` op
     12     gradients should be written in `array_grad.cc`).
     13 
     14 2.  Write the op gradient with the following naming scheme:
     15 
     16         Status OpNameGrad(const Scope& scope, const Operation& op,
     17                           const std::vector<Output>& grad_inputs,
     18                           std::vector<Output>* grad_outputs) {
     19           ...
     20           return scope.status();
     21         }
     22         REGISTER_GRADIENT_OP("OpName", OpNameGrad);
     23 
     24 3.  Ops gradients are implemented by using the [C++
     25     API](https://www.tensorflow.org/api_docs/cc/).
     26 
     27 4.  Tests should be included in `foo_grad_test.cc`. Please see
     28     [`array_grad_test.cc`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/cc/gradients/array_grad_test.cc)
     29     for an many examples. Tests are as simple as, creating a placeholder input
     30     for the op's inputs and calling `RunTest` (`RunTest` uses a [gradient
     31     checker](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/cc/framework/gradient_checker.cc)
     32     to verify that the theoretical gradient matches the numeric gradient). For
     33     example:
     34 
     35         TEST_F(ArrayGradTest, IdentityGrad) {
     36           TensorShape shape({5, 2});
     37           auto x = Placeholder(scope_, DT_FLOAT, Placeholder::Shape(shape));
     38           auto y = Identity(scope_, x);
     39           RunTest(x, shape, y, shape);
     40         }
     41 
     42 NOTE: There are some ops that require features from the C++ API that are not yet
     43 implemented.
     44 
     45 *   Ops that require PartialTensorShape information cannot yet be implemented.
     46 
     47 *   Ops that require SparseTensor or IndexSlices (currently only in python)
     48     cannot yet be implemented.
     49 
     50 *   Maybe more.
     51 
     52 For questions: Please create an issue assigned to suharshs.
     53