Git Product home page Git Product logo

Comments (8)

fs-eire avatar fs-eire commented on July 19, 2024

@KTibow thank you for reporting this issue. I am not very familiar with Vite. I want to understand more details about the problem.

The new version of ORT Web uses dynamic import to load file ort-wasm-simd-threaded.jsep.mjs. Do you mean that Vite does not support dynamic import, or it is not recommended to use dynamic import in Vite?

from onnxruntime.

KTibow avatar KTibow commented on July 19, 2024

The import function is supported in Vite to some degree.
If a static argument is passed, or a directory with a templated file, Vite can bundle the code. However, if the argument is dynamic, Vite won't know which code to bundle and won't update the function to work.
There are other ways that can help with dynamic file importing, but regardless, the directory of the file has to be known at build time in order for bundling to work.

* technicality: Vite isn't a bundler in itself, it uses Rollup, esbuild, and soon a rewrite of Rollup to bundle the code
* just writing this down has made me realize that this might not be a simple solution as I wrote in the original post, it'll probably require some consideration

from onnxruntime.

fs-eire avatar fs-eire commented on July 19, 2024

The fundamental reason of why I uses dynamic import is becaues Emscripten does not support to generate both UMD/ESM glue for a Wasm target - you have to choose either. This means I have the following options:

  1. build both ort-wasm-simd-threaded-umd.wasm+ort-wasm-simd-threaded-umd.js and ort-wasm-simd-threaded-esm.wasm+ort-wasm-simd-threaded-esm.mjs
  2. only build one target, and use it in both ESM/UMD.

The option (1) not only doubled the package size for technically unnecessary reason, but also makes the deployment more complicated. A mismatch will not work and adds quite steps into troubleshooting.

I am currently using (2) to build ESM and import it in both UMD/ESM bundle.

from onnxruntime.

fs-eire avatar fs-eire commented on July 19, 2024

If a static argument is passed, or a directory with a templated file, Vite can bundle the code. However, if the argument is dynamic, Vite won't know which code to bundle and won't update the function to work.

Based on the reason above, I expect the bundler to leave the dynamic import as-is, to keep the dynamic import behavior. rollup ( the underlying bundler) seems to support it correctly, but it seems Vite does not expect any .js/.mjs files to serve directly as assets.

from onnxruntime.

KTibow avatar KTibow commented on July 19, 2024

rollup seems to support it correctly

I'm a bit confused by how this would be possible. I have a suspicion, but I'd like to see the file structure of the bundled files so I can confirm/deny it.

from onnxruntime.

fs-eire avatar fs-eire commented on July 19, 2024

https://github.com/microsoft/onnxruntime/tree/main/js/web/test/e2e

The E2E folder contains bundler test for webpack, rollup and percel

from onnxruntime.

fs-eire avatar fs-eire commented on July 19, 2024

@KTibow you can alternatively import ORT Web in ESM. In latest main branch, dynamic import is disabled by default when you consume ORT Web as ESModule.

from onnxruntime.

KTibow avatar KTibow commented on July 19, 2024

Works in my tests 👍

from onnxruntime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.