# How does torch.compile work with autograd?

**URL:** https://dev-discuss.pytorch.org/t/how-does-torch-compile-work-with-autograd/1621
**Category:** Uncategorized
**Created:** [October 30, 2023, 1:43pm UTC](https://dev-discuss.pytorch.org/t/how-does-torch-compile-work-with-autograd/1621 "2023-10-30T13:43:13Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![youkaichao](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/youkaichao/32/1278_2.png) [@youkaichao](https://dev-discuss.pytorch.org/u/youkaichao)
#### Post date: [October 31, 2023, 2:57am UTC](https://dev-discuss.pytorch.org/t/how-does-torch-compile-work-with-autograd/1621/11 "2023-10-31T02:57:09Z")

</div>

Thanks for the pointer, it really helps!

Plus: the example of `sin` in the slides seems to have no memory benefit I think. Another example you provide in [Min-cut optimal(\*) recomputation (i.e. activation checkpointing) with AOTAutograd](https://dev-discuss.pytorch.org/t/min-cut-optimal-recomputation-i-e-activation-checkpointing-with-aotautograd/467) did have memory benefit.

Plus: I’m confused by the word “partition”. By partition, we usually mean to partition the graph into disjoint subsets. In the following example, if we save `add_2` for backward, both fwd and bwd have to compute the edge `cos` on `add_2`. When we partition the joint graph to get the bwd graph based on activations `{x1, ..., xn}`, the fwd graph should be the minimum graph that can compute `{x1, ..., xn, output}`. Those two graphs might have some overlap.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/pytorch1/original/2X/7/70a2b49ca927e6a93e8059e044a4cc8a7c63e6b6.jpeg)

Final Plus: I used to think aot autograd can discover something like optimized sigmoid (e.g. users write eager code `z = 1 / (1 + torch.exp(-x))`, and we can figure out the smart backward as `z * (1 - z)`). Now that I understand what aot autograd can do.

---

_[View the full topic](https://dev-discuss.pytorch.org/t/how-does-torch-compile-work-with-autograd/1621)._
