Fixed creation of ORT_Value to pass offset of 0 (#11004)

This commit is contained in:
Chandru Ramakrishnan 2022-03-25 15:52:10 -04:00 committed by GitHub
parent 47c09e6701
commit cb31b7eab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -133,7 +133,7 @@ OrtValue create_ort_value(
OrtValue ort_tensor;
onnxruntime::Tensor::InitOrtValue(element_type, onnxruntime::TensorShape(tensor.sizes().vec()), tensor.data_ptr(),
*mem_info, ort_tensor, tensor.storage_offset() * element_type->Size(),
*mem_info, ort_tensor, 0L /* offset = 0 - because tensor.data_ptr() includes the underyling offset */,
tensor.strides().vec());
return ort_tensor;
}

View file

@ -114,5 +114,11 @@ class OrtOpTests(unittest.TestCase):
x = cpu_tensor.min()
assert torch.allclose(x, y.cpu())
def test_narrow(self):
cpu_tensor = torch.rand(10, 10)
cpu_narrow = cpu_tensor.narrow(0, 5, 5)
ort_narrow = cpu_narrow.to('ort')
assert torch.allclose(cpu_narrow, ort_narrow.cpu())
if __name__ == '__main__':
unittest.main()