mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-23 22:13:38 +00:00
### Description
enable external data loading for ort-web.
### Why
The ORT external data design is highly depending on the file system,
especially synchronous file I/O APIs. Those are not available in web
platforms. We need to have extra code to make external data working on
web.
### How
Considering there is no file system in web, an implementation for web to
support external data is to use pre-loaded data. Assume model file
a.onnx includes initializers that linked to ./b.bin, we require users to
pass a full data file list when creating the session. The user code will
be look like:
```js
const mySess = await ort.InferenceSession.create('./path/model/a.onnx', {
// session options
externalData: [
{
// relative or absolute path/URL of the file,
// or a pre-loaded Uint8Array containing the data of the external data file
data: './path/data/b.bin',
// the relative path of the external data. Should match initializers' "location" value defined in the model file
path: './b.bin'
},
// { } if multiple external data file
]
});
```
Currently, this feature only works with JSEP build enabled.
62 lines
2.3 KiB
JavaScript
62 lines
2.3 KiB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
'use strict';
|
|
|
|
const args = require('minimist')(process.argv.slice(2));
|
|
const SELF_HOST = !!args['self-host'];
|
|
const ORT_MAIN = args['ort-main'];
|
|
const TEST_MAIN = args['test-main'];
|
|
if (typeof TEST_MAIN !== 'string') {
|
|
throw new Error('flag --test-main=<TEST_MAIN_JS_FILE> is required');
|
|
}
|
|
const USER_DATA = args['user-data'];
|
|
if (typeof USER_DATA !== 'string') {
|
|
throw new Error('flag --user-data=<CHROME_USER_DATA_FOLDER> is required');
|
|
}
|
|
|
|
const flags = ['--ignore-gpu-blocklist', '--gpu-vendor-id=0x10de'];
|
|
|
|
module.exports = function(config) {
|
|
const distPrefix = SELF_HOST ? './node_modules/onnxruntime-web/dist/' : 'http://localhost:8081/dist/';
|
|
config.set({
|
|
frameworks: ['mocha'],
|
|
files: [
|
|
{pattern: distPrefix + ORT_MAIN},
|
|
{pattern: './common.js'},
|
|
{pattern: TEST_MAIN},
|
|
{pattern: './node_modules/onnxruntime-web/dist/*.wasm', included: false, nocache: true},
|
|
{pattern: './model.onnx', included: false},
|
|
{pattern: './model_with_orig_ext_data.onnx', included: false},
|
|
{pattern: './model_with_orig_ext_data.bin', included: false},
|
|
],
|
|
plugins: [require('@chiragrupani/karma-chromium-edge-launcher'), ...config.plugins],
|
|
proxies: {
|
|
'/model.onnx': '/base/model.onnx',
|
|
'/model_with_orig_ext_data.onnx': '/base/model_with_orig_ext_data.onnx',
|
|
'/model_with_orig_ext_data.bin': '/base/model_with_orig_ext_data.bin',
|
|
'/test-wasm-path-override/ort-wasm.wasm': '/base/node_modules/onnxruntime-web/dist/ort-wasm.wasm',
|
|
'/test-wasm-path-override/renamed.wasm': '/base/node_modules/onnxruntime-web/dist/ort-wasm.wasm',
|
|
},
|
|
client: {captureConsole: true, mocha: {expose: ['body'], timeout: 60000}},
|
|
reporters: ['mocha'],
|
|
captureTimeout: 120000,
|
|
reportSlowerThan: 100,
|
|
browserDisconnectTimeout: 600000,
|
|
browserNoActivityTimeout: 300000,
|
|
browserDisconnectTolerance: 0,
|
|
browserSocketTimeout: 60000,
|
|
hostname: 'localhost',
|
|
browsers: [],
|
|
customLaunchers: {
|
|
Chrome_default: {base: 'Chrome', flags, chromeDataDir: USER_DATA},
|
|
Chrome_no_threads: {
|
|
base: 'Chrome',
|
|
chromeDataDir: USER_DATA,
|
|
flags
|
|
// TODO: no-thread flags
|
|
},
|
|
Edge_default: {base: 'Edge', edgeDataDir: USER_DATA}
|
|
}
|
|
});
|
|
};
|