# Problems with torch.compile generated code in tutorial

**URL:** <https://dev-discuss.pytorch.org/t/problems-with-torch-compile-generated-code-in-tutorial/1765>\
**Category:** compiler\
**Created:** [January 2, 2024, 12:44pm UTC](https://dev-discuss.pytorch.org/t/problems-with-torch-compile-generated-code-in-tutorial/1765 "2024-01-02T12:44:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![azik1725](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/azik1725/32/1277_2.png) [@azik1725](https://dev-discuss.pytorch.org/u/azik1725)\
**Post date:** [January 2, 2024, 12:44pm UTC](https://dev-discuss.pytorch.org/t/problems-with-torch-compile-generated-code-in-tutorial/1765/1 "2024-01-02T12:44:49Z")

</div>

Hello!

I decided to start the new year by diving into the intricacies of PyTorch 2.0 🙂

I’m trying to reproduce the example from the tutorial [Accelerating Hugging Face and TIMM models](https://pytorch.org/blog/Accelerating-Hugging-Face-and-TIMM-models/) and code generation is different in my case from what is given in the tutorial. As I understand, the Triton code was supposed to use 1 load, in my case there are still 2 loads. I would appreciate your help.

Fyi, I tried to reproduce the code in docker with the image [ghcr.io/pytorch/pytorch-nightly:2.0.0.dev20230301-devel](http://ghcr.io/pytorch/pytorch-nightly:2.0.0.dev20230301-devel)

The generated code during reproducing can be viewed here - [pytorch\_experiments/torch\_compile\_first\_test/torch\_compile\_debug/run\_2024\_01\_02\_14\_44\_21\_028356-pid\_9378/aot\_torchinductor/model\_\_0\_inference\_0.0/output\_code.py at master · azsh1725/pytorch\_experiments · GitHub](https://github.com/azsh1725/pytorch_experiments/blob/master/torch_compile_first_test/torch_compile_debug/run_2024_01_02_14_44_21_028356-pid_9378/aot_torchinductor/model__0_inference_0.0/output_code.py#L36)

---

<div class="post-metadata">

**Author:** ![azik1725](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/azik1725/32/1277_2.png) [@azik1725](https://dev-discuss.pytorch.org/u/azik1725)\
**Post date:** [January 2, 2024, 2:01pm UTC](https://dev-discuss.pytorch.org/t/problems-with-torch-compile-generated-code-in-tutorial/1765/2 "2024-01-02T14:01:05Z")

</div>

Another strange thing in the tutorial, I’m trying to reproduce “a real model” example with the TORCH\_COMPILE\_DEBUG=1 flag and I don’t see any logs for converting this model and also the `aot_torchinductor` directory is not created, is this how it should be?

---

<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:** [January 2, 2024, 3:38pm UTC](https://dev-discuss.pytorch.org/t/problems-with-torch-compile-generated-code-in-tutorial/1765/3 "2024-01-02T15:38:30Z")

</div>

The point of fusion is that every tensor is loaded just once and fused intermediary tensors are not stored/loaded to/from global memory. That is exactly what happens in that example. You are going to need two loads as you have two tensors and you need to read the data of each of them!

That blogpost has an errata. It should read “we can turn 4 reads and 3 writes into 2 reads and 1 write”

In the future, please post these questions in [https://discuss.pytorch.org/](https://discuss.pytorch.org/).

---

<div class="post-metadata">

**Author:** ![azik1725](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/azik1725/32/1277_2.png) [@azik1725](https://dev-discuss.pytorch.org/u/azik1725)\
**Post date:** [January 2, 2024, 8:05pm UTC](https://dev-discuss.pytorch.org/t/problems-with-torch-compile-generated-code-in-tutorial/1765/4 "2024-01-02T20:05:30Z")

</div>

Thank you very much for the clarification and answer!
