diff options
author | 2018-05-10 15:54:13 -0700 | |
---|---|---|
committer | 2018-05-10 15:56:58 -0700 | |
commit | 8a8dddf8bd93946d02fa080f8103943a03a6a274 (patch) | |
tree | f1f6c446bdc42dab532deed0458780f014a46e8b /tensorflow/c/eager | |
parent | f7e24ab1113ae7094e4831a606a29e0d5b956bfe (diff) |
Do not differentiate integers in the eager backprop API.
(with bugfix)
PiperOrigin-RevId: 196184587
Diffstat (limited to 'tensorflow/c/eager')
-rw-r--r-- | tensorflow/c/eager/tape.h | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/tensorflow/c/eager/tape.h b/tensorflow/c/eager/tape.h index 8026076b9e..dcc2357b71 100644 --- a/tensorflow/c/eager/tape.h +++ b/tensorflow/c/eager/tape.h @@ -130,13 +130,15 @@ class GradientTape { } } - bool ShouldRecord(gtl::ArraySlice<int64> tensor_ids); + bool ShouldRecord(gtl::ArraySlice<int64> tensor_ids, + gtl::ArraySlice<tensorflow::DataType> dtypes); void Watch(int64 tensor_id); void RecordOperation(const string& op_type, gtl::ArraySlice<TapeTensor> output_tensors, gtl::ArraySlice<int64> input_tensor_id, + gtl::ArraySlice<tensorflow::DataType> input_dtypes, BackwardFunction* backward_function, const std::function<void()>& backward_function_deleter); @@ -170,12 +172,32 @@ class GradientTape { // Template instantiations here +inline bool IsDtypeTrainable(DataType dtype) { + switch (dtype) { + case DT_HALF: + case DT_BFLOAT16: + case DT_FLOAT: + case DT_DOUBLE: + case DT_COMPLEX64: + case DT_COMPLEX128: + case DT_RESOURCE: + case DT_VARIANT: + return true; + default: + return false; + } +} + template <typename Gradient, typename BackwardFunction> bool GradientTape<Gradient, BackwardFunction>::ShouldRecord( - gtl::ArraySlice<int64> tensor_ids) { - for (int64 i : tensor_ids) { - if (tensor_tape_.find(i) != tensor_tape_.end()) { - return true; + gtl::ArraySlice<int64> tensor_ids, + gtl::ArraySlice<tensorflow::DataType> dtypes) { + CHECK_EQ(tensor_ids.size(), dtypes.size()); + for (int i = 0; i < tensor_ids.size(); ++i) { + if (tensor_tape_.find(tensor_ids[i]) != tensor_tape_.end()) { + if (IsDtypeTrainable(dtypes[i])) { + return true; + } } } return false; @@ -189,9 +211,11 @@ void GradientTape<Gradient, BackwardFunction>::Watch(int64 tensor_id) { template <typename Gradient, typename BackwardFunction> void GradientTape<Gradient, BackwardFunction>::RecordOperation( const string& op_type, gtl::ArraySlice<TapeTensor> output_tensors, - gtl::ArraySlice<int64> input_tensor_id, BackwardFunction* backward_function, + gtl::ArraySlice<int64> input_tensor_id, + gtl::ArraySlice<tensorflow::DataType> input_dtypes, + BackwardFunction* backward_function, const std::function<void()>& backward_function_deleter) { - if (!ShouldRecord(input_tensor_id)) { + if (!ShouldRecord(input_tensor_id, input_dtypes)) { backward_function_deleter(); return; } |