Skip to content
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

What's the right way to use torch dispatch? #35

Open
lichao0613 opened this issue May 16, 2022 · 3 comments · Fixed by #36
Open

What's the right way to use torch dispatch? #35

lichao0613 opened this issue May 16, 2022 · 3 comments · Fixed by #36

Comments

@lichao0613
Copy link

If I want to enable our new device like "NPU" based on PyTorch, do I still need register a dispatch key(just like pytorch/pytorch#75863 does) when using torch_dispatch?

@albanD
Copy link
Owner

albanD commented Jun 2, 2022

Hi,

Sorry for the long time to answer.
I think the question is best answered with an example so you can take a look at #36
Let me know what you think, how it works for you and if there are any shortcomings that you need help fixing!

@albanD albanD closed this as completed in #36 Jun 3, 2022
@lichao0613
Copy link
Author

lichao0613 commented Jun 17, 2022

Hi,

Sorry for the long time to answer. I think the question is best answered with an example so you can take a look at #36 Let me know what you think, how it works for you and if there are any shortcomings that you need help fixing!

Hi albanD.
Thanks a lot for the reply and demos.
en.... there are some questions when using the demos in #36.

How to rename Tensor.device.type as "my_device"?We can create a "my_device" tensor by wrapping a "meta" tensor, but we cannot modify its device_type. As we all know that "tensor.device.type == 'my_device' " is a common judgement statement for pytorch users.
the MyDeviceMode seems not work to me, such as t1 = torch.empty(4, device="my_device"). Is there anything I have missed?

@albanD
Copy link
Owner

albanD commented Jun 17, 2022

How to rename Tensor.device.type as "my_device"?

When you call tensor.device that will call __torch_function__ for Tensor.device.__get__. You can then return anything you want from there.

the MyDeviceMode seems not work to me, such as t1 = torch.empty(4, device="my_device"). Is there anything I have missed?

Did you properly called enable_my_device() ?
If so, can you share a code sample to repro?

Note: leaving this issue open to track the conversation more easily on my end.

@albanD albanD reopened this Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants