@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 +2 -2
- package/dist/transformers.cjs +84 -75
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.js +48 -22
- package/dist/transformers.js.map +1 -1
- package/dist/transformers.min.cjs +25 -31
- package/dist/transformers.min.cjs.map +1 -1
- package/dist/transformers.min.js +5 -5
- package/dist/transformers.min.js.map +1 -1
- package/dist/transformers.min.mjs +20 -26
- package/dist/transformers.min.mjs.map +1 -1
- package/dist/transformers.mjs +104 -89
- package/dist/transformers.mjs.map +1 -1
- package/package.json +7 -7
- package/src/backends/onnx.js +22 -1
- package/src/env.js +1 -1
- package/src/utils/devices.js +6 -4
- package/src/utils/dtypes.js +2 -0
- package/src/utils/hub.js +17 -16
- package/types/backends/onnx.d.ts +2 -2
- package/types/backends/onnx.d.ts.map +1 -1
- package/types/utils/devices.d.ts +2 -0
- package/types/utils/devices.d.ts.map +1 -1
- package/types/utils/dtypes.d.ts +2 -0
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huggingface/transformers",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.6",
|
|
4
4
|
"description": "State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!",
|
|
5
5
|
"main": "./src/transformers.js",
|
|
6
6
|
"types": "./types/transformers.d.ts",
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
"node": {
|
|
10
10
|
"import": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"types": "./types/transformers.d.ts",
|
|
12
|
+
"default": "./dist/transformers.mjs"
|
|
13
13
|
},
|
|
14
14
|
"require": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"types": "./types/transformers.d.ts",
|
|
16
|
+
"default": "./dist/transformers.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"default": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"types": "./types/transformers.d.ts",
|
|
21
|
+
"default": "./dist/transformers.js"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
package/src/backends/onnx.js
CHANGED
|
@@ -33,6 +33,27 @@ let defaultExecutionProviders;
|
|
|
33
33
|
let ONNX;
|
|
34
34
|
if (apis.IS_NODE_ENV) {
|
|
35
35
|
ONNX = ONNX_NODE.default ?? ONNX_NODE;
|
|
36
|
+
|
|
37
|
+
// Updated as of ONNX Runtime 1.18.0
|
|
38
|
+
// The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries.
|
|
39
|
+
// | EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 |
|
|
40
|
+
// | ------------- | ----------- | ------------- | ----------------- | ----------- | --------- | ----------- |
|
|
41
|
+
// | CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
42
|
+
// | DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ |
|
|
43
|
+
// | CUDA | ❌ | ❌ | ✔️ (CUDA v11.8) | ❌ | ❌ | ❌ |
|
|
44
|
+
switch (process.platform) {
|
|
45
|
+
case 'win32': // Windows x64 and Windows arm64
|
|
46
|
+
supportedExecutionProviders.push('dml');
|
|
47
|
+
break;
|
|
48
|
+
case 'linux': // Linux x64 and Linux arm64
|
|
49
|
+
if (process.arch === 'x64') {
|
|
50
|
+
supportedExecutionProviders.push('cuda');
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case 'darwin': // MacOS x64 and MacOS arm64
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
|
|
36
57
|
supportedExecutionProviders.push('cpu');
|
|
37
58
|
defaultExecutionProviders = ['cpu'];
|
|
38
59
|
} else {
|
|
@@ -76,7 +97,7 @@ let wasmInitPromise = null;
|
|
|
76
97
|
/**
|
|
77
98
|
* Create an ONNX inference session.
|
|
78
99
|
* @param {Uint8Array} buffer The ONNX model buffer.
|
|
79
|
-
* @param {
|
|
100
|
+
* @param {import('onnxruntime-common').InferenceSession.SessionOptions} session_options ONNX inference session options.
|
|
80
101
|
* @returns {Promise<import('onnxruntime-common').InferenceSession>} The ONNX inference session.
|
|
81
102
|
*/
|
|
82
103
|
export async function createInferenceSession(buffer, session_options) {
|
package/src/env.js
CHANGED
|
@@ -26,7 +26,7 @@ import fs from 'fs';
|
|
|
26
26
|
import path from 'path';
|
|
27
27
|
import url from 'url';
|
|
28
28
|
|
|
29
|
-
const VERSION = '3.0.0-alpha.
|
|
29
|
+
const VERSION = '3.0.0-alpha.6';
|
|
30
30
|
|
|
31
31
|
// Check if various APIs are available (depends on environment)
|
|
32
32
|
const IS_BROWSER_ENV = typeof self !== 'undefined';
|
package/src/utils/devices.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
export const DEVICE_TYPES = Object.freeze({
|
|
3
|
-
cpu: 'cpu',
|
|
4
|
-
gpu: 'gpu',
|
|
5
|
-
wasm: 'wasm',
|
|
6
|
-
webgpu: 'webgpu',
|
|
3
|
+
cpu: 'cpu', // CPU
|
|
4
|
+
gpu: 'gpu', // Auto-detect GPU
|
|
5
|
+
wasm: 'wasm', // WebAssembly
|
|
6
|
+
webgpu: 'webgpu', // WebGPU
|
|
7
|
+
cuda: 'cuda', // CUDA
|
|
8
|
+
dml: 'dml', // DirectML
|
|
7
9
|
});
|
|
8
10
|
|
|
9
11
|
/**
|
package/src/utils/dtypes.js
CHANGED
|
@@ -47,6 +47,8 @@ export const DEFAULT_DEVICE_DTYPE_MAPPING = Object.freeze({
|
|
|
47
47
|
[DEVICE_TYPES.gpu]: DATA_TYPES.fp32,
|
|
48
48
|
[DEVICE_TYPES.wasm]: DATA_TYPES.q8,
|
|
49
49
|
[DEVICE_TYPES.webgpu]: DATA_TYPES.fp32,
|
|
50
|
+
[DEVICE_TYPES.cuda]: DATA_TYPES.fp32,
|
|
51
|
+
[DEVICE_TYPES.dml]: DATA_TYPES.fp32,
|
|
50
52
|
});
|
|
51
53
|
|
|
52
54
|
/** @type {Record<DataType, string>} */
|
package/src/utils/hub.js
CHANGED
|
@@ -32,28 +32,29 @@ import { dispatchCallback } from './core.js';
|
|
|
32
32
|
* @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.
|
|
33
33
|
* @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.
|
|
34
34
|
* @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).
|
|
35
|
-
* @property {
|
|
35
|
+
* @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.
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* @typedef {PretrainedOptions & ModelSpecificPretrainedOptions} PretrainedModelOptions Options for loading a pretrained model.
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Mapping from file extensions to MIME types.
|
|
44
|
+
*/
|
|
45
|
+
const CONTENT_TYPE_MAP = {
|
|
46
|
+
'txt': 'text/plain',
|
|
47
|
+
'html': 'text/html',
|
|
48
|
+
'css': 'text/css',
|
|
49
|
+
'js': 'text/javascript',
|
|
50
|
+
'json': 'application/json',
|
|
51
|
+
'png': 'image/png',
|
|
52
|
+
'jpg': 'image/jpeg',
|
|
53
|
+
'jpeg': 'image/jpeg',
|
|
54
|
+
'gif': 'image/gif',
|
|
55
|
+
}
|
|
42
56
|
class FileResponse {
|
|
43
|
-
|
|
44
|
-
* Mapping from file extensions to MIME types.
|
|
45
|
-
*/
|
|
46
|
-
_CONTENT_TYPE_MAP = {
|
|
47
|
-
'txt': 'text/plain',
|
|
48
|
-
'html': 'text/html',
|
|
49
|
-
'css': 'text/css',
|
|
50
|
-
'js': 'text/javascript',
|
|
51
|
-
'json': 'application/json',
|
|
52
|
-
'png': 'image/png',
|
|
53
|
-
'jpg': 'image/jpeg',
|
|
54
|
-
'jpeg': 'image/jpeg',
|
|
55
|
-
'gif': 'image/gif',
|
|
56
|
-
}
|
|
57
|
+
|
|
57
58
|
/**
|
|
58
59
|
* Creates a new `FileResponse` object.
|
|
59
60
|
* @param {string|URL} filePath
|
|
@@ -96,7 +97,7 @@ class FileResponse {
|
|
|
96
97
|
updateContentType() {
|
|
97
98
|
// Set content-type header based on file extension
|
|
98
99
|
const extension = this.filePath.toString().split('.').pop().toLowerCase();
|
|
99
|
-
this.headers.set('content-type',
|
|
100
|
+
this.headers.set('content-type', CONTENT_TYPE_MAP[extension] ?? 'application/octet-stream');
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
/**
|
package/types/backends/onnx.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ export function deviceToExecutionProviders(device?: import("../utils/devices.js"
|
|
|
7
7
|
/**
|
|
8
8
|
* Create an ONNX inference session.
|
|
9
9
|
* @param {Uint8Array} buffer The ONNX model buffer.
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {import('onnxruntime-common').InferenceSession.SessionOptions} session_options ONNX inference session options.
|
|
11
11
|
* @returns {Promise<import('onnxruntime-common').InferenceSession>} The ONNX inference session.
|
|
12
12
|
*/
|
|
13
|
-
export function createInferenceSession(buffer: Uint8Array, session_options:
|
|
13
|
+
export function createInferenceSession(buffer: Uint8Array, session_options: import('onnxruntime-common').InferenceSession.SessionOptions): Promise<import('onnxruntime-common').InferenceSession>;
|
|
14
14
|
/**
|
|
15
15
|
* Check if an object is an ONNX tensor.
|
|
16
16
|
* @param {any} x The object to check
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onnx.d.ts","sourceRoot":"","sources":["../../src/backends/onnx.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onnx.d.ts","sourceRoot":"","sources":["../../src/backends/onnx.js"],"names":[],"mappings":"AAsEA;;;;GAIG;AACH,oDAHW,OAAO,qBAAqB,EAAE,UAAU,GACtC,OAAO,qBAAqB,EAAE,UAAU,EAAE,CAYtD;AAWD;;;;;GAKG;AACH,+CAJW,UAAU,mBACV,OAAO,oBAAoB,EAAE,gBAAgB,CAAC,cAAc,GAC1D,QAAQ,OAAO,oBAAoB,EAAE,gBAAgB,CAAC,CAYlE;AAED;;;;GAIG;AACH,gCAHW,GAAG,GACD,OAAO,CAInB;AAwCD;;;GAGG;AACH,+BAFa,OAAO,CAKnB"}
|
package/types/utils/devices.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../src/utils/devices.js"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../src/utils/devices.js"],"names":[],"mappings":"AACA;;;;;;;GAOG;yBAGU,MAAM,mBAAmB"}
|
package/types/utils/dtypes.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dtypes.d.ts","sourceRoot":"","sources":["../../src/utils/dtypes.js"],"names":[],"mappings":"AAeW,0DAcN;AAGL;;;;;;;;;GASG;AACH,kDAAkD;AAElD
|
|
1
|
+
{"version":3,"file":"dtypes.d.ts","sourceRoot":"","sources":["../../src/utils/dtypes.js"],"names":[],"mappings":"AAeW,0DAcN;AAGL;;;;;;;;;GASG;AACH,kDAAkD;AAElD;;;;;;;GAOG;AAEH,uCAAuC;AACvC,2CADW,OAAO,QAAQ,EAAE,MAAM,CAAC,CAUhC;uBArBW,MAAM,iBAAiB"}
|
package/types/utils/hub.d.ts
CHANGED
|
@@ -89,57 +89,18 @@ export type ModelSpecificPretrainedOptions = {
|
|
|
89
89
|
/**
|
|
90
90
|
* (Optional) User-specified session options passed to the runtime. If not provided, suitable defaults will be chosen.
|
|
91
91
|
*/
|
|
92
|
-
session_options?:
|
|
92
|
+
session_options?: import('onnxruntime-common').InferenceSession.SessionOptions;
|
|
93
93
|
};
|
|
94
94
|
/**
|
|
95
95
|
* Options for loading a pretrained model.
|
|
96
96
|
*/
|
|
97
97
|
export type PretrainedModelOptions = PretrainedOptions & ModelSpecificPretrainedOptions;
|
|
98
|
-
/**
|
|
99
|
-
* @typedef {Object} PretrainedOptions Options for loading a pretrained model.
|
|
100
|
-
* @property {function} [progress_callback=null] If specified, this function will be called during model construction, to provide the user with progress updates.
|
|
101
|
-
* @property {Object} [config=null] Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
|
|
102
|
-
* - The model is a model provided by the library (loaded with the *model id* string of a pretrained model).
|
|
103
|
-
* - The model is loaded by supplying a local directory as `pretrained_model_name_or_path` and a configuration JSON file named *config.json* is found in the directory.
|
|
104
|
-
* @property {string} [cache_dir=null] Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.
|
|
105
|
-
* @property {boolean} [local_files_only=false] Whether or not to only look at local files (e.g., not try downloading the model).
|
|
106
|
-
* @property {string} [revision='main'] The specific model version to use. It can be a branch name, a tag name, or a commit id,
|
|
107
|
-
* since we use a git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier allowed by git.
|
|
108
|
-
* NOTE: This setting is ignored for local requests.
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* @typedef {Object} ModelSpecificPretrainedOptions Options for loading a pretrained model.
|
|
112
|
-
* @property {string} [subfolder='onnx'] In case the relevant files are located inside a subfolder of the model repo on huggingface.co,
|
|
113
|
-
* you can specify the folder name here.
|
|
114
|
-
* @property {string} [model_file_name=null] If specified, load the model with this name (excluding the .onnx suffix). Currently only valid for encoder- or decoder-only models.
|
|
115
|
-
* @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.
|
|
116
|
-
* @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.
|
|
117
|
-
* @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).
|
|
118
|
-
* @property {Object} [session_options] (Optional) User-specified session options passed to the runtime. If not provided, suitable defaults will be chosen.
|
|
119
|
-
*/
|
|
120
|
-
/**
|
|
121
|
-
* @typedef {PretrainedOptions & ModelSpecificPretrainedOptions} PretrainedModelOptions Options for loading a pretrained model.
|
|
122
|
-
*/
|
|
123
98
|
declare class FileResponse {
|
|
124
99
|
/**
|
|
125
100
|
* Creates a new `FileResponse` object.
|
|
126
101
|
* @param {string|URL} filePath
|
|
127
102
|
*/
|
|
128
103
|
constructor(filePath: string | URL);
|
|
129
|
-
/**
|
|
130
|
-
* Mapping from file extensions to MIME types.
|
|
131
|
-
*/
|
|
132
|
-
_CONTENT_TYPE_MAP: {
|
|
133
|
-
txt: string;
|
|
134
|
-
html: string;
|
|
135
|
-
css: string;
|
|
136
|
-
js: string;
|
|
137
|
-
json: string;
|
|
138
|
-
png: string;
|
|
139
|
-
jpg: string;
|
|
140
|
-
jpeg: string;
|
|
141
|
-
gif: string;
|
|
142
|
-
};
|
|
143
104
|
filePath: string | URL;
|
|
144
105
|
headers: Headers;
|
|
145
106
|
exists: any;
|
package/types/utils/hub.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../src/utils/hub.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../src/utils/hub.js"],"names":[],"mappings":"AAuLA;;;;;GAKG;AACH,mCAHW,GAAG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