@huggingface/transformers 3.0.0-alpha.5 → 3.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
- package/dist/transformers.cjs +172 -112
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.js +141 -64
- package/dist/transformers.js.map +1 -1
- package/dist/transformers.min.cjs +20 -26
- package/dist/transformers.min.cjs.map +1 -1
- package/dist/transformers.min.js +9 -9
- package/dist/transformers.min.js.map +1 -1
- package/dist/transformers.min.mjs +22 -28
- package/dist/transformers.min.mjs.map +1 -1
- package/dist/transformers.mjs +192 -126
- package/dist/transformers.mjs.map +1 -1
- package/package.json +3 -3
- package/src/backends/onnx.js +81 -21
- package/src/env.js +5 -1
- package/src/generation/streamers.js +3 -3
- package/src/models.js +13 -10
- package/src/utils/devices.js +15 -4
- package/src/utils/dtypes.js +1 -3
- package/src/utils/hub.js +17 -16
- package/types/backends/onnx.d.ts +6 -5
- package/types/backends/onnx.d.ts.map +1 -1
- package/types/env.d.ts +2 -0
- package/types/env.d.ts.map +1 -1
- package/types/models.d.ts.map +1 -1
- package/types/utils/devices.d.ts +11 -1
- package/types/utils/devices.d.ts.map +1 -1
- package/types/utils/dtypes.d.ts +0 -3
- package/types/utils/dtypes.d.ts.map +1 -1
- package/types/utils/hub.d.ts +1 -40
- package/types/utils/hub.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ npm i @huggingface/transformers
|
|
|
101
101
|
Alternatively, you can use it in vanilla JS, without any bundler, by using a CDN or static hosting. For example, using [ES Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), you can import the library with:
|
|
102
102
|
```html
|
|
103
103
|
<script type="module">
|
|
104
|
-
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0-alpha.
|
|
104
|
+
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0-alpha.7';
|
|
105
105
|
</script>
|
|
106
106
|
```
|
|
107
107
|
|
|
@@ -134,7 +134,7 @@ Check out the Transformers.js [template](https://huggingface.co/new-space?templa
|
|
|
134
134
|
|
|
135
135
|
|
|
136
136
|
|
|
137
|
-
By default, Transformers.js uses [hosted pretrained models](https://huggingface.co/models?library=transformers.js) and [precompiled WASM binaries](https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0-alpha.
|
|
137
|
+
By default, Transformers.js uses [hosted pretrained models](https://huggingface.co/models?library=transformers.js) and [precompiled WASM binaries](https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0-alpha.7/dist/), which should work out-of-the-box. You can customize this as follows:
|
|
138
138
|
|
|
139
139
|
### Settings
|
|
140
140
|
|
|
Binary file
|
package/dist/transformers.cjs
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
/******/ (() => { // webpackBootstrap
|
|
2
2
|
/******/ var __webpack_modules__ = ({
|
|
3
3
|
|
|
4
|
+
/***/ "fs":
|
|
5
|
+
/*!*********************!*\
|
|
6
|
+
!*** external "fs" ***!
|
|
7
|
+
\*********************/
|
|
8
|
+
/***/ ((module) => {
|
|
9
|
+
|
|
10
|
+
"use strict";
|
|
11
|
+
module.exports = require("fs");
|
|
12
|
+
|
|
13
|
+
/***/ }),
|
|
14
|
+
|
|
4
15
|
/***/ "onnxruntime-node":
|
|
5
16
|
/*!***********************************!*\
|
|
6
17
|
!*** external "onnxruntime-node" ***!
|
|
@@ -12,6 +23,17 @@ module.exports = require("onnxruntime-node");
|
|
|
12
23
|
|
|
13
24
|
/***/ }),
|
|
14
25
|
|
|
26
|
+
/***/ "path":
|
|
27
|
+
/*!***********************!*\
|
|
28
|
+
!*** external "path" ***!
|
|
29
|
+
\***********************/
|
|
30
|
+
/***/ ((module) => {
|
|
31
|
+
|
|
32
|
+
"use strict";
|
|
33
|
+
module.exports = require("path");
|
|
34
|
+
|
|
35
|
+
/***/ }),
|
|
36
|
+
|
|
15
37
|
/***/ "sharp":
|
|
16
38
|
/*!************************!*\
|
|
17
39
|
!*** external "sharp" ***!
|
|
@@ -23,60 +45,21 @@ module.exports = require("sharp");
|
|
|
23
45
|
|
|
24
46
|
/***/ }),
|
|
25
47
|
|
|
26
|
-
/***/ "
|
|
27
|
-
/*!****************************************!*\
|
|
28
|
-
!*** onnxruntime-web/webgpu (ignored) ***!
|
|
29
|
-
\****************************************/
|
|
30
|
-
/***/ (() => {
|
|
31
|
-
|
|
32
|
-
/* (ignored) */
|
|
33
|
-
|
|
34
|
-
/***/ }),
|
|
35
|
-
|
|
36
|
-
/***/ "?7a2c":
|
|
37
|
-
/*!********************!*\
|
|
38
|
-
!*** fs (ignored) ***!
|
|
39
|
-
\********************/
|
|
40
|
-
/***/ (() => {
|
|
41
|
-
|
|
42
|
-
/* (ignored) */
|
|
43
|
-
|
|
44
|
-
/***/ }),
|
|
45
|
-
|
|
46
|
-
/***/ "?a42a":
|
|
48
|
+
/***/ "url":
|
|
47
49
|
/*!**********************!*\
|
|
48
|
-
!***
|
|
50
|
+
!*** external "url" ***!
|
|
49
51
|
\**********************/
|
|
50
|
-
/***/ (() => {
|
|
51
|
-
|
|
52
|
-
/* (ignored) */
|
|
53
|
-
|
|
54
|
-
/***/ }),
|
|
55
|
-
|
|
56
|
-
/***/ "?569f":
|
|
57
|
-
/*!********************!*\
|
|
58
|
-
!*** fs (ignored) ***!
|
|
59
|
-
\********************/
|
|
60
|
-
/***/ (() => {
|
|
61
|
-
|
|
62
|
-
/* (ignored) */
|
|
63
|
-
|
|
64
|
-
/***/ }),
|
|
65
|
-
|
|
66
|
-
/***/ "?3f59":
|
|
67
|
-
/*!**********************!*\
|
|
68
|
-
!*** path (ignored) ***!
|
|
69
|
-
\**********************/
|
|
70
|
-
/***/ (() => {
|
|
52
|
+
/***/ ((module) => {
|
|
71
53
|
|
|
72
|
-
|
|
54
|
+
"use strict";
|
|
55
|
+
module.exports = require("url");
|
|
73
56
|
|
|
74
57
|
/***/ }),
|
|
75
58
|
|
|
76
|
-
/***/ "?
|
|
77
|
-
|
|
78
|
-
!***
|
|
79
|
-
|
|
59
|
+
/***/ "?9c66":
|
|
60
|
+
/*!****************************************!*\
|
|
61
|
+
!*** onnxruntime-web/webgpu (ignored) ***!
|
|
62
|
+
\****************************************/
|
|
80
63
|
/***/ (() => {
|
|
81
64
|
|
|
82
65
|
/* (ignored) */
|
|
@@ -3849,23 +3832,74 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3849
3832
|
|
|
3850
3833
|
|
|
3851
3834
|
|
|
3852
|
-
/**
|
|
3853
|
-
|
|
3835
|
+
/**
|
|
3836
|
+
* @typedef {import('onnxruntime-common').InferenceSession.ExecutionProviderConfig} ONNXExecutionProviders
|
|
3837
|
+
*/
|
|
3838
|
+
|
|
3839
|
+
/** @type {Record<import("../utils/devices.js").DeviceType, ONNXExecutionProviders>} */
|
|
3840
|
+
const DEVICE_TO_EXECUTION_PROVIDER_MAPPING = Object.freeze({
|
|
3841
|
+
auto: null, // Auto-detect based on device and environment
|
|
3842
|
+
gpu: null, // Auto-detect GPU
|
|
3843
|
+
cpu: 'cpu', // CPU
|
|
3844
|
+
wasm: 'wasm', // WebAssembly
|
|
3845
|
+
webgpu: 'webgpu', // WebGPU
|
|
3846
|
+
cuda: 'cuda', // CUDA
|
|
3847
|
+
dml: 'dml', // DirectML
|
|
3848
|
+
|
|
3849
|
+
webnn: { name: 'webnn', deviceType: 'cpu' }, // WebNN (default)
|
|
3850
|
+
'webnn-npu': { name: 'webnn', deviceType: 'npu' }, // WebNN NPU
|
|
3851
|
+
'webnn-gpu': { name: 'webnn', deviceType: 'gpu' }, // WebNN GPU
|
|
3852
|
+
'webnn-cpu': { name: 'webnn', deviceType: 'cpu' }, // WebNN CPU
|
|
3853
|
+
});
|
|
3854
|
+
|
|
3855
|
+
/**
|
|
3856
|
+
* The list of supported devices, sorted by priority/performance.
|
|
3857
|
+
* @type {import("../utils/devices.js").DeviceType[]}
|
|
3858
|
+
*/
|
|
3859
|
+
const supportedDevices = [];
|
|
3854
3860
|
|
|
3855
|
-
/** @type {
|
|
3856
|
-
let
|
|
3861
|
+
/** @type {ONNXExecutionProviders[]} */
|
|
3862
|
+
let defaultDevices;
|
|
3857
3863
|
let ONNX;
|
|
3858
3864
|
if (_env_js__WEBPACK_IMPORTED_MODULE_0__.apis.IS_NODE_ENV) {
|
|
3859
3865
|
ONNX = onnxruntime_node__WEBPACK_IMPORTED_MODULE_1__ ?? /*#__PURE__*/ (onnxruntime_node__WEBPACK_IMPORTED_MODULE_1___namespace_cache || (onnxruntime_node__WEBPACK_IMPORTED_MODULE_1___namespace_cache = __webpack_require__.t(onnxruntime_node__WEBPACK_IMPORTED_MODULE_1__, 2)));
|
|
3860
|
-
|
|
3861
|
-
|
|
3866
|
+
|
|
3867
|
+
// Updated as of ONNX Runtime 1.18.0
|
|
3868
|
+
// The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries.
|
|
3869
|
+
// | EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 |
|
|
3870
|
+
// | ------------- | ----------- | ------------- | ----------------- | ----------- | --------- | ----------- |
|
|
3871
|
+
// | CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
3872
|
+
// | DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ |
|
|
3873
|
+
// | CUDA | ❌ | ❌ | ✔️ (CUDA v11.8) | ❌ | ❌ | ❌ |
|
|
3874
|
+
switch (process.platform) {
|
|
3875
|
+
case 'win32': // Windows x64 and Windows arm64
|
|
3876
|
+
supportedDevices.push('dml');
|
|
3877
|
+
break;
|
|
3878
|
+
case 'linux': // Linux x64 and Linux arm64
|
|
3879
|
+
if (process.arch === 'x64') {
|
|
3880
|
+
supportedDevices.push('cuda');
|
|
3881
|
+
}
|
|
3882
|
+
break;
|
|
3883
|
+
case 'darwin': // MacOS x64 and MacOS arm64
|
|
3884
|
+
break;
|
|
3885
|
+
}
|
|
3886
|
+
|
|
3887
|
+
supportedDevices.push('cpu');
|
|
3888
|
+
defaultDevices = ['cpu'];
|
|
3862
3889
|
} else {
|
|
3863
3890
|
ONNX = /*#__PURE__*/ (onnxruntime_web_webgpu__WEBPACK_IMPORTED_MODULE_2___namespace_cache || (onnxruntime_web_webgpu__WEBPACK_IMPORTED_MODULE_2___namespace_cache = __webpack_require__.t(onnxruntime_web_webgpu__WEBPACK_IMPORTED_MODULE_2__, 2)));
|
|
3891
|
+
|
|
3892
|
+
if (_env_js__WEBPACK_IMPORTED_MODULE_0__.apis.IS_WEBNN_AVAILABLE) {
|
|
3893
|
+
// TODO: Only push supported providers (depending on available hardware)
|
|
3894
|
+
supportedDevices.push('webnn-npu', 'webnn-gpu', 'webnn-cpu', 'webnn');
|
|
3895
|
+
}
|
|
3896
|
+
|
|
3864
3897
|
if (_env_js__WEBPACK_IMPORTED_MODULE_0__.apis.IS_WEBGPU_AVAILABLE) {
|
|
3865
|
-
|
|
3898
|
+
supportedDevices.push('webgpu');
|
|
3866
3899
|
}
|
|
3867
|
-
|
|
3868
|
-
|
|
3900
|
+
|
|
3901
|
+
supportedDevices.push('wasm');
|
|
3902
|
+
defaultDevices = ['wasm'];
|
|
3869
3903
|
}
|
|
3870
3904
|
|
|
3871
3905
|
// @ts-ignore
|
|
@@ -3873,19 +3907,28 @@ const InferenceSession = ONNX.InferenceSession;
|
|
|
3873
3907
|
|
|
3874
3908
|
/**
|
|
3875
3909
|
* Map a device to the execution providers to use for the given device.
|
|
3876
|
-
* @param {import("../utils/devices.js").DeviceType} [device=null] (Optional) The device to run the inference on.
|
|
3877
|
-
* @returns {
|
|
3878
|
-
*/
|
|
3879
|
-
function deviceToExecutionProviders(device) {
|
|
3880
|
-
//
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3910
|
+
* @param {import("../utils/devices.js").DeviceType|"auto"|null} [device=null] (Optional) The device to run the inference on.
|
|
3911
|
+
* @returns {ONNXExecutionProviders[]} The execution providers to use for the given device.
|
|
3912
|
+
*/
|
|
3913
|
+
function deviceToExecutionProviders(device = null) {
|
|
3914
|
+
// Use the default execution providers if the user hasn't specified anything
|
|
3915
|
+
if (!device) return defaultDevices;
|
|
3916
|
+
|
|
3917
|
+
// Handle overloaded cases
|
|
3918
|
+
switch (device) {
|
|
3919
|
+
case "auto":
|
|
3920
|
+
return supportedDevices;
|
|
3921
|
+
case "gpu":
|
|
3922
|
+
return supportedDevices.filter(x =>
|
|
3923
|
+
["webgpu", "cuda", "dml", "webnn-gpu"].includes(x),
|
|
3924
|
+
);
|
|
3887
3925
|
}
|
|
3888
|
-
|
|
3926
|
+
|
|
3927
|
+
if (supportedDevices.includes(device)) {
|
|
3928
|
+
return [DEVICE_TO_EXECUTION_PROVIDER_MAPPING[device] ?? device];
|
|
3929
|
+
}
|
|
3930
|
+
|
|
3931
|
+
throw new Error(`Unsupported device: "${device}". Should be one of: ${supportedDevices.join(', ')}.`)
|
|
3889
3932
|
}
|
|
3890
3933
|
|
|
3891
3934
|
|
|
@@ -3900,7 +3943,7 @@ let wasmInitPromise = null;
|
|
|
3900
3943
|
/**
|
|
3901
3944
|
* Create an ONNX inference session.
|
|
3902
3945
|
* @param {Uint8Array} buffer The ONNX model buffer.
|
|
3903
|
-
* @param {
|
|
3946
|
+
* @param {import('onnxruntime-common').InferenceSession.SessionOptions} session_options ONNX inference session options.
|
|
3904
3947
|
* @returns {Promise<import('onnxruntime-common').InferenceSession>} The ONNX inference session.
|
|
3905
3948
|
*/
|
|
3906
3949
|
async function createInferenceSession(buffer, session_options) {
|
|
@@ -4366,9 +4409,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4366
4409
|
/* harmony export */ "apis": () => (/* binding */ apis),
|
|
4367
4410
|
/* harmony export */ "env": () => (/* binding */ env)
|
|
4368
4411
|
/* harmony export */ });
|
|
4369
|
-
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "
|
|
4370
|
-
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "
|
|
4371
|
-
/* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! url */ "
|
|
4412
|
+
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "fs");
|
|
4413
|
+
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "path");
|
|
4414
|
+
/* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! url */ "url");
|
|
4372
4415
|
/**
|
|
4373
4416
|
* @file Module used to configure Transformers.js.
|
|
4374
4417
|
*
|
|
@@ -4397,13 +4440,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4397
4440
|
|
|
4398
4441
|
|
|
4399
4442
|
|
|
4400
|
-
const VERSION = '3.0.0-alpha.
|
|
4443
|
+
const VERSION = '3.0.0-alpha.7';
|
|
4401
4444
|
|
|
4402
4445
|
// Check if various APIs are available (depends on environment)
|
|
4403
4446
|
const IS_BROWSER_ENV = typeof self !== 'undefined';
|
|
4404
4447
|
const IS_WEBWORKER_ENV = IS_BROWSER_ENV && self.constructor.name === 'DedicatedWorkerGlobalScope';
|
|
4405
4448
|
const IS_WEB_CACHE_AVAILABLE = IS_BROWSER_ENV && 'caches' in self;
|
|
4406
4449
|
const IS_WEBGPU_AVAILABLE = typeof navigator !== 'undefined' && 'gpu' in navigator;
|
|
4450
|
+
const IS_WEBNN_AVAILABLE = typeof navigator !== 'undefined' && 'ml' in navigator;
|
|
4407
4451
|
|
|
4408
4452
|
const IS_PROCESS_AVAILABLE = typeof process !== 'undefined';
|
|
4409
4453
|
const IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === 'node';
|
|
@@ -4426,6 +4470,9 @@ const apis = Object.freeze({
|
|
|
4426
4470
|
/** Whether the WebGPU API is available */
|
|
4427
4471
|
IS_WEBGPU_AVAILABLE,
|
|
4428
4472
|
|
|
4473
|
+
/** Whether the WebNN API is available */
|
|
4474
|
+
IS_WEBNN_AVAILABLE,
|
|
4475
|
+
|
|
4429
4476
|
/** Whether the Node.js process API is available */
|
|
4430
4477
|
IS_PROCESS_AVAILABLE,
|
|
4431
4478
|
|
|
@@ -6149,14 +6196,14 @@ class TextStreamer extends BaseStreamer {
|
|
|
6149
6196
|
throw Error('TextStreamer only supports batch size of 1');
|
|
6150
6197
|
}
|
|
6151
6198
|
|
|
6152
|
-
const tokens = value[0];
|
|
6153
|
-
this.token_callback_function?.(tokens)
|
|
6154
|
-
|
|
6155
6199
|
if (this.skip_prompt && this.next_tokens_are_prompt) {
|
|
6156
6200
|
this.next_tokens_are_prompt = false;
|
|
6157
6201
|
return;
|
|
6158
6202
|
}
|
|
6159
6203
|
|
|
6204
|
+
const tokens = value[0];
|
|
6205
|
+
this.token_callback_function?.(tokens)
|
|
6206
|
+
|
|
6160
6207
|
// Add the new token to the cache and decodes the entire thing.
|
|
6161
6208
|
this.token_cache = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(this.token_cache, tokens);
|
|
6162
6209
|
const text = this.tokenizer.decode(this.token_cache, this.decode_kwargs);
|
|
@@ -6828,9 +6875,10 @@ async function getSession(pretrained_model_name_or_path, fileName, options) {
|
|
|
6828
6875
|
}
|
|
6829
6876
|
|
|
6830
6877
|
// If the device is not specified, we use the default (supported) execution providers.
|
|
6831
|
-
const
|
|
6832
|
-
|
|
6878
|
+
const selectedDevice = /** @type {import("./utils/devices.js").DeviceType} */(
|
|
6879
|
+
device ?? (_env_js__WEBPACK_IMPORTED_MODULE_12__.apis.IS_NODE_ENV ? 'cpu' : 'wasm')
|
|
6833
6880
|
);
|
|
6881
|
+
const executionProviders = (0,_backends_onnx_js__WEBPACK_IMPORTED_MODULE_1__.deviceToExecutionProviders)(selectedDevice);
|
|
6834
6882
|
|
|
6835
6883
|
// If options.dtype is specified, we use it to choose the suffix for the model file.
|
|
6836
6884
|
// Otherwise, we use the default dtype for the device.
|
|
@@ -6839,19 +6887,21 @@ async function getSession(pretrained_model_name_or_path, fileName, options) {
|
|
|
6839
6887
|
if (dtype && dtype.hasOwnProperty(fileName)) {
|
|
6840
6888
|
dtype = dtype[fileName];
|
|
6841
6889
|
} else {
|
|
6842
|
-
dtype = _utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.DEFAULT_DEVICE_DTYPE_MAPPING[
|
|
6843
|
-
console.warn(`dtype not specified for "${fileName}". Using the default dtype for this device (${
|
|
6890
|
+
dtype = _utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.DEFAULT_DEVICE_DTYPE_MAPPING[selectedDevice] ?? _utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.DATA_TYPES.fp32;
|
|
6891
|
+
console.warn(`dtype not specified for "${fileName}". Using the default dtype (${dtype}) for this device (${selectedDevice}).`);
|
|
6844
6892
|
}
|
|
6845
6893
|
}
|
|
6846
6894
|
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
throw new Error(`
|
|
6895
|
+
const selectedDtype = /** @type {import("./utils/dtypes.js").DataType} */(dtype);
|
|
6896
|
+
|
|
6897
|
+
if (!_utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.DEFAULT_DTYPE_SUFFIX_MAPPING.hasOwnProperty(selectedDtype)) {
|
|
6898
|
+
throw new Error(`Invalid dtype: ${selectedDtype}. Should be one of: ${Object.keys(_utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.DATA_TYPES).join(', ')}`);
|
|
6899
|
+
} else if (selectedDtype === _utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.DATA_TYPES.fp16 && selectedDevice === 'webgpu' && !(await (0,_utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.isWebGpuFp16Supported)())) {
|
|
6900
|
+
throw new Error(`The device (${selectedDevice}) does not support fp16.`);
|
|
6851
6901
|
}
|
|
6852
6902
|
|
|
6853
6903
|
// Construct the model file name
|
|
6854
|
-
const suffix = _utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.DEFAULT_DTYPE_SUFFIX_MAPPING[
|
|
6904
|
+
const suffix = _utils_dtypes_js__WEBPACK_IMPORTED_MODULE_2__.DEFAULT_DTYPE_SUFFIX_MAPPING[selectedDtype];
|
|
6855
6905
|
const modelFileName = `${options.subfolder ?? ''}/${fileName}${suffix}.onnx`;
|
|
6856
6906
|
|
|
6857
6907
|
const session_options = { ...options.session_options } ?? {};
|
|
@@ -6898,7 +6948,7 @@ async function getSession(pretrained_model_name_or_path, fileName, options) {
|
|
|
6898
6948
|
session_options.externalData = await Promise.all(externalDataPromises);
|
|
6899
6949
|
}
|
|
6900
6950
|
|
|
6901
|
-
if (
|
|
6951
|
+
if (selectedDevice === 'webgpu') {
|
|
6902
6952
|
const shapes = (0,_configs_js__WEBPACK_IMPORTED_MODULE_0__.getKeyValueShapes)(options.config, {
|
|
6903
6953
|
prefix: 'present',
|
|
6904
6954
|
});
|
|
@@ -25932,11 +25982,22 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
25932
25982
|
/* harmony export */ "DEVICE_TYPES": () => (/* binding */ DEVICE_TYPES)
|
|
25933
25983
|
/* harmony export */ });
|
|
25934
25984
|
|
|
25985
|
+
/**
|
|
25986
|
+
* The list of devices supported by Transformers.js
|
|
25987
|
+
*/
|
|
25935
25988
|
const DEVICE_TYPES = Object.freeze({
|
|
25936
|
-
|
|
25937
|
-
gpu: 'gpu',
|
|
25938
|
-
|
|
25939
|
-
|
|
25989
|
+
auto: 'auto', // Auto-detect based on device and environment
|
|
25990
|
+
gpu: 'gpu', // Auto-detect GPU
|
|
25991
|
+
cpu: 'cpu', // CPU
|
|
25992
|
+
wasm: 'wasm', // WebAssembly
|
|
25993
|
+
webgpu: 'webgpu', // WebGPU
|
|
25994
|
+
cuda: 'cuda', // CUDA
|
|
25995
|
+
dml: 'dml', // DirectML
|
|
25996
|
+
|
|
25997
|
+
webnn: 'webnn', // WebNN (default)
|
|
25998
|
+
'webnn-npu': 'webnn-npu', // WebNN NPU
|
|
25999
|
+
'webnn-gpu': 'webnn-gpu', // WebNN GPU
|
|
26000
|
+
'webnn-cpu': 'webnn-cpu', // WebNN CPU
|
|
25940
26001
|
});
|
|
25941
26002
|
|
|
25942
26003
|
/**
|
|
@@ -26007,10 +26068,8 @@ const DATA_TYPES = Object.freeze({
|
|
|
26007
26068
|
/** @typedef {keyof typeof DATA_TYPES} DataType */
|
|
26008
26069
|
|
|
26009
26070
|
const DEFAULT_DEVICE_DTYPE_MAPPING = Object.freeze({
|
|
26010
|
-
|
|
26011
|
-
[_devices_js__WEBPACK_IMPORTED_MODULE_1__.DEVICE_TYPES.gpu]: DATA_TYPES.fp32,
|
|
26071
|
+
// NOTE: If not specified, will default to fp32
|
|
26012
26072
|
[_devices_js__WEBPACK_IMPORTED_MODULE_1__.DEVICE_TYPES.wasm]: DATA_TYPES.q8,
|
|
26013
|
-
[_devices_js__WEBPACK_IMPORTED_MODULE_1__.DEVICE_TYPES.webgpu]: DATA_TYPES.fp32,
|
|
26014
26073
|
});
|
|
26015
26074
|
|
|
26016
26075
|
/** @type {Record<DataType, string>} */
|
|
@@ -26091,8 +26150,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26091
26150
|
/* harmony export */ "getModelFile": () => (/* binding */ getModelFile),
|
|
26092
26151
|
/* harmony export */ "getModelJSON": () => (/* binding */ getModelJSON)
|
|
26093
26152
|
/* harmony export */ });
|
|
26094
|
-
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "
|
|
26095
|
-
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "
|
|
26153
|
+
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "fs");
|
|
26154
|
+
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "path");
|
|
26096
26155
|
/* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../env.js */ "./src/env.js");
|
|
26097
26156
|
/* harmony import */ var _core_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./core.js */ "./src/utils/core.js");
|
|
26098
26157
|
|
|
@@ -26129,28 +26188,29 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26129
26188
|
* @property {import("./devices.js").DeviceType|Record<string, import("./devices.js").DeviceType>} [device=null] The device to run the model on. If not specified, the device will be chosen from the environment settings.
|
|
26130
26189
|
* @property {import("./dtypes.js").DataType|Record<string, import("./dtypes.js").DataType>} [dtype=null] The data type to use for the model. If not specified, the data type will be chosen from the environment settings.
|
|
26131
26190
|
* @property {boolean|Record<string, boolean>} [use_external_data_format=false] Whether to load the model using the external data format (used for models >= 2GB in size).
|
|
26132
|
-
* @property {
|
|
26191
|
+
* @property {import('onnxruntime-common').InferenceSession.SessionOptions} [session_options] (Optional) User-specified session options passed to the runtime. If not provided, suitable defaults will be chosen.
|
|
26133
26192
|
*/
|
|
26134
26193
|
|
|
26135
26194
|
/**
|
|
26136
26195
|
* @typedef {PretrainedOptions & ModelSpecificPretrainedOptions} PretrainedModelOptions Options for loading a pretrained model.
|
|
26137
26196
|
*/
|
|
26138
26197
|
|
|
26198
|
+
/**
|
|
26199
|
+
* Mapping from file extensions to MIME types.
|
|
26200
|
+
*/
|
|
26201
|
+
const CONTENT_TYPE_MAP = {
|
|
26202
|
+
'txt': 'text/plain',
|
|
26203
|
+
'html': 'text/html',
|
|
26204
|
+
'css': 'text/css',
|
|
26205
|
+
'js': 'text/javascript',
|
|
26206
|
+
'json': 'application/json',
|
|
26207
|
+
'png': 'image/png',
|
|
26208
|
+
'jpg': 'image/jpeg',
|
|
26209
|
+
'jpeg': 'image/jpeg',
|
|
26210
|
+
'gif': 'image/gif',
|
|
26211
|
+
}
|
|
26139
26212
|
class FileResponse {
|
|
26140
|
-
|
|
26141
|
-
* Mapping from file extensions to MIME types.
|
|
26142
|
-
*/
|
|
26143
|
-
_CONTENT_TYPE_MAP = {
|
|
26144
|
-
'txt': 'text/plain',
|
|
26145
|
-
'html': 'text/html',
|
|
26146
|
-
'css': 'text/css',
|
|
26147
|
-
'js': 'text/javascript',
|
|
26148
|
-
'json': 'application/json',
|
|
26149
|
-
'png': 'image/png',
|
|
26150
|
-
'jpg': 'image/jpeg',
|
|
26151
|
-
'jpeg': 'image/jpeg',
|
|
26152
|
-
'gif': 'image/gif',
|
|
26153
|
-
}
|
|
26213
|
+
|
|
26154
26214
|
/**
|
|
26155
26215
|
* Creates a new `FileResponse` object.
|
|
26156
26216
|
* @param {string|URL} filePath
|
|
@@ -26193,7 +26253,7 @@ class FileResponse {
|
|
|
26193
26253
|
updateContentType() {
|
|
26194
26254
|
// Set content-type header based on file extension
|
|
26195
26255
|
const extension = this.filePath.toString().split('.').pop().toLowerCase();
|
|
26196
|
-
this.headers.set('content-type',
|
|
26256
|
+
this.headers.set('content-type', CONTENT_TYPE_MAP[extension] ?? 'application/octet-stream');
|
|
26197
26257
|
}
|
|
26198
26258
|
|
|
26199
26259
|
/**
|