DLPack: add test using PyTorch DLPack functions.#8294
Merged
Conversation
JackCaoG
approved these changes
Oct 21, 2024
vanbasten23
approved these changes
Oct 21, 2024
Collaborator
Author
|
Not sure this was ok to merge, since it still depends on pytorch/pytorch#138470 (as noted by the |
qihqi
added a commit
that referenced
this pull request
Oct 30, 2024
ysiraichi
commented
Nov 1, 2024
Comment on lines
+2915
to
+2925
| @onlyIfTorchSupportsCUDA | ||
| @onlyIfPJRTDeviceIsCUDA | ||
| def test_dlpack_xla_to_pytorch_cuda_protocol_conversion(self): | ||
| xla_t1 = torch.arange(5).to(xm.xla_device()) | ||
| caps_t1 = torch.utils.dlpack.to_dlpack(xla_t1) | ||
| cuda_t1 = torch.utils.dlpack.from_dlpack(caps_t1) | ||
| self.assertEqual(cuda_t1.device.type, 'cuda') | ||
| self.assertEqual(cuda_t1.device.index, xla_t1.device.index) | ||
| cuda_t1[0] = cuda_t1[0] + 20 | ||
| self.assertTrue(torch.allclose(xla_t1.cpu(), cuda_t1.cpu())) | ||
|
|
Collaborator
Author
There was a problem hiding this comment.
@vanbasten23 @JackCaoG @qihqi
I was wondering why removing .torch_pin (#8344) wasn't breaking CI. I realized that it was because I modified the test @vanbasten23 had implemented, calling to_dlpack(...), and only then from_dlpack(...). In summary: it was correct, and I messed it up. Anyway, I will open a PR fixing this, so as to have it merged after pytorch/pytorch#138470.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Taking over: #7213
This PR introduces a test using PyTorch's
to_dlpackandfrom_dlpackfunctions. In order to use the former, PyTorch's tensor__dlpack__and__dlpack_device__methods had to be modified. The actual changes are in pytorch/pytorch#138470.