# PrimTorch: could we get pure core-aten-ops or prims-ops after aot\_autograd

**URL:** <https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048>\
**Category:** compiler\
**Created:** [February 12, 2023, 10:36am UTC](https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048 "2023-02-12T10:36:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![YellowHCH](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/yellowhch/32/935_2.png) [@YellowHCH](https://dev-discuss.pytorch.org/u/YellowHCH)\
**Post date:** [February 12, 2023, 10:36am UTC](https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048/1 "2023-02-12T10:36:01Z")

</div>

According to pytorch2.0’s [Doc](https://pytorch.org/get-started/pytorch-2.0/#technology-overview), ATen ops and Prims ops seem to be independent. But Fx Graph after aot\_autograd seems like a mix of both ATen and Prims ops.  
So how could one get pure ATen ops(or Prims ops) after aot\_autograd? Or am I misunderstanding the design of PrimTorch?

---

<div class="post-metadata">

**Author:** ![YellowHCH](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/yellowhch/32/935_2.png) [@YellowHCH](https://dev-discuss.pytorch.org/u/YellowHCH)\
**Post date:** [February 13, 2023, 11:41am UTC](https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048/2 "2023-02-13T11:41:09Z")

</div>

> [@YellowHCH](#):
>
> But Fx Graph after aot\_autograd seems like a mix of both ATen and Prims ops.

Incorrect.  
Ref to:

> [@Tracing with Primitives: Update 2](https://dev-discuss.pytorch.org/t/tracing-with-primitives-update-2/645):
>
> Hey PyTorch developers and community members! The “tracing with primitives” program continues to grow, with over a dozen direct contributors who have added Python reference implementations for more than a quarter of PyTorch’s torch, torch.nn.functional, torch.linalg, torch.fft, and torch.special operations! (To learn more about why we’re writing Python reference implementations of PyTorch operators see [“Tracing with Primitives: Update 0”](https://dev-discuss.pytorch.org/t/tracing-with-primitives-update-0/577).) As the project expands it uncovers interesting challen…

---

<div class="post-metadata">

**Author:** ![Minerva\_Yu](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Minerva\_Yu](https://dev-discuss.pytorch.org/u/Minerva_Yu)\
**Post date:** [February 15, 2023, 6:53am UTC](https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048/3 "2023-02-15T06:53:14Z")

</div>

In my understanding, the Prims ops only work for those who have their “hardened decompositions” in module “\_refs”(currently at Feb. 2023). For example if you use `torch._refs.abs(x)` and get its Fx Graph, you may get pure Prim IR `abs_1 = torch.ops.prims.abs.default(add_2)`.

---

<div class="post-metadata">

**Author:** ![ezyang](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/ezyang/32/12_2.png) [@ezyang](https://dev-discuss.pytorch.org/u/ezyang)\
**Post date:** [February 17, 2023, 2:15am UTC](https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048/4 "2023-02-17T02:15:46Z")

</div>

The answer to this question is a little complicated because we have not spent enough effort on this part of the UX, but the short answer is that you have the ability to pick which decomps you use, so in principle you can get only aten or prims in your graph by choosing your decomps carefully. How to choose? Well, uh, we should have an api for this but we don’t. We could probably figure this out automatically by analyzing each decomp and seeing if it calls a prim or not. This would be a pretty useful PR if you want to submit it.

---

<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:20am UTC](https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048/5 "2023-03-10T08:20:04Z")

</div>

from torch.\_decomp import core\_aten\_decompositions

core\_aten\_decompositions() should give you a Aten-Only opset.

---

<div class="post-metadata">

**Author:** ![YellowHCH](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/yellowhch/32/935_2.png) [@YellowHCH](https://dev-discuss.pytorch.org/u/YellowHCH)\
**Post date:** [March 20, 2023, 2:59am UTC](https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048/6 "2023-03-20T02:59:50Z")

</div>

> [@ezyang](#):
>
> choosing your decomps carefully.

In fact, I tried core\_aten\_decompositions(), but got Ops outside [Core-ATen-IR](https://pytorch.org/docs/master/ir.html#core-aten-ir) 😁

---

<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 21, 2023, 5:07pm UTC](https://dev-discuss.pytorch.org/t/primtorch-could-we-get-pure-core-aten-ops-or-prims-ops-after-aot-autograd/1048/7 "2023-03-21T17:07:01Z")

</div>

Could you please report an issue in pytorch repo?  
Core Aten IR is still under development, we might be missing some operators in core aten opset.
