Exhaustive list of environment variables for PT2.0 Compiler Debug Traces

username: Abhishek_Ghosh
cooked: <p>I often struggle to find out which environment variable would enable certain debug traces. Often, I find myself looking into the source code to figure out the environment variable check hidden behind a conditional to enable the debug tracing.</p>
<p>I have seen certain useful environment variables mentioned in PyTorch blogs/docs (the <a href="https://pytorch.org/docs/stable/torch.compiler_troubleshooting.html" rel="noopener nofollow ugc">troubleshooting</a>  guide, for example) or tutorials/talks. But they are not exhaustive.</p>
<p>For instance, I want to print the “cache hit” message from <code>_custom_eval_frame</code>:</p><aside class="onebox githubblob" data-onebox-src="https://github.com/pytorch/pytorch/blob/c5c9dbece10e92e325e4efd0aea91d681737142d/torch/csrc/dynamo/eval_frame.c#L620">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/blob/c5c9dbece10e92e325e4efd0aea91d681737142d/torch/csrc/dynamo/eval_frame.c#L620" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/c5c9dbece10e92e325e4efd0aea91d681737142d/torch/csrc/dynamo/eval_frame.c#L620" target="_blank" rel="noopener nofollow ugc">pytorch/pytorch/blob/c5c9dbece10e92e325e4efd0aea91d681737142d/torch/csrc/dynamo/eval_frame.c#L620</a></h4>



    <pre class="onebox"><code class="lang-c">
      <ol class="start lines" start="610" style="counter-reset: li-counter 609 ;">
          <li>  if (maybe_cached_code == NULL) {</li>
          <li>    // guard eval failed, keep propagating</li>
          <li>    *should_clear_frame = 1;</li>
          <li>    return NULL;</li>
          <li>  } else if (maybe_cached_code == Py_None) {</li>
          <li>    DEBUG_TRACE("cache miss %s", get_frame_name(frame));</li>
          <li>    return eval_frame_default(tstate, frame, throw_flag);</li>
          <li>  }</li>
          <li>  PyCodeObject* cached_code = (PyCodeObject*)maybe_cached_code;</li>
          <li>  // used cached version</li>
          <li class="selected">  DEBUG_TRACE("cache hit %s", get_frame_name(frame));</li>
          <li>  *should_clear_frame = 1;</li>
          <li>  return eval_custom_code(tstate, frame, cached_code, throw_flag, free_vars_copied);</li>
          <li>}</li>
          <li>DEBUG_CHECK(PyDict_CheckExact(frame-&gt;f_locals));</li>
          <li>DEBUG_CHECK(PyDict_CheckExact(frame-&gt;f_globals));</li>
          <li>DEBUG_CHECK(PyDict_CheckExact(frame-&gt;f_builtins));</li>
          <li></li>
          <li>// We don't run the current custom_eval_frame behavior for guards.</li>
          <li>// So we temporarily set the callback to Py_None to drive the correct behavior</li>
          <li>// in the shim.</li>
      </ol>
    </code></pre>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Do you have any suggestions for this?</p>
<hr>
<p>The above specific case is a compilation flag, which is enabled by uncommenting <code>#define TORCHDYNAMO_DEBUG 1</code> in <code>torch/csrc/dynamo/debug_macros.h</code></p>