@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.
Files changed (59) hide show
  1. package/README.md +82 -50
  2. package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
  3. package/dist/transformers.cjs +2550 -2552
  4. package/dist/transformers.cjs.map +1 -1
  5. package/dist/transformers.js +3639 -3567
  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 +41 -42
  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 +2586 -2564
  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 +356 -539
  21. package/src/ops/registry.js +14 -3
  22. package/src/pipelines.js +5 -5
  23. package/src/processors.js +392 -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 +58 -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,
@@ -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 (let [name, cls] of mapping.entries()) {
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 (let c of cls) {
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 (let [name, promise] of Object.entries(result)) {
3336
+ for (const [name, promise] of Object.entries(result)) {
3337
3337
  result[name] = await promise;
3338
3338
  }
3339
3339