@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.
Files changed (59) hide show
  1. package/README.md +33 -22
  2. package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
  3. package/dist/transformers.cjs +2515 -2525
  4. package/dist/transformers.cjs.map +1 -1
  5. package/dist/transformers.js +3529 -3455
  6. package/dist/transformers.js.map +1 -1
  7. package/dist/transformers.min.cjs +25 -25
  8. package/dist/transformers.min.cjs.map +1 -1
  9. package/dist/transformers.min.js +39 -40
  10. package/dist/transformers.min.js.map +1 -1
  11. package/dist/transformers.min.mjs +56 -57
  12. package/dist/transformers.min.mjs.map +1 -1
  13. package/dist/transformers.mjs +2551 -2538
  14. package/dist/transformers.mjs.map +1 -1
  15. package/package.json +14 -13
  16. package/src/backends/onnx.js +24 -19
  17. package/src/configs.js +19 -4
  18. package/src/env.js +5 -9
  19. package/src/generation/logits_process.js +40 -37
  20. package/src/models.js +326 -514
  21. package/src/ops/registry.js +14 -3
  22. package/src/pipelines.js +5 -4
  23. package/src/processors.js +390 -351
  24. package/src/tokenizers.js +140 -175
  25. package/src/utils/constants.js +1 -1
  26. package/src/utils/core.js +12 -0
  27. package/src/utils/data-structures.js +13 -11
  28. package/src/utils/hub.js +1 -1
  29. package/src/utils/maths.js +14 -5
  30. package/src/utils/tensor.js +60 -13
  31. package/types/backends/onnx.d.ts +5 -2
  32. package/types/backends/onnx.d.ts.map +1 -1
  33. package/types/configs.d.ts +29 -3
  34. package/types/configs.d.ts.map +1 -1
  35. package/types/env.d.ts +4 -2
  36. package/types/env.d.ts.map +1 -1
  37. package/types/generation/logits_process.d.ts.map +1 -1
  38. package/types/models.d.ts +116 -289
  39. package/types/models.d.ts.map +1 -1
  40. package/types/ops/registry.d.ts +6 -6
  41. package/types/ops/registry.d.ts.map +1 -1
  42. package/types/pipelines.d.ts +1 -2
  43. package/types/pipelines.d.ts.map +1 -1
  44. package/types/processors.d.ts +55 -51
  45. package/types/processors.d.ts.map +1 -1
  46. package/types/tokenizers.d.ts +23 -32
  47. package/types/tokenizers.d.ts.map +1 -1
  48. package/types/utils/constants.d.ts +1 -1
  49. package/types/utils/constants.d.ts.map +1 -1
  50. package/types/utils/core.d.ts +7 -0
  51. package/types/utils/core.d.ts.map +1 -1
  52. package/types/utils/data-structures.d.ts +6 -6
  53. package/types/utils/data-structures.d.ts.map +1 -1
  54. package/types/utils/hub.d.ts +1 -1
  55. package/types/utils/hub.d.ts.map +1 -1
  56. package/types/utils/maths.d.ts +2 -2
  57. package/types/utils/maths.d.ts.map +1 -1
  58. package/types/utils/tensor.d.ts +27 -1
  59. package/types/utils/tensor.d.ts.map +1 -1
@@ -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 (let [name, cls] of mapping.entries()) {
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 (let c of cls) {
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 (let [name, promise] of Object.entries(result)) {
3337
+ for (const [name, promise] of Object.entries(result)) {
3337
3338
  result[name] = await promise;
3338
3339
  }
3339
3340