From 44396f47f6213d3d224d090dc8c1ddb4839b3fb0 Mon Sep 17 00:00:00 2001 From: Dero Gharibian Date: Tue, 18 Aug 2020 10:29:23 -0700 Subject: [PATCH] 'convert_string' superfluous after cl/318933001 PiperOrigin-RevId: 327255887 Change-Id: Ia6d88299ee30caf961408c6afcc6fda19fbaefa2 --- .../c/eager/immediate_execution_context.h | 13 ++++--------- .../core/common_runtime/eager/context.cc | 19 +++++-------------- .../core/common_runtime/eager/context.h | 1 - tensorflow/python/client/tf_session_helper.cc | 5 ++--- tensorflow/python/lib/core/ndarray_tensor.cc | 12 +++++------- tensorflow/python/lib/core/ndarray_tensor.h | 2 +- tensorflow/python/lib/core/py_seq_tensor.cc | 3 +-- 7 files changed, 18 insertions(+), 37 deletions(-) diff --git a/tensorflow/c/eager/immediate_execution_context.h b/tensorflow/c/eager/immediate_execution_context.h index 6d06d9a8de6..02a3320ef65 100644 --- a/tensorflow/c/eager/immediate_execution_context.h +++ b/tensorflow/c/eager/immediate_execution_context.h @@ -57,15 +57,10 @@ class ImmediateExecutionContext : public AbstractContext { // Create a tensor instance from the given data buffer and description. // `memory_releaser` will be called on destruction, and it's responsible for - // cleaning up the underlying buffer. `convert_string` indicates whether it - // has to handle tstring conversion. Expected to be removed once tstring - // migration is done. - virtual AbstractTensorInterface* CreateTensor(DataType dtype, - const int64_t* dims, - int num_dims, void* data, - size_t len, bool convert_string, - MemoryReleaser memory_releaser, - void* memory_releaser_arg) = 0; + // cleaning up the underlying buffer. + virtual AbstractTensorInterface* CreateTensor( + DataType dtype, const int64_t* dims, int num_dims, void* data, size_t len, + MemoryReleaser memory_releaser, void* memory_releaser_arg) = 0; // Create a handle to wrap and manage a Tensor virtual ImmediateExecutionTensorHandle* CreateLocalHandle( diff --git a/tensorflow/core/common_runtime/eager/context.cc b/tensorflow/core/common_runtime/eager/context.cc index bf2fc0dcc69..196c4635ac4 100644 --- a/tensorflow/core/common_runtime/eager/context.cc +++ b/tensorflow/core/common_runtime/eager/context.cc @@ -170,24 +170,15 @@ AbstractTensorInterface* EagerContext::CreateTensor( AbstractTensorInterface* EagerContext::CreateTensor( DataType dtype, const int64_t* dims, int num_dims, void* data, size_t len, - bool convert_string, MemoryReleaser memory_releaser, - void* memory_releaser_arg) { + MemoryReleaser memory_releaser, void* memory_releaser_arg) { TF_Tensor* tensor_wrapper = TF_NewTensor(static_cast(dtype), dims, num_dims, data, len, memory_releaser, memory_releaser_arg); - if (convert_string) { - tensorflow::Tensor tensor; - Status status = TF_TensorToTensor(tensor_wrapper, &tensor); - TF_DeleteTensor(tensor_wrapper); - if (!status.ok()) return nullptr; - return new TensorInterface(std::move(tensor)); - } else { - AbstractTensorInterface* result = nullptr; - std::swap(result, tensor_wrapper->tensor); - TF_DeleteTensor(tensor_wrapper); - return result; - } + AbstractTensorInterface* result = nullptr; + std::swap(result, tensor_wrapper->tensor); + TF_DeleteTensor(tensor_wrapper); + return result; } void EagerContext::ResetPFLR(const DeviceMgr* device_mgr, Env* env, diff --git a/tensorflow/core/common_runtime/eager/context.h b/tensorflow/core/common_runtime/eager/context.h index 286eb44fbeb..1e8460ed35f 100644 --- a/tensorflow/core/common_runtime/eager/context.h +++ b/tensorflow/core/common_runtime/eager/context.h @@ -174,7 +174,6 @@ class EagerContext : public ImmediateExecutionContext, public core::RefCounted { DataType dtype, absl::Span dim_sizes) override; AbstractTensorInterface* CreateTensor(DataType dtype, const int64_t* dims, int num_dims, void* data, size_t len, - bool convert_string, MemoryReleaser memory_releaser, void* memory_releaser_arg) override; diff --git a/tensorflow/python/client/tf_session_helper.cc b/tensorflow/python/client/tf_session_helper.cc index cb960fd599a..3bb87cdd4d6 100644 --- a/tensorflow/python/client/tf_session_helper.cc +++ b/tensorflow/python/client/tf_session_helper.cc @@ -89,8 +89,7 @@ void TF_Run_wrapper_helper(TF_DeprecatedSession* session, const char* handle, input_names.push_back(key_string); inputs_safe.emplace_back(make_safe(static_cast(nullptr))); - s = NdarrayToTensor(nullptr /*ctx*/, value, &inputs_safe.back(), - true /*convert_to_string*/); + s = NdarrayToTensor(nullptr /*ctx*/, value, &inputs_safe.back()); if (!s.ok()) { Set_TF_Status_from_Status(out_status, s); return; @@ -383,7 +382,7 @@ void TF_SessionRun_wrapper_helper(TF_Session* session, const char* handle, std::vector input_vals_safe; for (PyObject* ndarray : input_ndarrays) { input_vals_safe.emplace_back(make_safe(static_cast(nullptr))); - s = NdarrayToTensor(nullptr, ndarray, &input_vals_safe.back(), true); + s = NdarrayToTensor(nullptr, ndarray, &input_vals_safe.back()); if (!s.ok()) { Set_TF_Status_from_Status(out_status, s); return; diff --git a/tensorflow/python/lib/core/ndarray_tensor.cc b/tensorflow/python/lib/core/ndarray_tensor.cc index 7be05c03e36..03fbea39748 100644 --- a/tensorflow/python/lib/core/ndarray_tensor.cc +++ b/tensorflow/python/lib/core/ndarray_tensor.cc @@ -470,7 +470,7 @@ Status TF_TensorToPyArray(Safe_TF_TensorPtr tensor, PyObject** out_ndarray) { } Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray, - Safe_TF_TensorPtr* ret, bool convert_string) { + Safe_TF_TensorPtr* ret) { DCHECK(ret != nullptr); // Make sure we dereference this array object in case of error, etc. @@ -501,7 +501,7 @@ Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray, if (ctx) { *ret = make_safe(new TF_Tensor{tensorflow::unwrap(ctx)->CreateTensor( static_cast(dtype), {}, 0, PyArray_DATA(array), - size, convert_string, &DelayedNumpyDecref, array)}); + size, &DelayedNumpyDecref, array)}); } else { *ret = make_safe(TF_NewTensor(dtype, {}, 0, PyArray_DATA(array), size, &DelayedNumpyDecref, array)); @@ -513,8 +513,7 @@ Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray, if (ctx) { *ret = make_safe(new TF_Tensor{tensorflow::unwrap(ctx)->CreateTensor( static_cast(dtype), dims.data(), dims.size(), - PyArray_DATA(array), size, convert_string, &DelayedNumpyDecref, - array)}); + PyArray_DATA(array), size, &DelayedNumpyDecref, array)}); } else { *ret = make_safe(TF_NewTensor(dtype, dims.data(), dims.size(), PyArray_DATA(array), size, @@ -528,7 +527,7 @@ Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray, if (ctx) { *ret = make_safe(new TF_Tensor{tensorflow::unwrap(ctx)->CreateTensor( static_cast(dtype), dims.data(), dims.size(), - encoded, size, convert_string, + encoded, size, [](void* data, size_t len, void* arg) { delete[] reinterpret_cast(data); }, @@ -551,8 +550,7 @@ TF_Tensor* TF_TensorFromTensor(const tensorflow::Tensor& src, Status* status); Status NdarrayToTensor(PyObject* obj, Tensor* ret) { Safe_TF_TensorPtr tf_tensor = make_safe(static_cast(nullptr)); - Status s = NdarrayToTensor(nullptr /*ctx*/, obj, &tf_tensor, - false /*convert_string*/); + Status s = NdarrayToTensor(nullptr /*ctx*/, obj, &tf_tensor); if (!s.ok()) { return s; } diff --git a/tensorflow/python/lib/core/ndarray_tensor.h b/tensorflow/python/lib/core/ndarray_tensor.h index 38c098417d5..e7657778fa8 100644 --- a/tensorflow/python/lib/core/ndarray_tensor.h +++ b/tensorflow/python/lib/core/ndarray_tensor.h @@ -36,7 +36,7 @@ Status TF_TensorToPyArray(Safe_TF_TensorPtr tensor, PyObject** out_ndarray); // Expected to be removed once tstring migration is done. ABSL_MUST_USE_RESULT Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray, - Safe_TF_TensorPtr* ret, bool convert_string); + Safe_TF_TensorPtr* ret); // Creates a tensor in 'ret' from the input Ndarray. // TODO(kkb): This is an old conversion function that does not support TFRT. diff --git a/tensorflow/python/lib/core/py_seq_tensor.cc b/tensorflow/python/lib/core/py_seq_tensor.cc index 0139355c6b7..9acb6d4a283 100644 --- a/tensorflow/python/lib/core/py_seq_tensor.cc +++ b/tensorflow/python/lib/core/py_seq_tensor.cc @@ -686,8 +686,7 @@ typedef Converter BoolConverter; // other. TFE_TensorHandle* NumpyToTFE_TensorHandle(TFE_Context* ctx, PyObject* obj) { Safe_TF_TensorPtr tf_tensor = make_safe(static_cast(nullptr)); - Status status = tensorflow::NdarrayToTensor(ctx, obj, &tf_tensor, - true /*convert_string*/); + Status status = tensorflow::NdarrayToTensor(ctx, obj, &tf_tensor); if (TF_PREDICT_FALSE(!status.ok())) { PyErr_SetString(PyExc_ValueError,