# Does warming up the torch.compile necessarily trigger all cases?

**URL:** <https://discuss.pytorch.org/t/does-warming-up-the-torch-compile-necessarily-trigger-all-cases/215146>\
**Category:** torch.\_dynamo\
**Created:** [January 9, 2025, 3:01am UTC](https://discuss.pytorch.org/t/does-warming-up-the-torch-compile-necessarily-trigger-all-cases/215146 "2025-01-09T03:01:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GodHforever](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/godhforever/32/72261_2.png) [@GodHforever](https://discuss.pytorch.org/u/GodHforever)\
**Post date:** [January 9, 2025, 3:01am UTC](https://discuss.pytorch.org/t/does-warming-up-the-torch-compile-necessarily-trigger-all-cases/215146/1 "2025-01-09T03:01:32Z")

</div>

my test code is as follows:

```auto
@torch.compile(backend=my_compiler)
def my_function(inputs):
    x = inputs["x"]
    y = inputs["y"]
    x = torch.add(x, 0.5)
    if x.mean() > 0.5:
        x = x / 1.1
    return x * y

```

I debug into the compile process and find that tensor `x` always save the true value instead of fake tensor, thus different inputs can trigger all code branches.  
In theory, `x` should be a fake tensor, so is it possible that no mattter how many times you warm up models, it will never trigger some corner branches?

---

<div class="post-metadata">

**Author:** ![bdhirsh](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/bdhirsh/32/74038_2.png) [@bdhirsh](https://discuss.pytorch.org/u/bdhirsh)\
**Post date:** [January 10, 2025, 3:09am UTC](https://discuss.pytorch.org/t/does-warming-up-the-torch-compile-necessarily-trigger-all-cases/215146/2 "2025-01-10T03:09:05Z")

</div>

The direct answer to your question is no: torch.compile is a just-in-time, tracing-based compiler, so in order to fully “warm up” compile (and avoid new compilations / reach a steady state), you need to sure you warm it up with a full set of model inputs that go down all potential branches of your model.

On your specific example: when you branch on “x.mean() \> 0.5”, you are attempting to branch on a data-dependent value. Compile will capture a graph up until the branch, compile and execute it, and then use the computed value to “continue” and capture a new graph on the side of the control flow that the value sends it.

If you want to see what the actual graphs look like, you can run with “TORCH\_LOGS=graph\_code” to see the two distinct graphs that compile produces

---

<div class="post-metadata">

**Author:** ![GodHforever](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/godhforever/32/72261_2.png) [@GodHforever](https://discuss.pytorch.org/u/GodHforever)\
**Post date:** [January 18, 2025, 1:58am UTC](https://discuss.pytorch.org/t/does-warming-up-the-torch-compile-necessarily-trigger-all-cases/215146/3 "2025-01-18T01:58:06Z")

</div>

Thanks for your reply. dynamo says it will use faketensors which only include meta data, by in this case real data is captured.

Does this mean that if there is a computational process that is data-dependent, then the values of the real inputs are used, otherwise the faketensor is used?
