# Registering new compiler backend in Pytorch2.0

**URL:** https://dev-discuss.pytorch.org/t/registering-new-compiler-backend-in-pytorch2-0/1092
**Category:** compiler
**Created:** [March 3, 2023, 10:29am UTC](https://dev-discuss.pytorch.org/t/registering-new-compiler-backend-in-pytorch2-0/1092 "2023-03-03T10:29:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![AR51](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@AR51](https://dev-discuss.pytorch.org/u/AR51)
#### Post date: [March 3, 2023, 10:29am UTC](https://dev-discuss.pytorch.org/t/registering-new-compiler-backend-in-pytorch2-0/1092/1 "2023-03-03T10:29:34Z")

</div>

Hi,  
I want to know how to register the new backend in pytorch 2.0 at the dynamo stage to get the Aten/prim IR and take control of the graph.  
Is there any sample document or same code available in the repository.

---

<div class="post-metadata">

### Author: ![AR51](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@AR51](https://dev-discuss.pytorch.org/u/AR51)
#### Post date: [March 7, 2023, 1:10pm UTC](https://dev-discuss.pytorch.org/t/registering-new-compiler-backend-in-pytorch2-0/1092/3 "2023-03-07T13:10:08Z")

</div>

Can anyone help me on this.

---

<div class="post-metadata">

### Author: ![jansel](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/jansel/32/74_2.png) [@jansel](https://dev-discuss.pytorch.org/u/jansel)
#### Post date: [March 8, 2023, 11:14pm UTC](https://dev-discuss.pytorch.org/t/registering-new-compiler-backend-in-pytorch2-0/1092/4 "2023-03-08T23:14:08Z")

</div>

You can call this function to register a backend:

> <https://github.com/pytorch/pytorch/blob/32ffd70644d8593e0e126d4df62df27a61e23619/torch/_dynamo/backends/registry.py#L19>

This allows you to use a string alias for the `backend=...` arg to `torch.compile(.., backend="some_name")`. You can also just pass your backend directly to `torch.compile(..., backend=my_backend)`, no need to register.

To get the aten/prim graph use:

> <https://github.com/pytorch/pytorch/blob/32ffd70644d8593e0e126d4df62df27a61e23619/torch/_dynamo/backends/common.py#L14>

---

<div class="post-metadata">

### Author: ![AR51](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@AR51](https://dev-discuss.pytorch.org/u/AR51)
#### Post date: [March 9, 2023, 1:17pm UTC](https://dev-discuss.pytorch.org/t/registering-new-compiler-backend-in-pytorch2-0/1092/5 "2023-03-09T13:17:23Z")

</div>

Thanks for the reply.  
How to dump the primIR graph?

---

<div class="post-metadata">

### Author: ![SherlockNoMad](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/sherlocknomad/32/346_2.png) [@SherlockNoMad](https://dev-discuss.pytorch.org/u/SherlockNoMad)
#### Post date: [March 10, 2023, 8:11am UTC](https://dev-discuss.pytorch.org/t/registering-new-compiler-backend-in-pytorch2-0/1092/6 "2023-03-10T08:11:36Z")

</div>

You might also find this notebook helpful.

> **[Google Colaboratory](https://colab.research.google.com/drive/1Zh-Uo3TcTH8yYJF-LLo5rjlHVMtqvMdf#scrollTo=KA_FS0D831T5)**

---

<div class="post-metadata">

### Author: ![AR51](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@AR51](https://dev-discuss.pytorch.org/u/AR51)
#### Post date: [March 20, 2023, 10:07am UTC](https://dev-discuss.pytorch.org/t/registering-new-compiler-backend-in-pytorch2-0/1092/7 "2023-03-20T10:07:09Z")

</div>

I got. I was able to get to it. Thanks for the help.  
Another question is how we are doing mid-layer integration at the Aten FX graph layer.  
I’ve my own backend implemented in the cpp with my own data structures. I want to convert the aten FX graph into my own data structure graph which my backend can emit the binary out and run on the respective hardware. Can you give some pointers on that?? How are we providing control from python to cpp and its integration?

I’ve posted the question in: [How do we do mid layer integration after Aten fx graph](https://dev-discuss.pytorch.org/t/how-do-we-do-mid-layer-integration-after-aten-fx-graph/1140)
