Skip to content

Commit

Permalink
remove const cast for DLManagedTensor (microsoft#20015)
Browse files Browse the repository at this point in the history
### Description
<!-- Describe your changes. -->
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](microsoft#19982)


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
  • Loading branch information
ajindal1 authored and Ted Themistokleous committed May 7, 2024
1 parent fe044be commit 2b3d343
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct ATenOperator {
size_t return_size;
std::vector<c10::TypeKind> 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] ||
Expand All @@ -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<DLManagedTensor*>(dlpack));
at::Tensor tensor = at::fromDLPack(dlpack);
switch (elem_kinds[index]) {
case c10::TypeKind::TensorType: {
i_value = is_optional ? c10::IValue(c10::optional<at::Tensor>(tensor)) : c10::IValue(tensor);
Expand Down

0 comments on commit 2b3d343

Please sign in to comment.