aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/c/c_api.h
diff options
context:
space:
mode:
authorGravatar Suharsh Sivakumar <suharshs@google.com>2017-04-13 11:42:52 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-04-13 13:05:08 -0700
commit908d5b6ede6ae829dff138a873eec397ef434cd6 (patch)
treede7898ec319637d2f6d4a78067715bd02808fb02 /tensorflow/c/c_api.h
parent59ccf014e89ff625dc3d9779e1fb54a980c4b6ac (diff)
Add C++ gradients to c_api.
#6268 This CL does the following: (1) Adds TF_AddGradients function to C_API which adds gradient nodes for the specified inputs. (2) Adds internal constructor for Scope, need to create a scope from an existing graph in the c_api. (3) Adds constructor for AddSymbolicGradients that assumes OnesLike when grad_inputs aren't provided. (4) Improves error message when gradients aren't provided. Change: 153092774
Diffstat (limited to 'tensorflow/c/c_api.h')
-rw-r--r--tensorflow/c/c_api.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/tensorflow/c/c_api.h b/tensorflow/c/c_api.h
index 9b08f9d981..88438a3585 100644
--- a/tensorflow/c/c_api.h
+++ b/tensorflow/c/c_api.h
@@ -898,7 +898,7 @@ typedef struct TF_WhileParams {
// TF_FinishWhile() or TF_AbortWhile().
//
// Missing functionality (TODO):
-// - Gradients (not yet implmented for any ops)
+// - Gradients
// - Reference-type inputs
// - Directly referencing external tensors from the cond/body graphs (this is
// possible in the Python API)
@@ -921,7 +921,22 @@ void TF_FinishWhile(const TF_WhileParams* params, TF_Status* status,
// called after a successful TF_NewWhile() call.
void TF_AbortWhile(const TF_WhileParams* params);
-// TODO(andydavis): Function to add gradients to a graph.
+// Adds operations to compute the partial derivatives of sum of `y`s w.r.t `x`s,
+// i.e., d(y_1 + y_2 + ...)/dx_1, d(y_1 + y_2 + ...)/dx_2...
+// `dx` are used as initial gradients (which represent the symbolic partial
+// derivatives of some loss function `L` w.r.t. `y`).
+// `dx` must be nullptr or have size `ny`.
+// If `dx` is nullptr, the implementation will use dx of `OnesLike` for all
+// shapes in `y`.
+// The partial derivatives are returned in `dy`. `dy` should be allocated to
+// size `nx`.
+//
+// WARNING: This function does not yet support all the gradients that python
+// supports. See
+// https://www.tensorflow.org/code/tensorflow/cc/gradients/README.md
+// for instructions on how to add C++ more gradients.
+void TF_AddGradients(TF_Graph* g, TF_Output* y, int ny, TF_Output* x, int nx,
+ TF_Output* dx, TF_Status* status, TF_Output* dy);
// TODO(josh11b): Register OpDef, available to all operations added
// to this graph.