1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CC_FRAMEWORK_GRADIENTS_H_
17 #define TENSORFLOW_CC_FRAMEWORK_GRADIENTS_H_
18 
19 #include "tensorflow/cc/framework/ops.h"
20 #include "tensorflow/cc/framework/scope.h"
21 
22 namespace tensorflow {
23 
24 /// NOTE: This API is a work in progress and will likely be changing frequently.
25 ///
26 /// Given initial gradients 'grad_inputs' (which represent the symbolic partial
27 /// derivatives of some loss function 'L' w.r.t 'outputs'), adds gradient nodes
28 /// to the graph associated with 'scope', which compute (and return in
29 /// 'grad_outputs') the symbolic partial derivatives of 'L' w.r.t 'inputs'.
30 Status AddSymbolicGradients(const Scope& scope,
31                             const std::vector<Output>& outputs,
32                             const std::vector<Output>& inputs,
33                             const std::vector<Output>& grad_inputs,
34                             std::vector<Output>* grad_outputs);
35 
36 // Same as above, but uses 'OnesLike' for all shapes in
37 // 'outputs' as grad_inputs.
38 Status AddSymbolicGradients(const Scope& scope,
39                             const std::vector<Output>& outputs,
40                             const std::vector<Output>& inputs,
41                             std::vector<Output>* grad_outputs);
42 
43 /// Returns a sentinel Output that represents 'no gradient' (i.e. no gradient
44 /// flows along some graph edge during backpropagation).
45 /// Can be returned in 'grad_outputs' by an invocation of 'AddSymbolicGradients'
46 /// (note that gradient flow through an Output can be stopped through the use of
47 /// the StopGradient node).
48 Output NoGradient();
49 
50 }  // namespace tensorflow
51 
52 #endif  // TENSORFLOW_CC_FRAMEWORK_GRADIENTS_H_
53