[js/web] update default export to include webgpu (#22754)

### Description

This PR changes the following exports:
- `onnxruntime-web` now is same to `onnxruntime-web/webgpu`.
- `onnxruntime-web/webgpu` is deprecating.

### Migration instructions:
- use `onnxruntime-web` instead of `onnxruntime-web/webgpu`.
- use `onnxruntime-web/wasm` if want to use onnxruntime-web without
webgpu/webnn.

### Export table

| file name | export entry | includes WASM | includes JSEP (WebGPU &
WebNN) | includes WebGL
| ------------- | ------------- | ----- | ----- | -----
| ort.all.min.js<br/>ort.all.js<br/>ort.all.min.mjs<br/>ort.all.mjs |
`onnxruntime-web/all` | ✔️| ✔️| ✔️
| ort.min.js<br/>ort.js<br/>ort.min.mjs<br/>ort.mjs | `onnxruntime-web`
| ✔️|  --> ✔️| ✔️ -->
|
ort.webgpu.min.js<br/>ort.webgpu.js<br/>ort.webgpu.min.mjs<br/>ort.webgpu.mjs
| `onnxruntime-web/webgpu` | ✔️ | ✔️ |
| ort.wasm.min.js<br/>ort.wasm.js<br/>ort.wasm.min.mjs<br/>ort.wasm.mjs
| `onnxruntime-web/wasm` | ✔️ |  |
This commit is contained in:
Yulong Wang 2024-12-04 09:46:45 -08:00 committed by GitHub
parent 9b9f881475
commit 50b38ca9d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 51 additions and 12 deletions

View file

@ -83,7 +83,7 @@
"types": "./types.d.ts"
},
"./wasm": {
"import": "./dist/ort.wasm.min.mjs",
"import": "./dist/ort.wasm.bundle.min.mjs",
"require": "./dist/ort.wasm.min.js",
"types": "./types.d.ts"
},

View file

@ -591,14 +591,14 @@ async function main() {
// ort[.min].[m]js
await addAllWebBuildTasks({
outputName: 'ort',
define: { ...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_JSEP': 'true' },
define: { ...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_WEBGL': 'true' },
});
// ort.bundle.min.mjs
await buildOrt({
isProduction: true,
outputName: 'ort.bundle',
format: 'esm',
define: { ...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_JSEP': 'true', 'BUILD_DEFS.DISABLE_DYNAMIC_IMPORT': 'true' },
define: { ...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_WEBGL': 'true', 'BUILD_DEFS.DISABLE_DYNAMIC_IMPORT': 'true' },
});
// ort.webgpu[.min].[m]js
@ -619,6 +619,13 @@ async function main() {
outputName: 'ort.wasm',
define: { ...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_JSEP': 'true', 'BUILD_DEFS.DISABLE_WEBGL': 'true' },
});
// ort.wasm.bundle.min.mjs
await buildOrt({
isProduction: true,
outputName: 'ort.wasm.bundle',
format: 'esm',
define: { ...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_JSEP': 'true', 'BUILD_DEFS.DISABLE_WEBGL': 'true' },
});
// ort.webgl[.min].[m]js
await addAllWebBuildTasks({
outputName: 'ort.webgl',

View file

@ -7,7 +7,7 @@ const documentUrl = document.currentScript.src;
it('Browser E2E testing - WebAssembly backend', async function () {
// preload .wasm file binary
const wasmUrl = new URL('./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.wasm', documentUrl).href;
const wasmUrl = new URL('./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm', documentUrl).href;
const response = await fetch(wasmUrl);
// make sure the .wasm file is loaded successfully

View file

@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
it('Browser E2E testing - WebAssembly backend (path override filename)', async function () {
// check base URL port from test args
if (typeof __ort_arg_port === 'undefined') {
throw new Error('test flag --port=<PORT> is required');
}
const base = `http://localhost:${__ort_arg_port}/`;
ort.env.wasm.wasmPaths = {};
if (typeof __ort_arg_files === 'string' && __ort_arg_files.includes('wasm')) {
const overrideWasmUrl = new URL('./test-wasm-path-override/jsep-renamed.wasm', base).href;
console.log(`ort.env.wasm.wasmPaths['wasm'] = ${JSON.stringify(overrideWasmUrl)};`);
ort.env.wasm.wasmPaths.wasm = overrideWasmUrl;
}
if (typeof __ort_arg_files === 'string' && __ort_arg_files.includes('mjs')) {
const overrideMjsUrl = new URL('./test-wasm-path-override/jsep-renamed.mjs', base).href;
console.log(`ort.env.wasm.wasmPaths['mjs'] = ${JSON.stringify(overrideMjsUrl)};`);
ort.env.wasm.wasmPaths.mjs = overrideMjsUrl;
}
await testFunction(ort, { executionProviders: ['wasm'] });
});

View file

@ -14,7 +14,7 @@ const NODEJS_TEST_CASES = [
// [test_for_same_origin, test_for_cross_origin, main_js, ort_main_js, [test_args]]
const BROWSER_TEST_CASES = [
// IIFE
[true, true, './browser-test-webgl.js', 'ort.min.js'], // webgl
[true, true, './browser-test-webgl.js', 'ort.all.min.js'], // webgl
[true, true, './browser-test-webgl.js', 'ort.webgl.min.js'], // webgl
[true, true, './browser-test-wasm.js', 'ort.wasm.min.js'], // wasm, ort.wasm
[true, true, './browser-test-wasm-multi-session-create.js', 'ort.min.js'], // wasm, multi-session create
@ -24,7 +24,7 @@ const BROWSER_TEST_CASES = [
[true, true, './browser-test-wasm.js', 'ort.min.js', ['num_threads=1', 'proxy=1']], // wasm, 1 thread, proxy
// ort.min.mjs
[true, true, './browser-test-webgl.js', 'ort.min.mjs'], // webgl
[true, true, './browser-test-webgl.js', 'ort.webgl.min.mjs'], // webgl
[true, true, './browser-test-wasm.js', 'ort.min.mjs', ['num_threads=1']], // wasm, 1 thread
[true, true, './browser-test-wasm.js', 'ort.min.mjs', ['num_threads=2']], // wasm, 2 threads
[true, true, './browser-test-wasm.js', 'ort.min.mjs', ['num_threads=2', 'proxy=1']], // wasm, 2 threads, proxy
@ -41,22 +41,22 @@ const BROWSER_TEST_CASES = [
// path override:
// wasm, path override filenames for both mjs and wasm, same origin
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.min.js', ['port=9876', 'files=mjs,wasm']],
[true, false, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=9876', 'files=mjs,wasm']],
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=9876', 'files=mjs,wasm']],
// wasm, path override filenames for both mjs and wasm, cross origin
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.min.js', ['port=8081', 'files=mjs,wasm']],
[false, true, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=8081', 'files=mjs,wasm']],
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=8081', 'files=mjs,wasm']],
// wasm, path override filename for wasm, same origin
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.min.js', ['port=9876', 'files=wasm']],
[true, false, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=9876', 'files=wasm']],
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=9876', 'files=wasm']],
// wasm, path override filename for wasm, cross origin
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.min.js', ['port=8081', 'files=wasm']],
[false, true, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=8081', 'files=wasm']],
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=8081', 'files=wasm']],
// wasm, path override filename for mjs, same origin
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.min.js', ['port=9876', 'files=mjs']],
[true, false, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=9876', 'files=mjs']],
[true, false, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=9876', 'files=mjs']],
// wasm, path override filename for mjs, cross origin
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.min.js', ['port=8081', 'files=mjs']],
[false, true, './browser-test-wasm-path-override-filename-jsep.js', 'ort.min.js', ['port=8081', 'files=mjs']],
[false, true, './browser-test-wasm-path-override-filename.js', 'ort.wasm.min.js', ['port=8081', 'files=mjs']],
// wasm, path override prefix, same origin
[true, false, './browser-test-wasm-path-override-prefix.js', 'ort.min.js', ['port=9876']],

View file

@ -146,6 +146,10 @@ function prepareWasmPathOverrideFiles() {
fs.copyFileSync(`${sourceFile}.wasm`, path.join(folder, 'ort-wasm-simd-threaded.wasm'));
fs.copyFileSync(`${sourceFile}.mjs`, path.join(folder, 'renamed.mjs'));
fs.copyFileSync(`${sourceFile}.wasm`, path.join(folder, 'renamed.wasm'));
fs.copyFileSync(`${sourceFile}.jsep.mjs`, path.join(folder, 'ort-wasm-simd-threaded.jsep.mjs'));
fs.copyFileSync(`${sourceFile}.jsep.wasm`, path.join(folder, 'ort-wasm-simd-threaded.jsep.wasm'));
fs.copyFileSync(`${sourceFile}.jsep.mjs`, path.join(folder, 'jsep-renamed.mjs'));
fs.copyFileSync(`${sourceFile}.jsep.wasm`, path.join(folder, 'jsep-renamed.wasm'));
}
async function testAllNodejsCases() {