# Inductor file structure explanation

**URL:** <https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860>\
**Category:** Uncategorized\
**Created:** [February 5, 2024, 11:32am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860 "2024-02-05T11:32:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anubane](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/anubane/32/1651_2.png) [@anubane](https://dev-discuss.pytorch.org/u/anubane)\
**Post date:** [February 5, 2024, 11:32am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/1 "2024-02-05T11:32:34Z")

</div>

Could someone please explain the file structure and/or the classes involved in the Inductor module at [the inductor codebase](https://github.com/pytorch/pytorch/tree/main/torch/_inductor)?

I have gathered the general idea of **what** inductor does, now I need to understand **how** it does that!

---

<div class="post-metadata">

**Author:** ![anubane](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/anubane/32/1651_2.png) [@anubane](https://dev-discuss.pytorch.org/u/anubane)\
**Post date:** [February 6, 2024, 6:57am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/2 "2024-02-06T06:57:27Z")

</div>

Found a relevant post: [What should we do about developer documentation?](https://dev-discuss.pytorch.org/t/what-should-we-do-about-developer-documentation/491)

Also, my question is on the similar lines as [How to read the autograd codebase](https://dev-discuss.pytorch.org/t/how-to-read-the-autograd-codebase/383), albeit I was hoping for a source code deep dive!

---

<div class="post-metadata">

**Author:** ![anubane](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/anubane/32/1651_2.png) [@anubane](https://dev-discuss.pytorch.org/u/anubane)\
**Post date:** [February 8, 2024, 10:35am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/3 "2024-02-08T10:35:35Z")

</div>

So here is my preliminary attempt to use a [codebase mapper](https://www.codesee.io) to understand Inductor:

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

In that, I can focus on how the codebase is connected for (_perhaps_) C++ codegen like this:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/pytorch1/original/2X/3/31b4fa9314690aa47d52d6338117d588d7e859d6.png)

So, this is in no way conclusive, but, I am still exploring. If only I could request @jansel to help with the source code understanding!

---

<div class="post-metadata">

**Author:** ![Lezcano](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/lezcano/32/300_2.png) [@Lezcano](https://dev-discuss.pytorch.org/u/Lezcano)\
**Post date:** [February 8, 2024, 4:42pm UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/4 "2024-02-08T16:42:24Z")

</div>

I think the best way to understand this codebase (or any, for the matter) is to drop a few breakpoints, run a program, and look at the backtrace when they are hit. Rinse and repeat.

---

<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:** [February 9, 2024, 5:34am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/5 "2024-02-09T05:34:25Z")

</div>

The [PyTorch 2 paper](https://pytorch.org/blog/pytorch-2-paper-tutorial/) has some more details about how inductor works. Contributions are also very welcome to help improve documentation.

---

<div class="post-metadata">

**Author:** ![anubane](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/anubane/32/1651_2.png) [@anubane](https://dev-discuss.pytorch.org/u/anubane)\
**Post date:** [February 9, 2024, 6:24am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/6 "2024-02-09T06:24:51Z")

</div>

@jansel thank you for sharing the paper. I will try to continue preparing a record of my understanding and share it here.

@Lezcano I am currently following the approach (debug mode step through) that you have suggested, it is just that it is a bit tedious while not entirely revealing the implementation decisions.

---

<div class="post-metadata">

**Author:** ![Lezcano](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/lezcano/32/300_2.png) [@Lezcano](https://dev-discuss.pytorch.org/u/Lezcano)\
**Post date:** [February 9, 2024, 10:22am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/7 "2024-02-09T10:22:56Z")

</div>

It is true that the dev docs are very much lacking. As @jansel mentioned, we would very much accept some contributions, for example in the form of `README.md`s in the relevant folders.

When it comes to design decisions, it’s always useful to dig up the history of the relevant lines via git blame and have a look at the PRs that led to those lines.

---

<div class="post-metadata">

**Author:** ![anubane](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/anubane/32/1651_2.png) [@anubane](https://dev-discuss.pytorch.org/u/anubane)\
**Post date:** [February 21, 2024, 8:43am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/8 "2024-02-21T08:43:20Z")

</div>

> [@Lezcano](#):
>
> we would very much accept some contributions, for example in the form of `README.md`s in the relevant folders.

@Lezcano where as I am working on developing an understanding of the source code, I think, there is a contradiction - developer docs are to be created by the **developer** , for other (_potential newcomer_) developers!

---

<div class="post-metadata">

**Author:** ![anubane](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/anubane/32/1651_2.png) [@anubane](https://dev-discuss.pytorch.org/u/anubane)\
**Post date:** [February 23, 2024, 9:49am UTC](https://dev-discuss.pytorch.org/t/inductor-file-structure-explanation/1860/9 "2024-02-23T09:49:09Z")

</div>

Note to self:

> [“Code is more often read than written.”  
> — Guido van Rossum](https://realpython.com/documenting-python-code/)
