• Home
  • History
  • Annotate
  • only in /external/tensorflow/tensorflow/cc/gradients/
NameDateSize

..10-Aug-20184 KiB

array_grad.cc10-Aug-201815.5 KiB

array_grad_test.cc10-Aug-201812.6 KiB

data_flow_grad.cc10-Aug-20185.7 KiB

data_flow_grad_test.cc10-Aug-20182.6 KiB

grad_testutil.cc10-Aug-20181.3 KiB

grad_testutil.h10-Aug-20181.3 KiB

math_grad.cc10-Aug-201838.2 KiB

math_grad_test.cc10-Aug-201826.2 KiB

nn_grad.cc10-Aug-20188.4 KiB

nn_grad_test.cc10-Aug-20187.4 KiB

README.md10-Aug-20182 KiB

README.md

1# C++ gradients
2
3Gradients are currently being ported from
4[python](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/python/ops)
5to C++ (in this directory).
6
7Contributions are welcome and much appreciated; please follow the instructions
8below.
9
101.  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
142.  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
243.  Ops gradients are implemented by using the [C++
25    API](https://www.tensorflow.org/api_docs/cc/).
26
274.  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
42NOTE: There are some ops that require features from the C++ API that are not yet
43implemented.
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
52For questions: Please create an issue assigned to suharshs.
53