1 /* Copyright 2017 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_WHILE_GRADIENTS_H_ 17 #define TENSORFLOW_CC_FRAMEWORK_WHILE_GRADIENTS_H_ 18 19 #include "tensorflow/cc/framework/ops.h" 20 #include "tensorflow/cc/framework/scope.h" 21 #include "tensorflow/core/graph/while_context.h" 22 23 // Utility functions for constructing while loop gradients 24 25 namespace tensorflow { 26 27 // Adds the gradient computation for the while loop associated with 28 // `while_ctx`. `grad_inputs` are the partial derivatives w.r.t. the loop 29 // outputs, i.e. the exit nodes. The partial derivatives w.r.t. the loop 30 // inputs, i.e. the input loop vars, are returned in `grad_outputs`. 31 // `grad_inputs` and `grad_outputs` are both in loop-variable order, as defined 32 // by the original inputs to BuildWhileLoop(). 33 // TODO(skyewm): maybe comment on NoGradient once it's supported 34 Status AddWhileLoopGradient(WhileContext* while_ctx, const Scope& scope, 35 const std::vector<Output>& grad_inputs, 36 std::vector<Output>* grad_outputs); 37 38 } // namespace tensorflow 39 40 #endif // TENSORFLOW_CC_FRAMEWORK_WHILE_GRADIENTS_H_ 41