@huggingface/transformers 3.0.0-alpha.4 → 3.0.0-alpha.6

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 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.4';
104
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0-alpha.6';
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.4/dist/), which should work out-of-the-box. You can customize this as follows:
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.6/dist/), which should work out-of-the-box. You can customize this as follows:
138
138
 
139
139
  ### Settings
140
140
 
@@ -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
- /***/ "?9c66":
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
- !*** path (ignored) ***!
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
- /* (ignored) */
54
+ "use strict";
55
+ module.exports = require("url");
73
56
 
74
57
  /***/ }),
75
58
 
76
- /***/ "?154a":
77
- /*!*********************!*\
78
- !*** url (ignored) ***!
79
- \*********************/
59
+ /***/ "?9c66":
60
+ /*!****************************************!*\
61
+ !*** onnxruntime-web/webgpu (ignored) ***!
62
+ \****************************************/
80
63
  /***/ (() => {
81
64
 
82
65
  /* (ignored) */
@@ -3857,6 +3840,27 @@ let defaultExecutionProviders;
3857
3840
  let ONNX;
3858
3841
  if (_env_js__WEBPACK_IMPORTED_MODULE_0__.apis.IS_NODE_ENV) {
3859
3842
  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)));
3843
+
3844
+ // Updated as of ONNX Runtime 1.18.0
3845
+ // The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries.
3846
+ // | EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 |
3847
+ // | ------------- | ----------- | ------------- | ----------------- | ----------- | --------- | ----------- |
3848
+ // | CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
3849
+ // | DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ |
3850
+ // | CUDA | ❌ | ❌ | ✔️ (CUDA v11.8) | ❌ | ❌ | ❌ |
3851
+ switch (process.platform) {
3852
+ case 'win32': // Windows x64 and Windows arm64
3853
+ supportedExecutionProviders.push('dml');
3854
+ break;
3855
+ case 'linux': // Linux x64 and Linux arm64
3856
+ if (process.arch === 'x64') {
3857
+ supportedExecutionProviders.push('cuda');
3858
+ }
3859
+ break;
3860
+ case 'darwin': // MacOS x64 and MacOS arm64
3861
+ break;
3862
+ }
3863
+
3860
3864
  supportedExecutionProviders.push('cpu');
3861
3865
  defaultExecutionProviders = ['cpu'];
3862
3866
  } else {
@@ -3900,7 +3904,7 @@ let wasmInitPromise = null;
3900
3904
  /**
3901
3905
  * Create an ONNX inference session.
3902
3906
  * @param {Uint8Array} buffer The ONNX model buffer.
3903
- * @param {Object} session_options ONNX inference session options.
3907
+ * @param {import('onnxruntime-common').InferenceSession.SessionOptions} session_options ONNX inference session options.
3904
3908
  * @returns {Promise<import('onnxruntime-common').InferenceSession>} The ONNX inference session.
3905
3909
  */
3906
3910
  async function createInferenceSession(buffer, session_options) {
@@ -4366,9 +4370,9 @@ __webpack_require__.r(__webpack_exports__);
4366
4370
  /* harmony export */ "apis": () => (/* binding */ apis),
4367
4371
  /* harmony export */ "env": () => (/* binding */ env)
4368
4372
  /* harmony export */ });
4369
- /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "?569f");
4370
- /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "?3f59");
4371
- /* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! url */ "?154a");
4373
+ /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "fs");
4374
+ /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "path");
4375
+ /* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! url */ "url");
4372
4376
  /**
4373
4377
  * @file Module used to configure Transformers.js.
4374
4378
  *
@@ -4397,7 +4401,7 @@ __webpack_require__.r(__webpack_exports__);
4397
4401
 
4398
4402
 
4399
4403
 
4400
- const VERSION = '3.0.0-alpha.4';
4404
+ const VERSION = '3.0.0-alpha.6';
4401
4405
 
4402
4406
  // Check if various APIs are available (depends on environment)
4403
4407
  const IS_BROWSER_ENV = typeof self !== 'undefined';
@@ -25933,10 +25937,12 @@ __webpack_require__.r(__webpack_exports__);
25933
25937
  /* harmony export */ });
25934
25938
 
25935
25939
  const DEVICE_TYPES = Object.freeze({
25936
- cpu: 'cpu',
25937
- gpu: 'gpu',
25938
- wasm: 'wasm',
25939
- webgpu: 'webgpu',
25940
+ cpu: 'cpu', // CPU
25941
+ gpu: 'gpu', // Auto-detect GPU
25942
+ wasm: 'wasm', // WebAssembly
25943
+ webgpu: 'webgpu', // WebGPU
25944
+ cuda: 'cuda', // CUDA
25945
+ dml: 'dml', // DirectML
25940
25946
  });
25941
25947
 
25942
25948
  /**
@@ -26011,6 +26017,8 @@ const DEFAULT_DEVICE_DTYPE_MAPPING = Object.freeze({
26011
26017
  [_devices_js__WEBPACK_IMPORTED_MODULE_1__.DEVICE_TYPES.gpu]: DATA_TYPES.fp32,
26012
26018
  [_devices_js__WEBPACK_IMPORTED_MODULE_1__.DEVICE_TYPES.wasm]: DATA_TYPES.q8,
26013
26019
  [_devices_js__WEBPACK_IMPORTED_MODULE_1__.DEVICE_TYPES.webgpu]: DATA_TYPES.fp32,
26020
+ [_devices_js__WEBPACK_IMPORTED_MODULE_1__.DEVICE_TYPES.cuda]: DATA_TYPES.fp32,
26021
+ [_devices_js__WEBPACK_IMPORTED_MODULE_1__.DEVICE_TYPES.dml]: DATA_TYPES.fp32,
26014
26022
  });
26015
26023
 
26016
26024
  /** @type {Record<DataType, string>} */
@@ -26091,8 +26099,8 @@ __webpack_require__.r(__webpack_exports__);
26091
26099
  /* harmony export */ "getModelFile": () => (/* binding */ getModelFile),
26092
26100
  /* harmony export */ "getModelJSON": () => (/* binding */ getModelJSON)
26093
26101
  /* harmony export */ });
26094
- /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "?7a2c");
26095
- /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "?a42a");
26102
+ /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "fs");
26103
+ /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "path");
26096
26104
  /* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../env.js */ "./src/env.js");
26097
26105
  /* harmony import */ var _core_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./core.js */ "./src/utils/core.js");
26098
26106
 
@@ -26129,28 +26137,29 @@ __webpack_require__.r(__webpack_exports__);
26129
26137
  * @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
26138
  * @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
26139
  * @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 {Object} [session_options] (Optional) User-specified session options passed to the runtime. If not provided, suitable defaults will be chosen.
26140
+ * @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
26141
  */
26134
26142
 
26135
26143
  /**
26136
26144
  * @typedef {PretrainedOptions & ModelSpecificPretrainedOptions} PretrainedModelOptions Options for loading a pretrained model.
26137
26145
  */
26138
26146
 
26147
+ /**
26148
+ * Mapping from file extensions to MIME types.
26149
+ */
26150
+ const CONTENT_TYPE_MAP = {
26151
+ 'txt': 'text/plain',
26152
+ 'html': 'text/html',
26153
+ 'css': 'text/css',
26154
+ 'js': 'text/javascript',
26155
+ 'json': 'application/json',
26156
+ 'png': 'image/png',
26157
+ 'jpg': 'image/jpeg',
26158
+ 'jpeg': 'image/jpeg',
26159
+ 'gif': 'image/gif',
26160
+ }
26139
26161
  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
- }
26162
+
26154
26163
  /**
26155
26164
  * Creates a new `FileResponse` object.
26156
26165
  * @param {string|URL} filePath
@@ -26193,7 +26202,7 @@ class FileResponse {
26193
26202
  updateContentType() {
26194
26203
  // Set content-type header based on file extension
26195
26204
  const extension = this.filePath.toString().split('.').pop().toLowerCase();
26196
- this.headers.set('content-type', this._CONTENT_TYPE_MAP[extension] ?? 'application/octet-stream');
26205
+ this.headers.set('content-type', CONTENT_TYPE_MAP[extension] ?? 'application/octet-stream');
26197
26206
  }
26198
26207
 
26199
26208
  /**