From 7e84ba0ea30f3642c75d8d3fce5626766ce5a20e Mon Sep 17 00:00:00 2001 From: Abhishek Jindal Date: Fri, 22 Mar 2024 10:39:19 -0700 Subject: [PATCH] remove const cast for DLManagedTensor (#20015) ### Description Removing const_cast as it might lead to unknown behavior. Specifying DLMangedTensor as a const doesn't seem to be necessary and I have tested this by running torch_ort.configure. Not sure what other tests which needs to be done. Background can be found in this [PR](https://github.com/microsoft/onnxruntime/pull/19982) ### Motivation and Context --- .../torch_cpp_extensions/aten_op_executor/aten_op_executor.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/python/torch_cpp_extensions/aten_op_executor/aten_op_executor.cc b/onnxruntime/python/torch_cpp_extensions/aten_op_executor/aten_op_executor.cc index 4148e63d58..f4d2f68d4d 100644 --- a/onnxruntime/python/torch_cpp_extensions/aten_op_executor/aten_op_executor.cc +++ b/onnxruntime/python/torch_cpp_extensions/aten_op_executor/aten_op_executor.cc @@ -36,7 +36,7 @@ struct ATenOperator { size_t return_size; std::vector ret_kinds; - c10::IValue ToIValueArgument(const DLManagedTensor* dlpack, size_t index) const { + c10::IValue ToIValueArgument(DLManagedTensor* dlpack, size_t index) const { TORCH_INTERNAL_ASSERT(index < argument_size); bool is_optional = is_optional_arguments[index]; TORCH_INTERNAL_ASSERT(dlpack || is_optional || default_values[index] || @@ -57,7 +57,7 @@ struct ATenOperator { c10::IValue i_value; // Create the torch tensor from this DLPack no matter we need it or not below, // so that the dlpack's deleter will be triggered when torch tensor is out of scope. - at::Tensor tensor = at::fromDLPack(const_cast(dlpack)); + at::Tensor tensor = at::fromDLPack(dlpack); switch (elem_kinds[index]) { case c10::TypeKind::TensorType: { i_value = is_optional ? c10::IValue(c10::optional(tensor)) : c10::IValue(tensor);