From 6fe02068af2ec9e7b0f49214e3ca84ed1d7cf6df Mon Sep 17 00:00:00 2001 From: Abhishek Jindal Date: Tue, 19 Mar 2024 17:00:44 -0700 Subject: [PATCH] Add const cast for DLManagedTensor (#19982) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description Add Const Cast for DLManagedTensor as PyTorch has changed it's [code](https://github.com/pytorch/pytorch/pull/121102) which creates incompatibility. ### Motivation and Context Fix the below error while configuring ORT-training with nightly PyTorch ``` aten_op_executor.cc:60:40: error: invalid conversion from ‘const DLManagedTensor*’ to ‘DLManagedTensor*’ [-fpermissive] 60 | at::Tensor tensor = at::fromDLPack(dlpack); | ^~~~~~ | | | const DLManagedTensor* ``` --- .../torch_cpp_extensions/aten_op_executor/aten_op_executor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e8be98cbfc0e4..4148e63d58619 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 @@ -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(dlpack); + at::Tensor tensor = at::fromDLPack(const_cast(dlpack)); switch (elem_kinds[index]) { case c10::TypeKind::TensorType: { i_value = is_optional ? c10::IValue(c10::optional(tensor)) : c10::IValue(tensor);