Any chance to torch.export TorchScript?

siahuat0727: <p>I am exploring pt2e quantization and want to quantize a torchscript model using pt2e, but I failed to convert a torchscript to torch.export.</p>
<p>I wonder if there any chance to get a torch.export model given a torchscript? Thanks.</p>
<pre data-code-wrap="python"><code class="lang-python">import torch

m = torch.nn.Conv2d(3, 3, 3)
m = torch.jit.script(m)
inputs = (torch.rand(1, 3, 32, 32), )
m(*inputs)

import torch.export._trace
torch.export._trace._export(m, inputs, pre_dispatch=True)
# torch.export.export(m, inputs)   # This also failed if the input is scriptmodule

</code></pre>
<p>Error message:</p>
<pre><code class="lang-auto">    gm_torch_level, _ = torch._dynamo.export(
  File ".../python3.8/site-packages/torch/_dynamo/eval_frame.py", line 1356, in inner
    assert (
AssertionError: Failed to produce a graph during tracing as no tensor operations were found.
</code></pre>

siahuat0727: <p>Looks like there is a prototype for this in PyTorch 2.4</p><aside class="onebox githubpullrequest" data-onebox-src="https://github.com/pytorch/pytorch/pull/126920">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/pull/126920" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">



    <div class="github-icon-container" title="Pull Request">
      <svg width="60" height="60" class="github-icon" viewBox="0 0 12 16" aria-hidden="true"><path fill-rule="evenodd" d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
    </div>

  <div class="github-info-container">



      <h4>
        <a href="https://github.com/pytorch/pytorch/pull/126920" target="_blank" rel="noopener nofollow ugc">TorchScript 2 ExportedProgram Converter</a>
      </h4>

    <div class="branches">
      <code>pytorch:main</code> ← <code>SherlockNoMad:export-D57694784</code>
    </div>

      <div class="github-info">
        <div class="date">
          opened <span class="discourse-local-date" data-format="ll" data-date="2024-05-22" data-time="22:02:23" data-timezone="UTC">10:02PM - 22 May 24 UTC</span>
        </div>

        <div class="user">
          <a href="https://github.com/SherlockNoMad" target="_blank" rel="noopener nofollow ugc">
            <img alt="SherlockNoMad" src="https://avatars.githubusercontent.com/u/9906745?v=4" class="onebox-avatar-inline" width="20" height="20">
            SherlockNoMad
          </a>
        </div>

        <div class="lines" title="1 commits changed 2 files with 395 additions and 0 deletions">
          <a href="https://github.com/pytorch/pytorch/pull/126920/files" target="_blank" rel="noopener nofollow ugc">
            <span class="added">+395</span>
            <span class="removed">-0</span>
          </a>
        </div>
      </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">Summary:
Initial commit for TorchScript 2 ExportedProgram Converter. 


TODO:
- <span class="show-more-container"><a href="https://github.com/pytorch/pytorch/pull/126920" target="_blank" rel="noopener nofollow ugc" class="show-more">…</a></span><span class="excerpt hidden">Improve TorchScript IR coverage
- parameter and buffers should be owned by output ExportedProgram
- Experiment on conditional op conversion

Test Plan: buck2 run mode/dev-nosan fbcode//caffe2/test:test_export -- -r TestConverter

Differential Revision: D57694784</span></p>
  </div>

  </article>

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

  <div style="clear: both"></div>
</aside>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/pytorch/pytorch/releases/tag/v2.4.0">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/pytorch/pytorch/releases/tag/v2.4.0" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/344;"><img src="https://opengraph.githubassets.com/103fefc2a40172db2be1ba3f02aaed7b2fd7793f28488d083266673b841e3396/pytorch/pytorch/releases/tag/v2.4.0" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/pytorch/pytorch/releases/tag/v2.4.0" target="_blank" rel="noopener nofollow ugc">Release PyTorch 2.4: Python 3.12, AOTInductor freezing, libuv backend for...</a></h3>

  <p>PyTorch 2.4 Release Notes

Highlights
Tracked Regressions
Backward incompatible changes
Deprecations
New features
Improvements
Bug Fixes
Performance
Documentation
Developers
Security

Highlights
We...</p>


  </article>

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

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