With ONNX export, does it mean it will avoid the problem when not using jit.script in torch.trace?

username: JonathanSum
cooked: <p>In the  torch.trace tutorial, it says if we don’t do jit.script  in some if-else logic statement in the model, the exported trace model won’t capture it. However, in ONNX, does it mean we don’t need to do jit.script in those logic statements in the model?</p>
<p>Thank you for answering.</p>

username: ebarsoum
cooked: <p>ONNX export leverage TorchIR to convert PyTorch model to ONNX graph. TorchIR is generated by trace or script, so you will still have the same limitation if you use trace to export to ONNX.</p>
<p>What the problem of using script to capture control flow and loop?</p>

username: JonathanSum
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/3/934441a0c10efc62da33ec53f6a748f0b1660655.png" data-download-href="https://discuss.pytorch.org/uploads/default/934441a0c10efc62da33ec53f6a748f0b1660655" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/9/3/934441a0c10efc62da33ec53f6a748f0b1660655.png" alt="image" data-base62-sha1="l0MqslXIJV399X128I4yjwst8HP" width="690" height="160" data-dominant-color="3A1614"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">829×193 7.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p><aside class="onebox githubissue" data-onebox-src="https://github.com/microsoft/onnxjs/issues/165">
  <header class="source">

      <a href="https://github.com/microsoft/onnxjs/issues/165" target="_blank" rel="noopener nofollow ugc">github.com/microsoft/onnxjs</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/microsoft/onnxjs/issues/165" target="_blank" rel="noopener nofollow ugc">Error loading onnxjs from webpack</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2019-06-16" data-time="05:52:18" data-timezone="UTC">05:52AM - 16 Jun 19 UTC</span>
      </div>


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

    <div class="labels">
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">I've been trying to add onnxjs support in [VoTT](https://github.com/microsoft/Vo<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">TT/issues/794), but I've been hitting some issues.  I have a model that I was able to successfully run in node.js, but when I try to run it on the frontend, I get 
```javascript
TypeError: cannot resolve operator 'Shape' with opsets: ai.onnx v9
```

I tried [converting the model](https://github.com/onnx/onnx/blob/master/docs/PythonAPIOverview.md#converting-version-of-an-onnx-model-within-default-domain-aionnx) to use a lower opset, but I faced similar errors with the converted models.

So I thought that I'd be clever and try a workaround and run the model on the backend using onnxjs-node, sending the results back to the frontend using IPC.

After adding a little code into src/electron/main.ts 
```javascript
import { Tensor, InferenceSession } from "onnxjs-node";
const inferenceSession = new InferenceSession();
```

and updating my webpack config, I'm seeing a couple of new errors.

```
 σ csaroff:~/fiddle/VoTT$ node_modules/.bin/webpack-cli --config config/webpack.dev.js
...
WARNING in ./node_modules/onnxjs-node/bin/napi-v3 sync ^\.\/.*\.node$
Module not found: Error: Can't resolve 'node-loader' in '/Users/csaroff/fiddle/VoTT'
 @ ./node_modules/onnxjs-node/bin/napi-v3 sync ^\.\/.*\.node$
 @ ./node_modules/onnxjs-node/lib/binding.js
 @ ./node_modules/onnxjs-node/lib/inference-session-override.js
 @ ./node_modules/onnxjs-node/lib/index.js
 @ ./src/electron/main.ts

ERROR in ./node_modules/onnxjs/lib/wasm-binding.js
Module not found: Error: Can't resolve 'worker-loader' in '/Users/csaroff/fiddle/VoTT/node_modules/onnxjs/lib'
 @ ./node_modules/onnxjs/lib/wasm-binding.js 101:29-96
 @ ./node_modules/onnxjs/lib/backends/backend-wasm.js
 @ ./node_modules/onnxjs/lib/api/onnx-impl.js
 @ ./node_modules/onnxjs/lib/api/index.js
 @ ./node_modules/onnxjs-node/lib/index.js
 @ ./src/electron/main.ts
```

So then I ran `npm install --save-dev node-loader worker-loader` and tried rerunning webpack.

```
σ csaroff:~/fiddle/VoTT$node_modules/.bin/webpack-cli --config config/webpack.dev.js
...
ERROR in ./node_modules/onnxjs/lib/wasm-binding.js
Module not found: Error: Can't resolve './worker/worker-main' in '/Users/csaroff/fiddle/VoTT/node_modules/onnxjs/lib'
 @ ./node_modules/onnxjs/lib/wasm-binding.js 101:29-96
 @ ./node_modules/onnxjs/lib/backends/backend-wasm.js
 @ ./node_modules/onnxjs/lib/api/onnx-impl.js
 @ ./node_modules/onnxjs/lib/api/index.js
 @ ./node_modules/onnxjs-node/lib/index.js
 @ ./src/electron/main.ts
```

And this is where I'm stuck. I see that you chose not to include lib/worker in your [tsconfig file](https://github.com/microsoft/onnxjs/blob/master/tsconfig.json#L3), but I couldn't figure out why.  So I tried rebuilding the project, removing the `  "exclude": ["lib/worker"],` line from the tsconfig.json, but that just gives me a whole mess of typescript errors.

```
σ csaroff:~/fiddle/onnxjs$npm run build

&gt; onnxjs@0.1.7 build /Users/csaroff/fiddle/onnxjs
&gt; tsc &amp;&amp; node tools/build --build-wasm --build-bundle

node_modules/typescript/lib/lib.dom.d.ts:25:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: EventListenerOrEventListenerObject, ImportExportKind, TableKind, BlobPart, HeadersInit, BodyInit, RequestInfo, DOMHighResTimeStamp, CanvasImageSource, OffscreenRenderingContext, MessageEventSource, ImageBitmapSource, TimerHandler, PerformanceEntryList, VibratePattern, AlgorithmIdentifier, HashAlgorithmIdentifier, BigInteger, NamedCurve, GLenum, GLboolean, GLbitfield, GLint, GLsizei, GLintptr, GLsizeiptr, GLuint, GLfloat, GLclampf, TexImageSource, Float32List, Int32List, BufferSource, DOMTimeStamp, FormDataEntryValue, IDBValidKey, Transferable, BinaryType, CanvasDirection, CanvasFillRule, CanvasLineCap, CanvasLineJoin, CanvasTextAlign, CanvasTextBaseline, ClientTypes, EndingType, IDBCursorDirection, IDBRequestReadyState, IDBTransactionMode, ImageSmoothingQuality, KeyFormat, KeyType, KeyUsage, NotificationDirection, NotificationPermission, OffscreenRenderingContextId, PermissionName, PermissionState, PushEncryptionKeyName, PushPermissionState, ReferrerPolicy, RequestCache, RequestCredentials, RequestDestination, RequestMode, RequestRedirect, ResponseType, ServiceWorkerState, ServiceWorkerUpdateViaCache, VisibilityState, WebGLPowerPreference, WorkerType, XMLHttpRequestResponseType

25 interface Account {
   ~~~~~~~~~

  node_modules/typescript/lib/lib.webworker.d.ts:25:1
    25 interface AddEventListenerOptions extends EventListenerOptions {
       ~~~~~~~~~
    Conflicts are in this file.
...
```

I'm pretty much out of ideas.  I checked in a minimally reproducible example on [this branch](https://github.com/csaroff/VoTT/tree/onnxjs-backend-example).  Here's a [diff of the changes](https://github.com/csaroff/VoTT/commit/a90769d2009c154ff47c412d63a305b7e5943c83).  Any help/insight here would be great!</span></p>
  </div>

  </article>

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

  <div style="clear: both"></div>
</aside>
<p>
I guess it is kind of like underdevelopment.</p>