@huggingface/transformers 3.1.0 → 3.1.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 (54) hide show
  1. package/README.md +3 -2
  2. package/dist/transformers.cjs +678 -153
  3. package/dist/transformers.cjs.map +1 -1
  4. package/dist/transformers.js +682 -154
  5. package/dist/transformers.js.map +1 -1
  6. package/dist/transformers.min.cjs +24 -18
  7. package/dist/transformers.min.cjs.map +1 -1
  8. package/dist/transformers.min.js +19 -13
  9. package/dist/transformers.min.js.map +1 -1
  10. package/dist/transformers.min.mjs +30 -24
  11. package/dist/transformers.min.mjs.map +1 -1
  12. package/dist/transformers.mjs +682 -154
  13. package/dist/transformers.mjs.map +1 -1
  14. package/package.json +1 -1
  15. package/src/configs.js +2 -1
  16. package/src/env.js +6 -6
  17. package/src/generation/configuration_utils.js +7 -0
  18. package/src/generation/logits_process.js +22 -16
  19. package/src/generation/streamers.js +7 -2
  20. package/src/models/idefics3/image_processing_idefics3.js +219 -0
  21. package/src/models/idefics3/processing_idefics3.js +136 -0
  22. package/src/models/image_processors.js +1 -0
  23. package/src/models/processors.js +1 -0
  24. package/src/models.js +112 -34
  25. package/src/utils/core.js +14 -0
  26. package/src/utils/dtypes.js +2 -1
  27. package/src/utils/image.js +19 -16
  28. package/src/utils/tensor.js +6 -1
  29. package/types/configs.d.ts +1 -1
  30. package/types/configs.d.ts.map +1 -1
  31. package/types/env.d.ts +1 -1
  32. package/types/env.d.ts.map +1 -1
  33. package/types/generation/configuration_utils.d.ts +6 -0
  34. package/types/generation/configuration_utils.d.ts.map +1 -1
  35. package/types/generation/logits_process.d.ts +30 -20
  36. package/types/generation/logits_process.d.ts.map +1 -1
  37. package/types/generation/streamers.d.ts +13 -8
  38. package/types/generation/streamers.d.ts.map +1 -1
  39. package/types/models/idefics3/image_processing_idefics3.d.ts +40 -0
  40. package/types/models/idefics3/image_processing_idefics3.d.ts.map +1 -0
  41. package/types/models/idefics3/processing_idefics3.d.ts +19 -0
  42. package/types/models/idefics3/processing_idefics3.d.ts.map +1 -0
  43. package/types/models/image_processors.d.ts +1 -0
  44. package/types/models/processors.d.ts +1 -0
  45. package/types/models.d.ts +16 -6
  46. package/types/models.d.ts.map +1 -1
  47. package/types/utils/core.d.ts +7 -0
  48. package/types/utils/core.d.ts.map +1 -1
  49. package/types/utils/dtypes.d.ts +3 -2
  50. package/types/utils/dtypes.d.ts.map +1 -1
  51. package/types/utils/image.d.ts +4 -0
  52. package/types/utils/image.d.ts.map +1 -1
  53. package/types/utils/tensor.d.ts +5 -3
  54. package/types/utils/tensor.d.ts.map +1 -1
package/src/models.js CHANGED
@@ -182,6 +182,22 @@ async function getSession(pretrained_model_name_or_path, fileName, options) {
182
182
  }
183
183
  }
184
184
 
185
+ if (dtype === DATA_TYPES.auto) {
186
+ // Try to choose the auto dtype based on the custom config
187
+ let config_dtype = custom_config.dtype;
188
+ if (typeof config_dtype !== 'string') {
189
+ config_dtype = config_dtype[fileName];
190
+ }
191
+
192
+ if (config_dtype && config_dtype !== DATA_TYPES.auto && DATA_TYPES.hasOwnProperty(config_dtype)) {
193
+ // Defined by the custom config, and is not "auto"
194
+ dtype = config_dtype;
195
+ } else {
196
+ // Choose default dtype based on device, falling back to fp32
197
+ dtype = DEFAULT_DEVICE_DTYPE_MAPPING[selectedDevice] ?? DATA_TYPES.fp32;
198
+ }
199
+ }
200
+
185
201
  const selectedDtype = /** @type {import("./utils/dtypes.js").DataType} */(dtype);
186
202
 
187
203
  if (!DEFAULT_DTYPE_SUFFIX_MAPPING.hasOwnProperty(selectedDtype)) {
@@ -387,9 +403,17 @@ async function sessionRun(session, inputs) {
387
403
  output = replaceTensors(output);
388
404
  return output;
389
405
  } catch (e) {
406
+ // Error messages can be long (nested) and uninformative. For this reason,
407
+ // we apply minor formatting to show the most important information
408
+ const formatted = Object.fromEntries(Object.entries(checkedInputs)
409
+ .map(([k, { type, dims, data }]) => [k, {
410
+ // Extract these properties from the underlying ORT tensor
411
+ type, dims, data,
412
+ }]));
413
+
390
414
  // This usually occurs when the inputs are of the wrong type.
391
415
  console.error(`An error occurred during model execution: "${e}".`);
392
- console.error('Inputs given to model:', checkedInputs)
416
+ console.error('Inputs given to model:', formatted);
393
417
  throw e;
394
418
  }
395
419
  }
@@ -546,6 +570,39 @@ async function decoderForward(self, model_inputs, is_encoder_decoder = false) {
546
570
  }
547
571
 
548
572
 
573
+
574
+ function default_merge_input_ids_with_image_features({
575
+ image_token_id,
576
+ inputs_embeds,
577
+ image_features,
578
+ input_ids,
579
+ attention_mask,
580
+ }) {
581
+ const image_tokens = input_ids.tolist().map(ids =>
582
+ ids.reduce((acc, x, idx) => {
583
+ if (x == image_token_id) acc.push(idx);
584
+ return acc;
585
+ }, [])
586
+ );
587
+ const n_image_tokens = image_tokens.reduce((acc, x) => acc + x.length, 0);
588
+ const n_image_features = image_features.dims[0];
589
+ if (n_image_tokens !== n_image_features) {
590
+ throw new Error(`Image features and image tokens do not match: tokens: ${n_image_tokens}, features ${n_image_features}`);
591
+ }
592
+
593
+ // Equivalent to performing a masked_scatter
594
+ let img = 0;
595
+ for (let i = 0; i < image_tokens.length; ++i) {
596
+ const tokens = image_tokens[i];
597
+ const embeds = inputs_embeds[i];
598
+ for (let j = 0; j < tokens.length; ++j) {
599
+ embeds[tokens[j]].data.set(image_features[img++].data)
600
+ }
601
+ }
602
+ return { inputs_embeds, attention_mask }
603
+ }
604
+
605
+
549
606
  /**
550
607
  * Forward pass of an image-text-to-text model.
551
608
  * @param {Object} self The image-text-to-text model model.
@@ -1013,7 +1070,10 @@ export class PreTrainedModel extends Callable {
1013
1070
 
1014
1071
  } else { // should be MODEL_TYPES.EncoderOnly
1015
1072
  if (modelType !== MODEL_TYPES.EncoderOnly) {
1016
- console.warn(`Model type for '${modelName ?? config?.model_type}' not found, assuming encoder-only architecture. Please report this at ${GITHUB_ISSUE_URL}.`)
1073
+ const type = modelName ?? config?.model_type;
1074
+ if (type !== 'custom') {
1075
+ console.warn(`Model type for '${type}' not found, assuming encoder-only architecture. Please report this at ${GITHUB_ISSUE_URL}.`)
1076
+ }
1017
1077
  }
1018
1078
  info = await Promise.all([
1019
1079
  constructSessions(pretrained_model_name_or_path, {
@@ -1757,7 +1817,7 @@ export class PreTrainedModel extends Callable {
1757
1817
  const dtype = session?.config?.kv_cache_dtype ?? 'float32';
1758
1818
  const empty = (dtype === 'float16') ? new Uint16Array() : [];
1759
1819
 
1760
- const batch_size = (decoderFeeds[this.main_input_name] ?? decoderFeeds.attention_mask).dims?.[0] ?? 1;
1820
+ const batch_size = (decoderFeeds[this.main_input_name] ?? decoderFeeds.attention_mask)?.dims?.[0] ?? 1;
1761
1821
  const shapes = getKeyValueShapes(this.config, { batch_size });
1762
1822
 
1763
1823
  for (const name in shapes) {
@@ -3304,8 +3364,8 @@ export class VisionEncoderDecoderModel extends PreTrainedModel {
3304
3364
  export class LlavaPreTrainedModel extends PreTrainedModel {
3305
3365
  forward_params = [
3306
3366
  'input_ids',
3307
- 'pixel_values',
3308
3367
  'attention_mask',
3368
+ 'pixel_values',
3309
3369
  'position_ids',
3310
3370
  'past_key_values',
3311
3371
  ];
@@ -3487,6 +3547,46 @@ export class Florence2ForConditionalGeneration extends Florence2PreTrainedModel
3487
3547
  return decoder_outputs;
3488
3548
  }
3489
3549
  }
3550
+
3551
+
3552
+ //////////////////////////////////////////////////
3553
+ // Idefics3 Models
3554
+ export class Idefics3PreTrainedModel extends PreTrainedModel {
3555
+ forward_params = [
3556
+ 'input_ids',
3557
+ 'attention_mask',
3558
+ 'pixel_values',
3559
+ 'pixel_attention_mask',
3560
+ 'position_ids',
3561
+ 'past_key_values',
3562
+ ];
3563
+ }
3564
+
3565
+ /**
3566
+ * The LLAVA model which consists of a vision backbone and a language model.
3567
+ */
3568
+ export class Idefics3ForConditionalGeneration extends Idefics3PreTrainedModel {
3569
+
3570
+ async encode_image({ pixel_values, pixel_attention_mask }) {
3571
+ const features = (await sessionRun(this.sessions['vision_encoder'], { pixel_values, pixel_attention_mask })).image_features;
3572
+ return features;
3573
+ }
3574
+
3575
+ _merge_input_ids_with_image_features(kwargs) {
3576
+ const vision_hidden_size = kwargs.image_features.dims.at(-1);
3577
+ const reshaped_image_hidden_states = kwargs.image_features.view(-1, vision_hidden_size);
3578
+
3579
+ return default_merge_input_ids_with_image_features({
3580
+ // @ts-ignore
3581
+ image_token_id: this.config.image_token_id,
3582
+ ...kwargs,
3583
+ image_features: reshaped_image_hidden_states,
3584
+ })
3585
+ }
3586
+ }
3587
+ //////////////////////////////////////////////////
3588
+
3589
+ //////////////////////////////////////////////////
3490
3590
  export class CLIPPreTrainedModel extends PreTrainedModel { }
3491
3591
 
3492
3592
  /**
@@ -4280,36 +4380,12 @@ export class Qwen2VLForConditionalGeneration extends Qwen2VLPreTrainedModel {
4280
4380
  return features;
4281
4381
  }
4282
4382
 
4283
- _merge_input_ids_with_image_features({
4284
- inputs_embeds,
4285
- image_features,
4286
- input_ids,
4287
- attention_mask,
4288
- }) {
4289
- // @ts-ignore
4290
- const { image_token_id } = this.config;
4291
- const image_tokens = input_ids.tolist().map(ids =>
4292
- ids.reduce((acc, x, idx) => {
4293
- if (x == image_token_id) acc.push(idx);
4294
- return acc;
4295
- }, [])
4296
- );
4297
- const n_image_tokens = image_tokens.reduce((acc, x) => acc + x.length, 0);
4298
- const n_image_features = image_features.dims[0];
4299
- if (n_image_tokens !== n_image_features) {
4300
- throw new Error(`Image features and image tokens do not match: tokens: ${n_image_tokens}, features ${n_image_features}`);
4301
- }
4302
-
4303
- // Equivalent to performing a masked_scatter
4304
- let img = 0;
4305
- for (let i = 0; i < image_tokens.length; ++i) {
4306
- const tokens = image_tokens[i];
4307
- const embeds = inputs_embeds[i];
4308
- for (let j = 0; j < tokens.length; ++j) {
4309
- embeds[tokens[j]].data.set(image_features[img++].data)
4310
- }
4311
- }
4312
- return { inputs_embeds, attention_mask }
4383
+ _merge_input_ids_with_image_features(kwargs) {
4384
+ return default_merge_input_ids_with_image_features({
4385
+ // @ts-ignore
4386
+ image_token_id: this.config.image_token_id,
4387
+ ...kwargs
4388
+ })
4313
4389
  }
4314
4390
 
4315
4391
  prepare_inputs_for_generation(input_ids, model_inputs, generation_config) {
@@ -6914,6 +6990,7 @@ const MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES = new Map([
6914
6990
 
6915
6991
  const MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES = new Map([
6916
6992
  ['vision-encoder-decoder', ['VisionEncoderDecoderModel', VisionEncoderDecoderModel]],
6993
+ ['idefics3', ['Idefics3ForConditionalGeneration', Idefics3ForConditionalGeneration]],
6917
6994
  ]);
6918
6995
 
6919
6996
  const MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES = new Map([
@@ -6922,6 +6999,7 @@ const MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES = new Map([
6922
6999
  ['moondream1', ['Moondream1ForConditionalGeneration', Moondream1ForConditionalGeneration]],
6923
7000
  ['florence2', ['Florence2ForConditionalGeneration', Florence2ForConditionalGeneration]],
6924
7001
  ['qwen2-vl', ['Qwen2VLForConditionalGeneration', Qwen2VLForConditionalGeneration]],
7002
+ ['idefics3', ['Idefics3ForConditionalGeneration', Idefics3ForConditionalGeneration]],
6925
7003
  ]);
6926
7004
 
6927
7005
  const MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES = new Map([
package/src/utils/core.js CHANGED
@@ -187,3 +187,17 @@ export function len(s) {
187
187
  for (const c of s) ++length;
188
188
  return length;
189
189
  }
190
+
191
+ /**
192
+ * Count the occurrences of a value in an array or string.
193
+ * This mimics the behavior of Python's `count` method.
194
+ * @param {any[]|string} arr The array or string to search.
195
+ * @param {any} value The value to count.
196
+ */
197
+ export function count(arr, value) {
198
+ let count = 0;
199
+ for (const v of arr) {
200
+ if (v === value) ++count;
201
+ }
202
+ return count;
203
+ }
@@ -31,6 +31,7 @@ export const isWebGpuFp16Supported = (function () {
31
31
  })();
32
32
 
33
33
  export const DATA_TYPES = Object.freeze({
34
+ auto: 'auto', // Auto-detect based on environment
34
35
  fp32: 'fp32',
35
36
  fp16: 'fp16',
36
37
  q8: 'q8',
@@ -47,7 +48,7 @@ export const DEFAULT_DEVICE_DTYPE_MAPPING = Object.freeze({
47
48
  [DEVICE_TYPES.wasm]: DATA_TYPES.q8,
48
49
  });
49
50
 
50
- /** @type {Record<DataType, string>} */
51
+ /** @type {Record<Exclude<DataType, "auto">, string>} */
51
52
  export const DEFAULT_DTYPE_SUFFIX_MAPPING = Object.freeze({
52
53
  [DATA_TYPES.fp32]: '',
53
54
  [DATA_TYPES.fp16]: '_fp16',
@@ -10,19 +10,17 @@
10
10
 
11
11
  import { isNullishDimension } from './core.js';
12
12
  import { getFile } from './hub.js';
13
- import { env } from '../env.js';
13
+ import { env, apis } from '../env.js';
14
14
  import { Tensor } from './tensor.js';
15
15
 
16
16
  // Will be empty (or not used) if running in browser or web-worker
17
17
  import sharp from 'sharp';
18
18
 
19
- const BROWSER_ENV = typeof self !== 'undefined';
20
- const WEBWORKER_ENV = BROWSER_ENV && self.constructor.name === 'DedicatedWorkerGlobalScope';
21
-
22
19
  let createCanvasFunction;
23
20
  let ImageDataClass;
24
21
  let loadImageFunction;
25
- if (BROWSER_ENV) {
22
+ const IS_BROWSER_OR_WEBWORKER = apis.IS_BROWSER_ENV || apis.IS_WEBWORKER_ENV;
23
+ if (IS_BROWSER_OR_WEBWORKER) {
26
24
  // Running in browser or web-worker
27
25
  createCanvasFunction = (/** @type {number} */ width, /** @type {number} */ height) => {
28
26
  if (!self.OffscreenCanvas) {
@@ -132,7 +130,7 @@ export class RawImage {
132
130
  * @returns {RawImage} The image object.
133
131
  */
134
132
  static fromCanvas(canvas) {
135
- if (!BROWSER_ENV) {
133
+ if (!IS_BROWSER_OR_WEBWORKER) {
136
134
  throw new Error('fromCanvas() is only supported in browser environments.')
137
135
  }
138
136
 
@@ -161,7 +159,7 @@ export class RawImage {
161
159
  * @returns {Promise<RawImage>} The image object.
162
160
  */
163
161
  static async fromBlob(blob) {
164
- if (BROWSER_ENV) {
162
+ if (IS_BROWSER_OR_WEBWORKER) {
165
163
  // Running in environment with canvas
166
164
  const img = await loadImageFunction(blob);
167
165
 
@@ -339,7 +337,7 @@ export class RawImage {
339
337
  height = (width / this.width) * this.height;
340
338
  }
341
339
 
342
- if (BROWSER_ENV) {
340
+ if (IS_BROWSER_OR_WEBWORKER) {
343
341
  // TODO use `resample` in browser environment
344
342
 
345
343
  // Store number of channels before resizing
@@ -412,7 +410,7 @@ export class RawImage {
412
410
  return this;
413
411
  }
414
412
 
415
- if (BROWSER_ENV) {
413
+ if (IS_BROWSER_OR_WEBWORKER) {
416
414
  // Store number of channels before padding
417
415
  const numChannels = this.channels;
418
416
 
@@ -461,7 +459,7 @@ export class RawImage {
461
459
  const crop_width = x_max - x_min + 1;
462
460
  const crop_height = y_max - y_min + 1;
463
461
 
464
- if (BROWSER_ENV) {
462
+ if (IS_BROWSER_OR_WEBWORKER) {
465
463
  // Store number of channels before resizing
466
464
  const numChannels = this.channels;
467
465
 
@@ -509,7 +507,7 @@ export class RawImage {
509
507
  const height_offset = (this.height - crop_height) / 2;
510
508
 
511
509
 
512
- if (BROWSER_ENV) {
510
+ if (IS_BROWSER_OR_WEBWORKER) {
513
511
  // Store number of channels before resizing
514
512
  const numChannels = this.channels;
515
513
 
@@ -614,7 +612,7 @@ export class RawImage {
614
612
  }
615
613
 
616
614
  async toBlob(type = 'image/png', quality = 1) {
617
- if (!BROWSER_ENV) {
615
+ if (!IS_BROWSER_OR_WEBWORKER) {
618
616
  throw new Error('toBlob() is only supported in browser environments.')
619
617
  }
620
618
 
@@ -640,7 +638,7 @@ export class RawImage {
640
638
  }
641
639
 
642
640
  toCanvas() {
643
- if (!BROWSER_ENV) {
641
+ if (!IS_BROWSER_OR_WEBWORKER) {
644
642
  throw new Error('toCanvas() is only supported in browser environments.')
645
643
  }
646
644
 
@@ -744,8 +742,8 @@ export class RawImage {
744
742
  */
745
743
  async save(path) {
746
744
 
747
- if (BROWSER_ENV) {
748
- if (WEBWORKER_ENV) {
745
+ if (IS_BROWSER_OR_WEBWORKER) {
746
+ if (apis.IS_WEBWORKER_ENV) {
749
747
  throw new Error('Unable to save an image from a Web Worker.')
750
748
  }
751
749
 
@@ -781,7 +779,7 @@ export class RawImage {
781
779
  }
782
780
 
783
781
  toSharp() {
784
- if (BROWSER_ENV) {
782
+ if (IS_BROWSER_OR_WEBWORKER) {
785
783
  throw new Error('toSharp() is only supported in server-side environments.')
786
784
  }
787
785
 
@@ -794,3 +792,8 @@ export class RawImage {
794
792
  });
795
793
  }
796
794
  }
795
+
796
+ /**
797
+ * Helper function to load an image from a URL, path, etc.
798
+ */
799
+ export const load_image = RawImage.read.bind(RawImage);
@@ -32,6 +32,8 @@ const DataTypeMap = Object.freeze({
32
32
  int64: BigInt64Array,
33
33
  uint64: BigUint64Array,
34
34
  bool: Uint8Array,
35
+ uint4: Uint8Array,
36
+ int4: Int8Array,
35
37
  });
36
38
 
37
39
  /**
@@ -1353,7 +1355,7 @@ function fullHelper(size, fill_value, dtype, cls) {
1353
1355
  /**
1354
1356
  * Creates a tensor of size size filled with fill_value. The tensor's dtype is inferred from fill_value.
1355
1357
  * @param {number[]} size A sequence of integers defining the shape of the output tensor.
1356
- * @param {number|bigint} fill_value The value to fill the output tensor with.
1358
+ * @param {number|bigint|boolean} fill_value The value to fill the output tensor with.
1357
1359
  * @returns {Tensor} The filled tensor.
1358
1360
  */
1359
1361
  export function full(size, fill_value) {
@@ -1365,6 +1367,9 @@ export function full(size, fill_value) {
1365
1367
  } else if (typeof fill_value === 'bigint') {
1366
1368
  dtype = 'int64';
1367
1369
  typedArrayCls = BigInt64Array;
1370
+ } else if (typeof fill_value === 'boolean') {
1371
+ dtype = 'bool';
1372
+ typedArrayCls = Uint8Array;
1368
1373
  } else {
1369
1374
  // TODO: support other dtypes
1370
1375
  throw new Error(`Unsupported data type: ${typeof fill_value}`);
@@ -79,7 +79,7 @@ export type TransformersJSConfig = {
79
79
  /**
80
80
  * The default data type to use for the model.
81
81
  */
82
- dtype?: import('./utils/dtypes.js').DataType;
82
+ dtype?: import('./utils/dtypes.js').DataType | Record<string, import('./utils/dtypes.js').DataType>;
83
83
  /**
84
84
  * Whether to load the model using the external data format (used for models >= 2GB in size).
85
85
  */
@@ -1 +1 @@
1
- {"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../src/configs.js"],"names":[],"mappings":"AAiOA;;;;GAIG;AACH,0CAHW,gBAAgB;;;IACd,OAAO,MAAM,EAAE,MAAM,EAAE,CAAC,CA2EpC;AACD;;;GAGG;AACH;IAwBI;;;;;;;;OAQG;IACH,sDANW,MAAM,0EACN,iBAAiB,GAGf,QAAQ,gBAAgB,CAAC,CAqBrC;IArCD;;;OAGG;IACH,6BAGC;IAnBD,0BAA0B;IAC1B,YADW,MAAM,GAAC,IAAI,CACJ;IAElB,sBAAsB;IACtB,oBADW,OAAO,CACS;IAE3B,qBAAqB;IACrB,yBADW,MAAM,CACO;IAExB,mCAAmC;IACnC,0BADW,oBAAoB,CACN;IAQrB,uBAAkD;CAgCzD;AAED;;;;;GAKG;AACH;IArCI;;;;;;;;OAQG;IACH,6MAmBC;CAcJ;gCAnVY,OAAO,gBAAgB,EAAE,iBAAiB;+BAI1C,OAAO,iBAAiB,EAAE,gBAAgB;2BAI1C,OAAO,iBAAiB,EAAE,YAAY;;;;;;;;qBAgVrC,OAAO,mBAAmB,EAAE,QAAQ,GAAC,OAAO,OAAO,mBAAmB,EAAE,QAAQ,EAAE,OAAO,mBAAmB,EAAE,QAAQ,CAAC;;;;;;+BACvH,OAAO,MAAM,EAAE,MAAM,CAAC;;;;aAGtB,OAAO,oBAAoB,EAAE,UAAU;;;;YACvC,OAAO,mBAAmB,EAAE,QAAQ;;;;+BACpC,OAAO,GAAC,OAAO,MAAM,EAAE,OAAO,CAAC"}
1
+ {"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../src/configs.js"],"names":[],"mappings":"AAkOA;;;;GAIG;AACH,0CAHW,gBAAgB;;;IACd,OAAO,MAAM,EAAE,MAAM,EAAE,CAAC,CA2EpC;AACD;;;GAGG;AACH;IAwBI;;;;;;;;OAQG;IACH,sDANW,MAAM,0EACN,iBAAiB,GAGf,QAAQ,gBAAgB,CAAC,CAqBrC;IArCD;;;OAGG;IACH,6BAGC;IAnBD,0BAA0B;IAC1B,YADW,MAAM,GAAC,IAAI,CACJ;IAElB,sBAAsB;IACtB,oBADW,OAAO,CACS;IAE3B,qBAAqB;IACrB,yBADW,MAAM,CACO;IAExB,mCAAmC;IACnC,0BADW,oBAAoB,CACN;IAQrB,uBAAkD;CAgCzD;AAED;;;;;GAKG;AACH;IArCI;;;;;;;;OAQG;IACH,6MAmBC;CAcJ;gCApVY,OAAO,gBAAgB,EAAE,iBAAiB;+BAI1C,OAAO,iBAAiB,EAAE,gBAAgB;2BAI1C,OAAO,iBAAiB,EAAE,YAAY;;;;;;;;qBAiVrC,OAAO,mBAAmB,EAAE,QAAQ,GAAC,OAAO,OAAO,mBAAmB,EAAE,QAAQ,EAAE,OAAO,mBAAmB,EAAE,QAAQ,CAAC;;;;;;+BACvH,OAAO,MAAM,EAAE,MAAM,CAAC;;;;aAGtB,OAAO,oBAAoB,EAAE,UAAU;;;;YACvC,OAAO,mBAAmB,EAAE,QAAQ,GAAC,OAAO,MAAM,EAAE,OAAO,mBAAmB,EAAE,QAAQ,CAAC;;;;+BACzF,OAAO,GAAC,OAAO,MAAM,EAAE,OAAO,CAAC"}
package/types/env.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * A read-only object containing information about the APIs available in the current environment.
3
3
  */
4
4
  export const apis: Readonly<{
5
- /** Whether we are running in a browser environment */
5
+ /** Whether we are running in a browser environment (and not a web worker) */
6
6
  IS_BROWSER_ENV: boolean;
7
7
  /** Whether we are running in a web worker environment */
8
8
  IS_WEBWORKER_ENV: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.js"],"names":[],"mappings":"AA0CA;;GAEG;AACH;IACI,sDAAsD;;IAGtD,yDAAyD;;IAGzD,yCAAyC;;IAGzC,0CAA0C;;IAG1C,yCAAyC;;IAGzC,mDAAmD;;IAGnD,sDAAsD;;IAGtD,8CAA8C;;IAG9C,wCAAwC;;GAEzC;AA6BH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,sCAAsC;AACtC,kBADW,uBAAuB,CA6BjC;;;;;;;;aAhDa,MAAM;;;;;cACN;QAAC,IAAI,EAAE,QAAQ,OAAO,oBAAoB,EAAE,GAAG,CAAC,CAAA;KAAC;;;;;uBAEjD,OAAO;;;;gBAEP,MAAM;;;;wBACN,MAAM;;;;;sBACN,OAAO;;;;oBAEP,MAAM;;;;WACN,OAAO;;;;qBACP,OAAO;;;;gBACP,OAAO;;;;cACP,MAAM;;;;oBACN,OAAO"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.js"],"names":[],"mappings":"AA0CA;;GAEG;AACH;IACI,6EAA6E;;IAG7E,yDAAyD;;IAGzD,yCAAyC;;IAGzC,0CAA0C;;IAG1C,yCAAyC;;IAGzC,mDAAmD;;IAGnD,sDAAsD;;IAGtD,8CAA8C;;IAG9C,wCAAwC;;GAEzC;AA6BH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,sCAAsC;AACtC,kBADW,uBAAuB,CA6BjC;;;;;;;;aAhDa,MAAM;;;;;cACN;QAAC,IAAI,EAAE,QAAQ,OAAO,oBAAoB,EAAE,GAAG,CAAC,CAAA;KAAC;;;;;uBAEjD,OAAO;;;;gBAEP,MAAM;;;;wBACN,MAAM;;;;;sBACN,OAAO;;;;oBAEP,MAAM;;;;WACN,OAAO;;;;qBACP,OAAO;;;;gBACP,OAAO;;;;cACP,MAAM;;;;oBACN,OAAO"}
@@ -223,6 +223,12 @@ export class GenerationConfig {
223
223
  * @default null
224
224
  */
225
225
  suppress_tokens: number[];
226
+ /**
227
+ * A streamer that will be used to stream the generation.
228
+ * @type {import('./streamers.js').TextStreamer}
229
+ * @default null
230
+ */
231
+ streamer: import('./streamers.js').TextStreamer;
226
232
  /**
227
233
  * A list of tokens that will be suppressed at the beginning of the generation.
228
234
  * The `SuppressBeginTokens` logit processor will set their log probs to `-inf` so that they are not sampled.
@@ -1 +1 @@
1
- {"version":3,"file":"configuration_utils.d.ts","sourceRoot":"","sources":["../../src/generation/configuration_utils.js"],"names":[],"mappings":"AAOA;;GAEG;AACH;IA0WI;;;OAGG;IACH,oBAFW,gBAAgB,GAAC,OAAO,eAAe,EAAE,gBAAgB,EAInE;IA9WD;;;;;;OAMG;IACH,YAHU,MAAM,CAGA;IAEhB;;;;OAIG;IACH,gBAHU,MAAM,CAGM;IAEtB;;;;;;OAMG;IACH,YAHU,MAAM,CAGD;IAEf;;;;OAIG;IACH,gBAHU,MAAM,CAGM;IAEtB;;;;;;;OAOG;IACH,gBAHU,OAAO,GAAC,OAAO,CAGF;IAEvB;;;;;OAKG;IACH,UAHU,MAAM,CAGA;IAGhB;;;;OAIG;IACH,WAHU,OAAO,CAGC;IAElB;;;;OAIG;IACH,WAHU,MAAM,CAGF;IAEd;;;;;OAKG;IACH,iBAHU,MAAM,CAGI;IAEpB;;;;OAIG;IACH,eAHU,MAAM,CAGK;IAErB;;;;OAIG;IACH,WAHU,OAAO,CAGA;IAGjB;;;;OAIG;IACH,aAHU,MAAM,CAGE;IAElB;;;;OAIG;IACH,OAHU,MAAM,CAGL;IAEX;;;;OAIG;IACH,OAHU,MAAM,CAGJ;IAEZ;;;;;;OAMG;IACH,WAHU,MAAM,CAGA;IAEhB;;;;;;OAMG;IACH,gBAHU,MAAM,CAGK;IAErB;;;;;;;OAOG;IACH,YAHU,MAAM,CAGC;IAEjB;;;;;OAKG;IACH,mBAHU,MAAM,CAGQ;IAExB;;;;;OAKG;IACH,oBAHU,MAAM,CAGS;IAEzB;;;;;;OAMG;IACH,4BAHU,MAAM,CAGiB;IAEjC;;;;;;OAMG;I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AHU,KAAQ,CAGC;IAEnB;;;;;OAKG;IACH,qBAHU,MAAM,CAGW;IAE3B;;;;;OAKG;IACH,qBAHU,MAAM,GAAC,MAAM,EAAE,CAGE;IAE3B;;;OAGG;IACH,uBAFU,OAAO,CAEa;IAE9B;;;;;OAKG;IACH,kCAHU,CAAC,MAAM,EAAE,MAAM,CAAC,CAGc;IAExC;;;;;OAKG;IACH,iBAHU,MAAM,EAAE,CAGK;IAEvB;;;;OAIG;IACH,UAHU,OAAO,gBAAgB,EAAE,YAAY,CAG/B;IAEhB;;;;;OAKG;IACH,uBAHU,MAAM,EAAE,CAGW;IAE7B;;;;;OAKG;IACH,oBAHU,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAGF;IAE1B;;;;;;OAMG;IACH,gBAHU,MAAM,CAGM;IAGtB;;;;OAIG;IACH,sBAHU,MAAM,CAGS;IAEzB;;;;;OAKG;IACH,mBAHU,OAAO,CAGS;IAE1B;;;;;OAKG;IACH,sBAHU,OAAO,CAGY;IAE7B;;;;;OAKG;IACH,eAHU,OAAO,CAGK;IAEtB;;;;OAIG;IACH,yBAHU,OAAO,CAGe;IAGhC;;;;OAIG;IACH,cAHU,MAAM,CAGI;IAEpB;;;;OAIG;IACH,cAHU,MAAM,CAGI;IAEpB;;;;;OAKG;IACH,cAHU,MAAM,GAAC,MAAM,EAAE,CAGL;IAGpB;;;;OAIG;IACH,8BAHU,MAAM,CAGiB;IAEjC;;;;OAIG;IACH,wBAHU,MAAM,CAGc;IAG9B;;;;;OAKG;IACH,uBAAuB;CAS1B"}
@@ -80,9 +80,9 @@ export class ForcedBOSTokenLogitsProcessor extends LogitsProcessor {
80
80
  * Apply the BOS token forcing to the logits.
81
81
  * @param {bigint[][]} input_ids The input IDs.
82
82
  * @param {Tensor} logits The logits.
83
- * @returns {Object} The logits with BOS token forcing.
83
+ * @returns {Tensor} The logits with BOS token forcing.
84
84
  */
85
- _call(input_ids: bigint[][], logits: Tensor): any;
85
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
86
86
  }
87
87
  /**
88
88
  * A logits processor that enforces the specified token as the last generated token when `max_length` is reached.
@@ -122,9 +122,9 @@ export class SuppressTokensAtBeginLogitsProcessor extends LogitsProcessor {
122
122
  * Apply the BOS token forcing to the logits.
123
123
  * @param {bigint[][]} input_ids The input IDs.
124
124
  * @param {Tensor} logits The logits.
125
- * @returns {Object} The logits with BOS token forcing.
125
+ * @returns {Tensor} The logits with BOS token forcing.
126
126
  */
127
- _call(input_ids: bigint[][], logits: Tensor): any;
127
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
128
128
  }
129
129
  /**
130
130
  * A LogitsProcessor that handles adding timestamps to generated text.
@@ -182,17 +182,27 @@ export class NoRepeatNGramLogitsProcessor extends LogitsProcessor {
182
182
  * Apply the no-repeat-ngram processor to the logits.
183
183
  * @param {bigint[][]} input_ids The input IDs.
184
184
  * @param {Tensor} logits The logits.
185
- * @returns {Object} The logits with no-repeat-ngram processing.
185
+ * @returns {Tensor} The logits with no-repeat-ngram processing.
186
186
  */
187
- _call(input_ids: bigint[][], logits: Tensor): any;
187
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
188
188
  }
189
189
  /**
190
- * A logits processor that penalises repeated output tokens.
190
+ * A logits processor that prevents the repetition of previous tokens through a penalty.
191
+ * This penalty is applied at most once per token. Note that, for decoder-only models like most LLMs,
192
+ * the considered tokens include the prompt.
193
+ *
194
+ * In the original [paper](https://arxiv.org/pdf/1909.05858.pdf), the authors suggest the use of a
195
+ * penalty of around 1.2 to achieve a good balance between truthful generation and lack of repetition.
196
+ * To penalize and reduce repetition, use `penalty` values above 1.0, where a higher value penalizes
197
+ * more strongly. To reward and encourage repetition, use `penalty` values between 0.0 and 1.0, where
198
+ * a lower value rewards more strongly.
191
199
  */
192
200
  export class RepetitionPenaltyLogitsProcessor extends LogitsProcessor {
193
201
  /**
194
202
  * Create a RepetitionPenaltyLogitsProcessor.
195
- * @param {number} penalty The penalty to apply for repeated tokens.
203
+ * @param {number} penalty The parameter for repetition penalty.
204
+ * - 1.0 means no penalty. Above 1.0 penalizes previously generated tokens.
205
+ * - Between 0.0 and 1.0 rewards previously generated tokens.
196
206
  */
197
207
  constructor(penalty: number);
198
208
  penalty: number;
@@ -200,9 +210,9 @@ export class RepetitionPenaltyLogitsProcessor extends LogitsProcessor {
200
210
  * Apply the repetition penalty to the logits.
201
211
  * @param {bigint[][]} input_ids The input IDs.
202
212
  * @param {Tensor} logits The logits.
203
- * @returns {Object} The logits with repetition penalty processing.
213
+ * @returns {Tensor} The logits with repetition penalty processing.
204
214
  */
205
- _call(input_ids: bigint[][], logits: Tensor): any;
215
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
206
216
  }
207
217
  /**
208
218
  * A logits processor that enforces a minimum number of tokens.
@@ -220,9 +230,9 @@ export class MinLengthLogitsProcessor extends LogitsProcessor {
220
230
  * Apply logit processor.
221
231
  * @param {bigint[][]} input_ids The input IDs.
222
232
  * @param {Tensor} logits The logits.
223
- * @returns {Object} The processed logits.
233
+ * @returns {Tensor} The processed logits.
224
234
  */
225
- _call(input_ids: bigint[][], logits: Tensor): any;
235
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
226
236
  }
227
237
  /**
228
238
  * A logits processor that enforces a minimum number of new tokens.
@@ -242,9 +252,9 @@ export class MinNewTokensLengthLogitsProcessor extends LogitsProcessor {
242
252
  * Apply logit processor.
243
253
  * @param {bigint[][]} input_ids The input IDs.
244
254
  * @param {Tensor} logits The logits.
245
- * @returns {Object} The processed logits.
255
+ * @returns {Tensor} The processed logits.
246
256
  */
247
- _call(input_ids: bigint[][], logits: Tensor): any;
257
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
248
258
  }
249
259
  export class NoBadWordsLogitsProcessor extends LogitsProcessor {
250
260
  /**
@@ -259,9 +269,9 @@ export class NoBadWordsLogitsProcessor extends LogitsProcessor {
259
269
  * Apply logit processor.
260
270
  * @param {bigint[][]} input_ids The input IDs.
261
271
  * @param {Tensor} logits The logits.
262
- * @returns {Object} The processed logits.
272
+ * @returns {Tensor} The processed logits.
263
273
  */
264
- _call(input_ids: bigint[][], logits: Tensor): any;
274
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
265
275
  }
266
276
  /**
267
277
  * [`LogitsProcessor`] for classifier free guidance (CFG). The scores are split over the batch dimension,
@@ -284,9 +294,9 @@ export class ClassifierFreeGuidanceLogitsProcessor extends LogitsProcessor {
284
294
  * Apply logit processor.
285
295
  * @param {bigint[][]} input_ids The input IDs.
286
296
  * @param {Tensor} logits The logits.
287
- * @returns {Object} The processed logits.
297
+ * @returns {Tensor} The processed logits.
288
298
  */
289
- _call(input_ids: bigint[][], logits: Tensor): any;
299
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
290
300
  }
291
301
  /**
292
302
  * [`LogitsWarper`] for temperature (exponential scaling output probability distribution), which effectively means
@@ -305,9 +315,9 @@ export class TemperatureLogitsWarper extends LogitsWarper {
305
315
  * Apply logit warper.
306
316
  * @param {bigint[][]} input_ids The input IDs.
307
317
  * @param {Tensor} logits The logits.
308
- * @returns {Object} The processed logits.
318
+ * @returns {Tensor} The processed logits.
309
319
  */
310
- _call(input_ids: bigint[][], logits: Tensor): any;
320
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
311
321
  }
312
322
  /**
313
323
  * [`LogitsWarper`] that performs top-p, i.e. restricting to top tokens summing to prob_cut_off <= prob_cut_off.
@@ -1 +1 @@
1
- {"version":3,"file":"logits_process.d.ts","sourceRoot":"","sources":["../../src/generation/logits_process.js"],"names":[],"mappings":";;;;AAUA;;GAEG;AACH;IACI;;;;;;;OAOG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,QAKhB;CACJ;;;;;AAGD;;GAEG;AACH;IACI;;;;;;;OAOG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,QAKhB;CACJ;;;;;AAGD;;;;GAIG;AACH;IAMQ,kBAAoB;IAGxB;;;;OAIG;IACH,WAFW,eA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AgC;IAChC,2BAA4C;CAEnD;AAED;;;GAGG;AACH;IACI;;;;;;OAMG;IACH,mBALW,MAAM;QAEW,YAAY,GAA7B,MAAM;QACW,kBAAkB,GAAnC,MAAM;OAahB;IAFG,cAAgD;IAChD,qBAAgC;CAEvC;uBAxsBsB,oBAAoB"}
1
+ {"version":3,"file":"logits_process.d.ts","sourceRoot":"","sources":["../../src/generation/logits_process.js"],"names":[],"mappings":";;;;AAUA;;GAEG;AACH;IACI;;;;;;;OAOG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,QAKhB;CACJ;;;;;AAGD;;GAEG;AACH;IACI;;;;;;;OAOG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,QAKhB;CACJ;;;;;AAGD;;;;GAIG;AACH;IAMQ,kBAAoB;IAGxB;;;;OAIG;IACH,WAFW,eAAe,QAIzB;IAED;;;;OAIG;IACH,cAFW,eAAe,EAAE,QAI3B;IAED;;;;;OAKG;IACH,iBAHW,MAAM,EAAE,EAAE,UACV,MAAM,UAShB;IAED,2CAEC;CACJ;AAwCD;;GAEG;AACH;IACI;;;OAGG;IACH,0BAFW,MAAM,EAKhB;IADG,qBAAgC;IAGpC;;;;;OAKG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,GACJ,MAAM,CAWlB;CACJ;AAED;;GAEG;AACH;IACI;;;;OAIG;IACH,wBAHW,MAAM,gBACN,MAAM,GAAC,MAAM,EAAE,EAMzB;IAFG,mBAA4B;IAC5B,uBAA+E;IAGnF;;;;;OAKG;IACH,iBAHW,MAAM,EAAE,EAAE,UACV,MAAM,UAahB;CACJ;AAED;;;;GAIG;AACH;IACI;;;;OAIG;IACH,mCAHW,MAAM,EAAE,eACR,MAAM,EAMhB;IAFG,gCAAkD;IAClD,oBAA8B;IAGlC;;;;;OAKG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,GACJ,MAAM,CAYlB;CACJ;AAED;;GAEG;AACH;IACI;;;;OAIG;IACH,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I;;;;OAIG;IACH,2BAHW,MAAM,EAAE,EAAE,gBACV,MAAM,GAAC,MAAM,EAAE,EAMzB;IAFG,0BAAkC;IAClC,uBAA+E;IAGnF;;;;;OAKG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,GACJ,MAAM,CA4BlB;CACJ;AAED;;;;;;;GAOG;AACH;IAEI;;;;;OAKG;IACH,4BAJW,MAAM,EAYhB;IADG,uBAAoC;IAGxC;;;;;OAKG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,GACJ,MAAM,CAsBlB;CACJ;AAED;;;GAGG;AACH;IACI;;;;;OAKG;IACH,yBAJW,MAAM,EAgBhB;IADG,oBAA8B;IAGlC;;;;;OAKG;IACH,iBAJW,MAAM,EAAE,EAAE,UACV,MAAM,GACJ,MAAM,CAQlB;CACJ;AAED;;;GAGG;AACH;IACI;;;;;;;OAOG;IACH,mBANW,MAAM;QAGW,YAAY,GAA7B,MAAM;QACW,kBAAkB,GAAnC,MAAM;OAiBhB;IAHG,cAAkB;IAClB,qBAAgC;IAChC,2BAA4C;CAEnD;AAED;;;GAGG;AACH;IACI;;;;;;OAMG;IACH,mBALW,MAAM;QAEW,YAAY,GAA7B,MAAM;QACW,kBAAkB,GAAnC,MAAM;OAahB;IAFG,cAAgD;IAChD,qBAAgC;CAEvC;uBA9sBsB,oBAAoB"}
@@ -16,18 +16,23 @@ export class TextStreamer extends BaseStreamer {
16
16
  /**
17
17
  *
18
18
  * @param {import('../tokenizers.js').PreTrainedTokenizer} tokenizer
19
+ * @param {Object} options
20
+ * @param {boolean} [options.skip_prompt=false] Whether to skip the prompt tokens
21
+ * @param {function(string): void} [options.callback_function=null] Function to call when a piece of text is ready to display
22
+ * @param {function(bigint[]): void} [options.token_callback_function=null] Function to call when a new token is generated
23
+ * @param {Object} [options.decode_kwargs={}] Additional keyword arguments to pass to the tokenizer's decode method
19
24
  */
20
25
  constructor(tokenizer: import('../tokenizers.js').PreTrainedTokenizer, { skip_prompt, callback_function, token_callback_function, decode_kwargs, ...kwargs }?: {
21
26
  skip_prompt?: boolean;
22
- callback_function?: any;
23
- token_callback_function?: any;
24
- decode_kwargs?: {};
27
+ callback_function?: (arg0: string) => void;
28
+ token_callback_function?: (arg0: bigint[]) => void;
29
+ decode_kwargs?: any;
25
30
  });
26
31
  tokenizer: import("../tokenizers.js").PreTrainedTokenizer;
27
32
  skip_prompt: boolean;
28
- callback_function: any;
29
- token_callback_function: any;
30
- decode_kwargs: {};
33
+ callback_function: (x: any) => void;
34
+ token_callback_function: (arg0: bigint[]) => void;
35
+ decode_kwargs: any;
31
36
  token_cache: any[];
32
37
  print_len: number;
33
38
  next_tokens_are_prompt: boolean;
@@ -52,7 +57,7 @@ export class WhisperTextStreamer extends TextStreamer {
52
57
  * @param {Object} options
53
58
  * @param {boolean} [options.skip_prompt=false] Whether to skip the prompt tokens
54
59
  * @param {function(string): void} [options.callback_function=null] Function to call when a piece of text is ready to display
55
- * @param {function(string): void} [options.token_callback_function=null] Function to call when a new token is generated
60
+ * @param {function(bigint[]): void} [options.token_callback_function=null] Function to call when a new token is generated
56
61
  * @param {function(number): void} [options.on_chunk_start=null] Function to call when a new chunk starts
57
62
  * @param {function(number): void} [options.on_chunk_end=null] Function to call when a chunk ends
58
63
  * @param {function(): void} [options.on_finalize=null] Function to call when the stream is finalized
@@ -63,7 +68,7 @@ export class WhisperTextStreamer extends TextStreamer {
63
68
  constructor(tokenizer: import('../tokenizers.js').WhisperTokenizer, { skip_prompt, callback_function, token_callback_function, on_chunk_start, on_chunk_end, on_finalize, time_precision, skip_special_tokens, decode_kwargs, }?: {
64
69
  skip_prompt?: boolean;
65
70
  callback_function?: (arg0: string) => void;
66
- token_callback_function?: (arg0: string) => void;
71
+ token_callback_function?: (arg0: bigint[]) => void;
67
72
  on_chunk_start?: (arg0: number) => void;
68
73
  on_chunk_end?: (arg0: number) => void;
69
74
  on_finalize?: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"streamers.d.ts","sourceRoot":"","sources":["../../src/generation/streamers.js"],"names":[],"mappings":"AASA;IACI;;;OAGG;IACH,WAFW,MAAM,EAAE,EAAE,QAIpB;IAED;;OAEG;IACH,YAEC;CACJ;AAMD;;GAEG;AACH;IACI;;;OAGG;IACH,uBAFW,OAAO,kBAAkB,EAAE,mBAAmB;;;;;OAoBxD;IAVG,0DAA0B;IAC1B,qBAA8B;IAC9B,uBAA0D;IAC1D,6BAAsD;IACtD,kBAAoD;IAGpD,mBAAqB;IACrB,kBAAkB;IAClB,gCAAkC;IA6DtC;;;;OAIG;IACH,wBAHW,MAAM,cACN,OAAO,QASjB;CACJ;AAED;;;;;;;GAOG;AACH;IACI;;;;;;;;;;;;OAYG;IACH,uBAZW,OAAO,kBAAkB,EAAE,gBAAgB;QAEzB,WAAW,GAA7B,OAAO;QAC0B,iBAAiB,UAAzC,MAAM,KAAG,IAAI;QACW,uBAAuB,UAA/C,MAAM,KAAG,IAAI;QACW,cAAc,UAAtC,MAAM,KAAG,IAAI;QACW,YAAY,UAApC,MAAM,KAAG,IAAI;QACK,WAAW,SAA1B,IAAI;QACC,cAAc,GAA/B,MAAM;QACY,mBAAmB,GAArC,OAAO;QACU,aAAa;OA4BxC;IATG,wBAAgD;IAEhD,uBA1BgB,MAAM,KAAG,IAAI,CA0BO;IACpC,qBA1BgB,MAAM,KAAG,IAAI,CA0BG;IAChC,mBA1BmB,IAAI,CA0BO;IAE9B,uBAAoC;IAEpC,+BAAkC;CAiCzC"}
1
+ {"version":3,"file":"streamers.d.ts","sourceRoot":"","sources":["../../src/generation/streamers.js"],"names":[],"mappings":"AASA;IACI;;;OAGG;IACH,WAFW,MAAM,EAAE,EAAE,QAIpB;IAED;;OAEG;IACH,YAEC;CACJ;AAMD;;GAEG;AACH;IACI;;;;;;;;OAQG;IACH,uBAPW,OAAO,kBAAkB,EAAE,mBAAmB;QAE5B,WAAW,GAA7B,OAAO;QAC0B,iBAAiB,UAAzC,MAAM,KAAG,IAAI;QACa,uBAAuB,UAA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