@huggingface/transformers 3.0.0-alpha.9 → 3.0.1
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 +82 -50
- package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
- package/dist/transformers.cjs +2550 -2552
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.js +3639 -3567
- 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 +41 -42
- 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 +2586 -2564
- 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 +356 -539
- package/src/ops/registry.js +14 -3
- package/src/pipelines.js +5 -5
- package/src/processors.js +392 -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 +58 -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,
|
|
@@ -2565,7 +2566,6 @@ export class DocumentQuestionAnsweringPipeline extends (/** @type {new (options:
|
|
|
2565
2566
|
|
|
2566
2567
|
/** @type {DocumentQuestionAnsweringPipelineCallback} */
|
|
2567
2568
|
async _call(image, question, generate_kwargs = {}) {
|
|
2568
|
-
throw new Error('This pipeline is not yet supported in Transformers.js v3.'); // TODO: Remove when implemented
|
|
2569
2569
|
|
|
2570
2570
|
// NOTE: For now, we only support a batch size of 1
|
|
2571
2571
|
|
|
@@ -3045,7 +3045,7 @@ const SUPPORTED_TASKS = Object.freeze({
|
|
|
3045
3045
|
"image-segmentation": {
|
|
3046
3046
|
// no tokenizer
|
|
3047
3047
|
"pipeline": ImageSegmentationPipeline,
|
|
3048
|
-
"model": [AutoModelForImageSegmentation, AutoModelForSemanticSegmentation],
|
|
3048
|
+
"model": [AutoModelForImageSegmentation, AutoModelForSemanticSegmentation, AutoModelForUniversalSegmentation],
|
|
3049
3049
|
"processor": AutoProcessor,
|
|
3050
3050
|
"default": {
|
|
3051
3051
|
// TODO: replace with original
|
|
@@ -3287,7 +3287,7 @@ async function loadItems(mapping, model, pretrainedOptions) {
|
|
|
3287
3287
|
|
|
3288
3288
|
/**@type {Promise[]} */
|
|
3289
3289
|
const promises = [];
|
|
3290
|
-
for (
|
|
3290
|
+
for (const [name, cls] of mapping.entries()) {
|
|
3291
3291
|
if (!cls) continue;
|
|
3292
3292
|
|
|
3293
3293
|
/**@type {Promise} */
|
|
@@ -3295,7 +3295,7 @@ async function loadItems(mapping, model, pretrainedOptions) {
|
|
|
3295
3295
|
if (Array.isArray(cls)) {
|
|
3296
3296
|
promise = new Promise(async (resolve, reject) => {
|
|
3297
3297
|
let e;
|
|
3298
|
-
for (
|
|
3298
|
+
for (const c of cls) {
|
|
3299
3299
|
if (c === null) {
|
|
3300
3300
|
// If null, we resolve it immediately, meaning the relevant
|
|
3301
3301
|
// class was not found, but it is optional.
|
|
@@ -3333,7 +3333,7 @@ async function loadItems(mapping, model, pretrainedOptions) {
|
|
|
3333
3333
|
await Promise.all(promises);
|
|
3334
3334
|
|
|
3335
3335
|
// Then assign to result
|
|
3336
|
-
for (
|
|
3336
|
+
for (const [name, promise] of Object.entries(result)) {
|
|
3337
3337
|
result[name] = await promise;
|
|
3338
3338
|
}
|
|
3339
3339
|
|