# Any simple example about the new way to register custom device through PrivateUse1

**URL:** <https://dev-discuss.pytorch.org/t/any-simple-example-about-the-new-way-to-register-custom-device-through-privateuse1/1561>\
**Category:** frontend API\
**Created:** [October 11, 2023, 3:26am UTC](https://dev-discuss.pytorch.org/t/any-simple-example-about-the-new-way-to-register-custom-device-through-privateuse1/1561 "2023-10-11T03:26:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanhaowen](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/hanhaowen/32/1505_2.png) [@hanhaowen](https://dev-discuss.pytorch.org/u/hanhaowen)\
**Post date:** [October 11, 2023, 3:26am UTC](https://dev-discuss.pytorch.org/t/any-simple-example-about-the-new-way-to-register-custom-device-through-privateuse1/1561/1 "2023-10-11T03:26:00Z")

</div>

I know in pytorch 2.1, it is more convient for user to register their own device in pytorch,  
[Facilitating New Backend Integration by PrivateUse1 — PyTorch Tutorials 2.1.0+cu121 documentation](https://pytorch.org/tutorials/advanced/privateuseone.html),  
it includes ddp amp sparce or anything else, but I have not seen any example code for how to utilize this new feature,  
[GitHub - Ascend/pytorch: Ascend PyTorch adapter (torch\_npu). Mirror of https://gitee.com/ascend/pytorch](https://github.com/Ascend/pytorch) is a good example but it is too complicated, so does the official Pytorch plan to provide a complete routine to explain how to use this new feature?

---

<div class="post-metadata">

**Author:** ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)\
**Post date:** [October 12, 2023, 4:44pm UTC](https://dev-discuss.pytorch.org/t/any-simple-example-about-the-new-way-to-register-custom-device-through-privateuse1/1561/2 "2023-10-12T16:44:25Z")

</div>

Hey!

I’m not sure what you mean here? The tutorial covers how to register your implementation onto the PrivateUse1 device and rename it.  
Then you can use it as you use any other device. Nothing special is needed.

---

<div class="post-metadata">

**Author:** ![hanhaowen](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/hanhaowen/32/1505_2.png) [@hanhaowen](https://dev-discuss.pytorch.org/u/hanhaowen)\
**Post date:** [October 20, 2023, 5:37am UTC](https://dev-discuss.pytorch.org/t/any-simple-example-about-the-new-way-to-register-custom-device-through-privateuse1/1561/4 "2023-10-20T05:37:52Z")

</div>

> [@hanhaowen](#):
>
> Hello, I mean any complete example instead of scattered code

Hello, I mean any complete example instead of scattered code

---

<div class="post-metadata">

**Author:** ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)\
**Post date:** [October 20, 2023, 6:49pm UTC](https://dev-discuss.pytorch.org/t/any-simple-example-about-the-new-way-to-register-custom-device-through-privateuse1/1561/5 "2023-10-20T18:49:30Z")

</div>

Hey!

In that case no, I don’t think there is any plan beyond the tutorial, doc, tests and end to end example in a separate repo I’m afraid.

---

<div class="post-metadata">

**Author:** ![hanhaowen](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/hanhaowen/32/1505_2.png) [@hanhaowen](https://dev-discuss.pytorch.org/u/hanhaowen)\
**Post date:** [October 23, 2023, 5:15am UTC](https://dev-discuss.pytorch.org/t/any-simple-example-about-the-new-way-to-register-custom-device-through-privateuse1/1561/6 "2023-10-23T05:15:51Z")

</div>

> [@albanD](#):
>
> In that case no, I don’t think there is any plan beyond the tutorial, doc, tests and end to end example in a separate repo I’m afraid.

find, thanks 😀

---

<div class="post-metadata">

**Author:** ![Hacker1337](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/hacker1337/32/2245_2.png) [@Hacker1337](https://dev-discuss.pytorch.org/u/Hacker1337)\
**Post date:** [August 23, 2024, 3:42pm UTC](https://dev-discuss.pytorch.org/t/any-simple-example-about-the-new-way-to-register-custom-device-through-privateuse1/1561/7 "2024-08-23T15:42:56Z")

</div>

For completeness I would add to the discussion the particular link to the relevant file with tests, which was very useful for me: [pytorch/test/cpp\_extensions/open\_registration\_extension.cpp at 7fd3b6988681557a4dfc35dc99807cdd78e805c9 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/blob/7fd3b6988681557a4dfc35dc99807cdd78e805c9/test/cpp_extensions/open_registration_extension.cpp)  
It gives minimal complete standalone example of new device secretly storing data on CPU RAM, and showcasing most of the things developer of new backend might need.

It is compiled dynamically in this file [pytorch/test/test\_cpp\_extensions\_open\_device\_registration.py at 7fd3b6988681557a4dfc35dc99807cdd78e805c9 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/blob/7fd3b6988681557a4dfc35dc99807cdd78e805c9/test/test_cpp_extensions_open_device_registration.py)  
however can be also compiled as a static python library in the way explained in this tutorial [Extending dispatcher for a new backend in C++ — PyTorch Tutorials 2.4.0+cu121 documentation](https://pytorch.org/tutorials/advanced/extend_dispatcher.html)
