-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Torch] Implements __torch_func__ protocol (#400)
This PR implements the `__torch_func__` protocol as suggested at https://pytorch.org/docs/stable/notes/extending.html#extending-torch-with-a-tensor-like-type
- Loading branch information
1 parent
4d71a8d
commit 57154a3
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
import torch | ||
import hidet | ||
|
||
|
||
def test_as_torch_tensor(): | ||
""" | ||
test __torch_func__ protocol | ||
""" | ||
a = hidet.randn([32, 32], dtype='float16', device='cuda') | ||
b = torch.abs(a) | ||
c = hidet.ops.abs(a) | ||
torch.testing.assert_close(b, c.torch()) | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main([__file__]) |