# Partial graph allocation for accelerators

**URL:** <https://dev-discuss.pytorch.org/t/partial-graph-allocation-for-accelerators/1120>\
**Category:** compiler\
**Created:** [March 9, 2023, 12:50pm UTC](https://dev-discuss.pytorch.org/t/partial-graph-allocation-for-accelerators/1120 "2023-03-09T12:50:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhkim](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@jhkim](https://dev-discuss.pytorch.org/u/jhkim)\
**Post date:** [March 9, 2023, 12:50pm UTC](https://dev-discuss.pytorch.org/t/partial-graph-allocation-for-accelerators/1120/1 "2023-03-09T12:50:36Z")

</div>

Hello, I have a question about integrating custom backend compilers into PyTorch.

Suppose I have an accelerator, and my compiler for this accelerator only supports a limited number of operations, such as convolutions and ReLUs.

Is it possible to allocate partial FX graphs that only include convolutions and ReLUs to my backend compiler, while allocating the remaining partial FX graphs to other compilers like TorchInductor for CPU execution?

---

<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:13am UTC](https://dev-discuss.pytorch.org/t/partial-graph-allocation-for-accelerators/1120/2 "2023-03-10T08:13:42Z")

</div>

Here’s an example of partial graph delegation.

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

---

<div class="post-metadata">

**Author:** ![jhkim](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@jhkim](https://dev-discuss.pytorch.org/u/jhkim)\
**Post date:** [March 12, 2023, 4:02am UTC](https://dev-discuss.pytorch.org/t/partial-graph-allocation-for-accelerators/1120/3 "2023-03-12T04:02:21Z")

</div>

This is what I wanted to know. Thank you so much!

---

<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 13, 2023, 4:43pm UTC](https://dev-discuss.pytorch.org/t/partial-graph-allocation-for-accelerators/1120/4 "2023-03-13T16:43:17Z")

</div>

You can also find the example usage in

- nvFuser
  - Backend bridge: [pytorch/torch/fx/passes/backends/nvfuser.py](https://github.com/YLGH/pytorch/blob/c9a0204ef4fb8edd29aeaebc5c74867fa1093a48/torch/fx/passes/backends/nvfuser.py)

- onnxruntime
  - Backend bridge: [onnxruntime/orttraining/orttraining/python/training/torchdynamo/ort\_backend.py](https://github.com/ramkrishna2910/onnxruntime/blob/master/orttraining/orttraining/python/training/torchdynamo/ort_backend.py)
