8000 Improve docs for `from_dlpack` and `to_dlpack` by rgommers · Pull Request #70437 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Improve docs for from_dlpack and to_dlpack #70437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use torch.from_dlpack in the examples
Leave `to_dlpack` in the `torch.utils.dlpack` namespace here.
It is present in the main namespace as well, but undocumented there
and it's not clear if we want to keep it there - see
#70543 (comment)
  • Loading branch information
rgommers committed Jan 3, 2022
commit ec8a29e35a3a59b06cf196da6209cdca55e9d441
6 changes: 3 additions & 3 deletions torch/utils/dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def from_dlpack(ext_tensor: Any) -> torch.Tensor:
>>> import torch.utils.dlpack
>>> t = torch.arange(4)

# Convert a tensor directly (PyTorch >= 1.10)
>>> t2 = torch.utils.dlpack.from_dlpack(t)
# Convert a tensor directly (supported in PyTorch >= 1.10)
>>> t2 = torch.from_dlpack(t)
>>> t2[:2] = -1 # show that memory is shared
>>> t2
tensor([-1, -1, 2, 3])
Expand All @@ -83,7 +83,7 @@ def from_dlpack(ext_tensor: Any) -> torch.Tensor:
>>> capsule = torch.utils.dlpack.to_dlpack(t)
>>> capsule
<capsule object "dltensor" at 0x7f6017d14300>
>>> t3 = torch.utils.dlpack.from_dlpack(capsule)
>>> t3 = torch.from_dlpack(capsule)
>>> t3
tensor([-1, -1, 2, 3])
>>> t3[0] = -9 # now we're sharing memory between 3 tensors
Expand Down
0