@huggingface/transformers 3.0.0-alpha.9 → 3.0.0
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 +33 -22
- package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
- package/dist/transformers.cjs +2515 -2525
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.js +3529 -3455
- package/dist/transformers.js.map +1 -1
- package/dist/transformers.min.cjs +25 -25
- package/dist/transformers.min.cjs.map +1 -1
- package/dist/transformers.min.js +39 -40
- package/dist/transformers.min.js.map +1 -1
- package/dist/transformers.min.mjs +56 -57
- package/dist/transformers.min.mjs.map +1 -1
- package/dist/transformers.mjs +2551 -2538
- package/dist/transformers.mjs.map +1 -1
- package/package.json +14 -13
- package/src/backends/onnx.js +24 -19
- package/src/configs.js +19 -4
- package/src/env.js +5 -9
- package/src/generation/logits_process.js +40 -37
- package/src/models.js +326 -514
- package/src/ops/registry.js +14 -3
- package/src/pipelines.js +5 -4
- package/src/processors.js +390 -351
- package/src/tokenizers.js +140 -175
- package/src/utils/constants.js +1 -1
- package/src/utils/core.js +12 -0
- package/src/utils/data-structures.js +13 -11
- package/src/utils/hub.js +1 -1
- package/src/utils/maths.js +14 -5
- package/src/utils/tensor.js +60 -13
- package/types/backends/onnx.d.ts +5 -2
- package/types/backends/onnx.d.ts.map +1 -1
- package/types/configs.d.ts +29 -3
- package/types/configs.d.ts.map +1 -1
- package/types/env.d.ts +4 -2
- package/types/env.d.ts.map +1 -1
- package/types/generation/logits_process.d.ts.map +1 -1
- package/types/models.d.ts +116 -289
- package/types/models.d.ts.map +1 -1
- package/types/ops/registry.d.ts +6 -6
- package/types/ops/registry.d.ts.map +1 -1
- package/types/pipelines.d.ts +1 -2
- package/types/pipelines.d.ts.map +1 -1
- package/types/processors.d.ts +55 -51
- package/types/processors.d.ts.map +1 -1
- package/types/tokenizers.d.ts +23 -32
- package/types/tokenizers.d.ts.map +1 -1
- package/types/utils/constants.d.ts +1 -1
- package/types/utils/constants.d.ts.map +1 -1
- package/types/utils/core.d.ts +7 -0
- package/types/utils/core.d.ts.map +1 -1
- package/types/utils/data-structures.d.ts +6 -6
- package/types/utils/data-structures.d.ts.map +1 -1
- package/types/utils/hub.d.ts +1 -1
- package/types/utils/hub.d.ts.map +1 -1
- package/types/utils/maths.d.ts +2 -2
- package/types/utils/maths.d.ts.map +1 -1
- package/types/utils/tensor.d.ts +27 -1
- package/types/utils/tensor.d.ts.map +1 -1
package/src/ops/registry.js
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
import { createInferenceSession } from "../backends/onnx.js";
|
|
2
2
|
import { Tensor } from "../utils/tensor.js";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Asynchronously creates a wrapper function for running an ONNX inference session.
|
|
6
|
+
*
|
|
7
|
+
* @param {number[]} session_bytes The session data in bytes.
|
|
8
|
+
* @param {import('onnxruntime-common').InferenceSession.SessionOptions} session_options The options for the ONNX session.
|
|
9
|
+
* @template {string | [string] | string[]} T
|
|
10
|
+
* @param {T} names The name(s) of the output tensor(s).
|
|
11
|
+
*
|
|
12
|
+
* @returns {Promise<function(Record<string, Tensor>): Promise<T extends string ? Tensor : T extends string[] ? { [K in keyof T]: Tensor } : never>>}
|
|
13
|
+
* The wrapper function for running the ONNX inference session.
|
|
14
|
+
*/
|
|
4
15
|
const wrap = async (session_bytes, session_options, names) => {
|
|
5
16
|
const session = await createInferenceSession(
|
|
6
17
|
new Uint8Array(session_bytes), session_options,
|
|
7
18
|
);
|
|
8
|
-
return async (inputs) => {
|
|
19
|
+
return /** @type {any} */(async (/** @type {Record<string, Tensor>} */ inputs) => {
|
|
9
20
|
const ortFeed = Object.fromEntries(Object.entries(inputs).map(([k, v]) => [k, v.ort_tensor]));
|
|
10
21
|
const outputs = await session.run(ortFeed);
|
|
11
22
|
|
|
12
23
|
if (Array.isArray(names)) {
|
|
13
24
|
return names.map((n) => new Tensor(outputs[n]));
|
|
14
25
|
} else {
|
|
15
|
-
return new Tensor(outputs[names]);
|
|
26
|
+
return new Tensor(outputs[/** @type {string} */(names)]);
|
|
16
27
|
}
|
|
17
|
-
}
|
|
28
|
+
})
|
|
18
29
|
}
|
|
19
30
|
|
|
20
31
|
// In-memory registry of initialized ONNX operators
|
package/src/pipelines.js
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
AutoModelForImageClassification,
|
|
35
35
|
AutoModelForImageSegmentation,
|
|
36
36
|
AutoModelForSemanticSegmentation,
|
|
37
|
+
AutoModelForUniversalSegmentation,
|
|
37
38
|
AutoModelForObjectDetection,
|
|
38
39
|
AutoModelForZeroShotObjectDetection,
|
|
39
40
|
AutoModelForDocumentQuestionAnswering,
|
|
@@ -3045,7 +3046,7 @@ const SUPPORTED_TASKS = Object.freeze({
|
|
|
3045
3046
|
"image-segmentation": {
|
|
3046
3047
|
// no tokenizer
|
|
3047
3048
|
"pipeline": ImageSegmentationPipeline,
|
|
3048
|
-
"model": [AutoModelForImageSegmentation, AutoModelForSemanticSegmentation],
|
|
3049
|
+
"model": [AutoModelForImageSegmentation, AutoModelForSemanticSegmentation, AutoModelForUniversalSegmentation],
|
|
3049
3050
|
"processor": AutoProcessor,
|
|
3050
3051
|
"default": {
|
|
3051
3052
|
// TODO: replace with original
|
|
@@ -3287,7 +3288,7 @@ async function loadItems(mapping, model, pretrainedOptions) {
|
|
|
3287
3288
|
|
|
3288
3289
|
/**@type {Promise[]} */
|
|
3289
3290
|
const promises = [];
|
|
3290
|
-
for (
|
|
3291
|
+
for (const [name, cls] of mapping.entries()) {
|
|
3291
3292
|
if (!cls) continue;
|
|
3292
3293
|
|
|
3293
3294
|
/**@type {Promise} */
|
|
@@ -3295,7 +3296,7 @@ async function loadItems(mapping, model, pretrainedOptions) {
|
|
|
3295
3296
|
if (Array.isArray(cls)) {
|
|
3296
3297
|
promise = new Promise(async (resolve, reject) => {
|
|
3297
3298
|
let e;
|
|
3298
|
-
for (
|
|
3299
|
+
for (const c of cls) {
|
|
3299
3300
|
if (c === null) {
|
|
3300
3301
|
// If null, we resolve it immediately, meaning the relevant
|
|
3301
3302
|
// class was not found, but it is optional.
|
|
@@ -3333,7 +3334,7 @@ async function loadItems(mapping, model, pretrainedOptions) {
|
|
|
3333
3334
|
await Promise.all(promises);
|
|
3334
3335
|
|
|
3335
3336
|
// Then assign to result
|
|
3336
|
-
for (
|
|
3337
|
+
for (const [name, promise] of Object.entries(result)) {
|
|
3337
3338
|
result[name] = await promise;
|
|
3338
3339
|
}
|
|
3339
3340
|
|