@huggingface/transformers 3.0.0-alpha.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/LICENSE +202 -0
- package/README.md +376 -0
- package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
- package/dist/transformers.cjs +30741 -0
- package/dist/transformers.cjs.map +1 -0
- package/dist/transformers.js +33858 -0
- package/dist/transformers.js.map +1 -0
- package/dist/transformers.min.cjs +173 -0
- package/dist/transformers.min.cjs.map +1 -0
- package/dist/transformers.min.js +231 -0
- package/dist/transformers.min.js.map +1 -0
- package/package.json +92 -0
- package/src/backends/onnx.js +151 -0
- package/src/configs.js +360 -0
- package/src/env.js +152 -0
- package/src/generation/configuration_utils.js +381 -0
- package/src/generation/logits_process.js +716 -0
- package/src/generation/logits_sampler.js +204 -0
- package/src/generation/parameters.js +35 -0
- package/src/generation/stopping_criteria.js +156 -0
- package/src/generation/streamers.js +212 -0
- package/src/models/whisper/common_whisper.js +151 -0
- package/src/models/whisper/generation_whisper.js +89 -0
- package/src/models.js +7028 -0
- package/src/ops/registry.js +92 -0
- package/src/pipelines.js +3341 -0
- package/src/processors.js +2614 -0
- package/src/tokenizers.js +4395 -0
- package/src/transformers.js +28 -0
- package/src/utils/audio.js +704 -0
- package/src/utils/constants.js +2 -0
- package/src/utils/core.js +149 -0
- package/src/utils/data-structures.js +445 -0
- package/src/utils/devices.js +11 -0
- package/src/utils/dtypes.js +62 -0
- package/src/utils/generic.js +35 -0
- package/src/utils/hub.js +671 -0
- package/src/utils/image.js +745 -0
- package/src/utils/maths.js +1050 -0
- package/src/utils/tensor.js +1378 -0
- package/types/backends/onnx.d.ts +26 -0
- package/types/backends/onnx.d.ts.map +1 -0
- package/types/configs.d.ts +59 -0
- package/types/configs.d.ts.map +1 -0
- package/types/env.d.ts +106 -0
- package/types/env.d.ts.map +1 -0
- package/types/generation/configuration_utils.d.ts +320 -0
- package/types/generation/configuration_utils.d.ts.map +1 -0
- package/types/generation/logits_process.d.ts +354 -0
- package/types/generation/logits_process.d.ts.map +1 -0
- package/types/generation/logits_sampler.d.ts +51 -0
- package/types/generation/logits_sampler.d.ts.map +1 -0
- package/types/generation/parameters.d.ts +47 -0
- package/types/generation/parameters.d.ts.map +1 -0
- package/types/generation/stopping_criteria.d.ts +81 -0
- package/types/generation/stopping_criteria.d.ts.map +1 -0
- package/types/generation/streamers.d.ts +81 -0
- package/types/generation/streamers.d.ts.map +1 -0
- package/types/models/whisper/common_whisper.d.ts +8 -0
- package/types/models/whisper/common_whisper.d.ts.map +1 -0
- package/types/models/whisper/generation_whisper.d.ts +76 -0
- package/types/models/whisper/generation_whisper.d.ts.map +1 -0
- package/types/models.d.ts +3845 -0
- package/types/models.d.ts.map +1 -0
- package/types/ops/registry.d.ts +11 -0
- package/types/ops/registry.d.ts.map +1 -0
- package/types/pipelines.d.ts +2403 -0
- package/types/pipelines.d.ts.map +1 -0
- package/types/processors.d.ts +917 -0
- package/types/processors.d.ts.map +1 -0
- package/types/tokenizers.d.ts +999 -0
- package/types/tokenizers.d.ts.map +1 -0
- package/types/transformers.d.ts +13 -0
- package/types/transformers.d.ts.map +1 -0
- package/types/utils/audio.d.ts +130 -0
- package/types/utils/audio.d.ts.map +1 -0
- package/types/utils/constants.d.ts +2 -0
- package/types/utils/constants.d.ts.map +1 -0
- package/types/utils/core.d.ts +91 -0
- package/types/utils/core.d.ts.map +1 -0
- package/types/utils/data-structures.d.ts +236 -0
- package/types/utils/data-structures.d.ts.map +1 -0
- package/types/utils/devices.d.ts +8 -0
- package/types/utils/devices.d.ts.map +1 -0
- package/types/utils/dtypes.d.ts +22 -0
- package/types/utils/dtypes.d.ts.map +1 -0
- package/types/utils/generic.d.ts +11 -0
- package/types/utils/generic.d.ts.map +1 -0
- package/types/utils/hub.d.ts +191 -0
- package/types/utils/hub.d.ts.map +1 -0
- package/types/utils/image.d.ts +119 -0
- package/types/utils/image.d.ts.map +1 -0
- package/types/utils/maths.d.ts +280 -0
- package/types/utils/maths.d.ts.map +1 -0
- package/types/utils/tensor.d.ts +392 -0
- package/types/utils/tensor.d.ts.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenizers.d.ts","sourceRoot":"","sources":["../src/tokenizers.js"],"names":[],"mappings":"AAkNA;;;;;;;;;;;;;GAaG;AACH,oCAHW,MAAM,GAAC,MAAM,GACX,OAAO,CAanB;;;;;AA2ED;;;;GAIG;AACH;IA0BI;;;;;;OAMG;IACH,gDAHa,cAAc,CAqB1B;IAlDD;;;OAGG;IACH,yBAmBC;IAjBG,YAAoB;IAEpB,uBAAuB;IACvB,OADW,MAAM,EAAE,CACJ;IAEf;;;OAGG;IACH,eAFU,IAAI,MAAM,EAAE,MAAM,CAAC,CAEC;IAE9B,kBAA6B;IAC7B,eAA0B;IAC1B,wBAAmC;IAEnC,uFAAuF;IACvF,UADW,OAAO,CAC2B;IA8BjD;;;;OAIG;IACH,cAHW,MAAM,EAAE,GACN,MAAM,EAAE,CASpB;IAED;;;;;OAKG;IACH,eAJW,MAAM,EAAE,GACN,MAAM,EAAE,CAKpB;IAED;;;;OAIG;IACH,8BAHW,MAAM,EAAE,GACN,MAAM,EAAE,CAIpB;IAED;;;;OAIG;IACH,2BAHW,MAAM,EAAE,GAAC,MAAM,EAAE,GACf,MAAM,EAAE,CAIpB;CACJ;;;;;AAsiED;;;;GAIG;AAEH;IAsII;;;;;;;;OAQG;IACH,sDANW,MAAM,kFACN,0BAA0B,GAGxB,QAAQ,mBAAmB,CAAC,CAsBxC;IA/JD;;;;OAIG;IACH,sDAiGC;IAzGD,+BAA8B;IAE9B,qBAAuB;IASnB,uBAAwC;IAGxC,uBAAiE;IACjE,4BAAyE;IACzE,sBAA4E;IAC5E,8BAA4E;IAC5E,iBAAwD;IAGxD,sBAAwB;IACxB,0BAAyB;IAEzB,2BAA2B;IAC3B,cADW,UAAU,EAAE,CACD;IAetB,+BAAgF;IAgBhF,2BAMQ;IAGR,mBAA6C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sBzB;IAlCD;;OAEG;IACH,yBAGC;IADG,YAAoB;IA+BxB;;;;;;;OAOG;IACH,6CAHa,mBAAmB,CAK/B;IAED;;;;;OAKG;IACH,sCAFa,mBAAmB,CAI/B;CACJ;;;;;AAoKD;;;GAGG;AACH;IAiBI;;;;;;KAMC;IACD,gCAHW,OAAO,CAgCjB;IAnDD;;;;MAIE;IACF,yBAQC;IANG,YAAoB;IAEpB,2BAA2B;IAC3B,cADW,UAAU,EAAE,CACD;IACtB,wBAA8B;IAC9B,kBAAuC;IAyC3C;;;;;MAKE;IACF,cAHU,MAAM,EAAE,GACN,MAAM,CAIjB;IAED;;;;MAIE;IACF,eAHU,MAAM,EAAE,GACN,MAAM,CAIjB;IAED;;;;;;OAMG;IACH,qBAJW,MAAM,EAAE,GACN,MAAM,EAAE,CAKpB;CAEJ;AApkDD;;;;;GAKG;AACH;IACI;;;;;;;;;;OAUG;IACH;QAR0B,OAAO,EAAtB,MAAM;QACS,EAAE,EAAjB,MAAM;QACW,WAAW,GAA5B,OAAO;QACU,MAAM,GAAvB,OAAO;QACU,MAAM,GAAvB,OAAO;QACU,UAAU,GAA3B,OAAO;QACU,OAAO,GAAxB,OAAO;OAUjB;IAPG,gBAA6B;IAC7B,WAAmB;IACnB,qBAA8C;IAC9C,gBAAoC;IACpC,gBAAoC;IACpC,iBAAsC;IACtC,oBAA2C;CAElD;uBA/QsB,mBAAmB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { env } from "./env.js";
|
|
2
|
+
export * from "./pipelines.js";
|
|
3
|
+
export * from "./models.js";
|
|
4
|
+
export * from "./tokenizers.js";
|
|
5
|
+
export * from "./processors.js";
|
|
6
|
+
export * from "./configs.js";
|
|
7
|
+
export * from "./utils/audio.js";
|
|
8
|
+
export * from "./utils/image.js";
|
|
9
|
+
export * from "./utils/tensor.js";
|
|
10
|
+
export * from "./utils/maths.js";
|
|
11
|
+
export * from "./generation/streamers.js";
|
|
12
|
+
export * from "./generation/stopping_criteria.js";
|
|
13
|
+
//# sourceMappingURL=transformers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../src/transformers.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to read audio from a path/URL.
|
|
3
|
+
* @param {string|URL} url The path/URL to load the audio from.
|
|
4
|
+
* @param {number} sampling_rate The sampling rate to use when decoding the audio.
|
|
5
|
+
* @returns {Promise<Float32Array>} The decoded audio as a `Float32Array`.
|
|
6
|
+
*/
|
|
7
|
+
export function read_audio(url: string | URL, sampling_rate: number): Promise<Float32Array>;
|
|
8
|
+
/**
|
|
9
|
+
* Generates a Hanning window of length M.
|
|
10
|
+
* See https://numpy.org/doc/stable/reference/generated/numpy.hanning.html for more information.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} M The length of the Hanning window to generate.
|
|
13
|
+
* @returns {Float64Array} The generated Hanning window.
|
|
14
|
+
*/
|
|
15
|
+
export function hanning(M: number): Float64Array;
|
|
16
|
+
/**
|
|
17
|
+
* Generates a Hamming window of length M.
|
|
18
|
+
* See https://numpy.org/doc/stable/reference/generated/numpy.hamming.html for more information.
|
|
19
|
+
*
|
|
20
|
+
* @param {number} M The length of the Hamming window to generate.
|
|
21
|
+
* @returns {Float64Array} The generated Hamming window.
|
|
22
|
+
*/
|
|
23
|
+
export function hamming(M: number): Float64Array;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a frequency bin conversion matrix used to obtain a mel spectrogram. This is called a *mel filter bank*, and
|
|
26
|
+
* various implementation exist, which differ in the number of filters, the shape of the filters, the way the filters
|
|
27
|
+
* are spaced, the bandwidth of the filters, and the manner in which the spectrum is warped. The goal of these
|
|
28
|
+
* features is to approximate the non-linear human perception of the variation in pitch with respect to the frequency.
|
|
29
|
+
* @param {number} num_frequency_bins Number of frequencies used to compute the spectrogram (should be the same as in `stft`).
|
|
30
|
+
* @param {number} num_mel_filters Number of mel filters to generate.
|
|
31
|
+
* @param {number} min_frequency Lowest frequency of interest in Hz.
|
|
32
|
+
* @param {number} max_frequency Highest frequency of interest in Hz. This should not exceed `sampling_rate / 2`.
|
|
33
|
+
* @param {number} sampling_rate Sample rate of the audio waveform.
|
|
34
|
+
* @param {string} [norm] If `"slaney"`, divide the triangular mel weights by the width of the mel band (area normalization).
|
|
35
|
+
* @param {string} [mel_scale] The mel frequency scale to use, `"htk"` or `"slaney"`.
|
|
36
|
+
* @param {boolean} [triangularize_in_mel_space] If this option is enabled, the triangular filter is applied in mel space rather than frequency space.
|
|
37
|
+
* This should be set to `true` in order to get the same results as `torchaudio` when computing mel filters.
|
|
38
|
+
* @returns {number[][]} Triangular filter bank matrix, which is a 2D array of shape (`num_frequency_bins`, `num_mel_filters`).
|
|
39
|
+
* This is a projection matrix to go from a spectrogram to a mel spectrogram.
|
|
40
|
+
*/
|
|
41
|
+
export function mel_filter_bank(num_frequency_bins: number, num_mel_filters: number, min_frequency: number, max_frequency: number, sampling_rate: number, norm?: string, mel_scale?: string, triangularize_in_mel_space?: boolean): number[][];
|
|
42
|
+
/**
|
|
43
|
+
* Calculates a spectrogram over one waveform using the Short-Time Fourier Transform.
|
|
44
|
+
*
|
|
45
|
+
* This function can create the following kinds of spectrograms:
|
|
46
|
+
* - amplitude spectrogram (`power = 1.0`)
|
|
47
|
+
* - power spectrogram (`power = 2.0`)
|
|
48
|
+
* - complex-valued spectrogram (`power = None`)
|
|
49
|
+
* - log spectrogram (use `log_mel` argument)
|
|
50
|
+
* - mel spectrogram (provide `mel_filters`)
|
|
51
|
+
* - log-mel spectrogram (provide `mel_filters` and `log_mel`)
|
|
52
|
+
*
|
|
53
|
+
* In this implementation, the window is assumed to be zero-padded to have the same size as the analysis frame.
|
|
54
|
+
* A padded window can be obtained from `window_function()`. The FFT input buffer may be larger than the analysis frame,
|
|
55
|
+
* typically the next power of two.
|
|
56
|
+
*
|
|
57
|
+
* @param {Float32Array|Float64Array} waveform The input waveform of shape `(length,)`. This must be a single real-valued, mono waveform.
|
|
58
|
+
* @param {Float32Array|Float64Array} window The windowing function to apply of shape `(frame_length,)`, including zero-padding if necessary. The actual window length may be
|
|
59
|
+
* shorter than `frame_length`, but we're assuming the array has already been zero-padded.
|
|
60
|
+
* @param {number} frame_length The length of the analysis frames in samples (a.k.a., `fft_length`).
|
|
61
|
+
* @param {number} hop_length The stride between successive analysis frames in samples.
|
|
62
|
+
* @param {Object} options
|
|
63
|
+
* @param {number} [options.fft_length=null] The size of the FFT buffer in samples. This determines how many frequency bins the spectrogram will have.
|
|
64
|
+
* For optimal speed, this should be a power of two. If `null`, uses `frame_length`.
|
|
65
|
+
* @param {number} [options.power=1.0] If 1.0, returns the amplitude spectrogram. If 2.0, returns the power spectrogram. If `null`, returns complex numbers.
|
|
66
|
+
* @param {boolean} [options.center=true] Whether to pad the waveform so that frame `t` is centered around time `t * hop_length`. If `false`, frame
|
|
67
|
+
* `t` will start at time `t * hop_length`.
|
|
68
|
+
* @param {string} [options.pad_mode="reflect"] Padding mode used when `center` is `true`. Possible values are: `"constant"` (pad with zeros),
|
|
69
|
+
* `"edge"` (pad with edge values), `"reflect"` (pads with mirrored values).
|
|
70
|
+
* @param {boolean} [options.onesided=true] If `true`, only computes the positive frequencies and returns a spectrogram containing `fft_length // 2 + 1`
|
|
71
|
+
* frequency bins. If `false`, also computes the negative frequencies and returns `fft_length` frequency bins.
|
|
72
|
+
* @param {number} [options.preemphasis=null] Coefficient for a low-pass filter that applies pre-emphasis before the DFT.
|
|
73
|
+
* @param {number[][]} [options.mel_filters=null] The mel filter bank of shape `(num_freq_bins, num_mel_filters)`.
|
|
74
|
+
* If supplied, applies this filter bank to create a mel spectrogram.
|
|
75
|
+
* @param {number} [options.mel_floor=1e-10] Minimum value of mel frequency banks.
|
|
76
|
+
* @param {string} [options.log_mel=null] How to convert the spectrogram to log scale. Possible options are:
|
|
77
|
+
* `null` (don't convert), `"log"` (take the natural logarithm) `"log10"` (take the base-10 logarithm), `"dB"` (convert to decibels).
|
|
78
|
+
* Can only be used when `power` is not `null`.
|
|
79
|
+
* @param {number} [options.reference=1.0] Sets the input spectrogram value that corresponds to 0 dB. For example, use `max(spectrogram)[0]` to set
|
|
80
|
+
* the loudest part to 0 dB. Must be greater than zero.
|
|
81
|
+
* @param {number} [options.min_value=1e-10] The spectrogram will be clipped to this minimum value before conversion to decibels, to avoid taking `log(0)`.
|
|
82
|
+
* For a power spectrogram, the default of `1e-10` corresponds to a minimum of -100 dB. For an amplitude spectrogram, the value `1e-5` corresponds to -100 dB.
|
|
83
|
+
* Must be greater than zero.
|
|
84
|
+
* @param {number} [options.db_range=null] Sets the maximum dynamic range in decibels. For example, if `db_range = 80`, the difference between the
|
|
85
|
+
* peak value and the smallest value will never be more than 80 dB. Must be greater than zero.
|
|
86
|
+
* @param {boolean} [options.remove_dc_offset=null] Subtract mean from waveform on each frame, applied before pre-emphasis. This should be set to `true` in
|
|
87
|
+
* order to get the same results as `torchaudio.compliance.kaldi.fbank` when computing mel filters.
|
|
88
|
+
* @param {number} [options.max_num_frames=null] If provided, limits the number of frames to compute to this value.
|
|
89
|
+
* @param {number} [options.min_num_frames=null] If provided, ensures the number of frames to compute is at least this value.
|
|
90
|
+
* @param {boolean} [options.do_pad=true] If `true`, pads the output spectrogram to have `max_num_frames` frames.
|
|
91
|
+
* @param {boolean} [options.transpose=false] If `true`, the returned spectrogram will have shape `(num_frames, num_frequency_bins/num_mel_filters)`. If `false`, the returned spectrogram will have shape `(num_frequency_bins/num_mel_filters, num_frames)`.
|
|
92
|
+
* @returns {Promise<Tensor>} Spectrogram of shape `(num_frequency_bins, length)` (regular spectrogram) or shape `(num_mel_filters, length)` (mel spectrogram).
|
|
93
|
+
*/
|
|
94
|
+
export function spectrogram(waveform: Float32Array | Float64Array, window: Float32Array | Float64Array, frame_length: number, hop_length: number, { fft_length, power, center, pad_mode, onesided, preemphasis, mel_filters, mel_floor, log_mel, reference, min_value, db_range, remove_dc_offset, min_num_frames, max_num_frames, do_pad, transpose, }?: {
|
|
95
|
+
fft_length?: number;
|
|
96
|
+
power?: number;
|
|
97
|
+
center?: boolean;
|
|
98
|
+
pad_mode?: string;
|
|
99
|
+
onesided?: boolean;
|
|
100
|
+
preemphasis?: number;
|
|
101
|
+
mel_filters?: number[][];
|
|
102
|
+
mel_floor?: number;
|
|
103
|
+
log_mel?: string;
|
|
104
|
+
reference?: number;
|
|
105
|
+
min_value?: number;
|
|
106
|
+
db_range?: number;
|
|
107
|
+
remove_dc_offset?: boolean;
|
|
108
|
+
max_num_frames?: number;
|
|
109
|
+
min_num_frames?: number;
|
|
110
|
+
do_pad?: boolean;
|
|
111
|
+
transpose?: boolean;
|
|
112
|
+
}): Promise<Tensor>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns an array containing the specified window.
|
|
115
|
+
* @param {number} window_length The length of the window in samples.
|
|
116
|
+
* @param {string} name The name of the window function.
|
|
117
|
+
* @param {Object} options Additional options.
|
|
118
|
+
* @param {boolean} [options.periodic=true] Whether the window is periodic or symmetric.
|
|
119
|
+
* @param {number} [options.frame_length=null] The length of the analysis frames in samples.
|
|
120
|
+
* Provide a value for `frame_length` if the window is smaller than the frame length, so that it will be zero-padded.
|
|
121
|
+
* @param {boolean} [options.center=true] Whether to center the window inside the FFT buffer. Only used when `frame_length` is provided.
|
|
122
|
+
* @returns {Float64Array} The window of shape `(window_length,)` or `(frame_length,)`.
|
|
123
|
+
*/
|
|
124
|
+
export function window_function(window_length: number, name: string, { periodic, frame_length, center, }?: {
|
|
125
|
+
periodic?: boolean;
|
|
126
|
+
frame_length?: number;
|
|
127
|
+
center?: boolean;
|
|
128
|
+
}): Float64Array;
|
|
129
|
+
import { Tensor } from './tensor.js';
|
|
130
|
+
//# sourceMappingURL=audio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/utils/audio.js"],"names":[],"mappings":"AAmBA;;;;;GAK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"],"names":[],"mappings":"AACA,6FAA8F"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Core utility functions/classes for Transformers.js.
|
|
3
|
+
*
|
|
4
|
+
* These are only used internally, meaning an end-user shouldn't
|
|
5
|
+
* need to access anything here.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/core
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to dispatch progress callbacks.
|
|
11
|
+
*
|
|
12
|
+
* @param {Function} progress_callback The progress callback function to dispatch.
|
|
13
|
+
* @param {any} data The data to pass to the progress callback function.
|
|
14
|
+
* @returns {void}
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
export function dispatchCallback(progress_callback: Function, data: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Reverses the keys and values of an object.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} data The object to reverse.
|
|
22
|
+
* @returns {Object} The reversed object.
|
|
23
|
+
* @see https://ultimatecourses.com/blog/reverse-object-keys-and-values-in-javascript
|
|
24
|
+
*/
|
|
25
|
+
export function reverseDictionary(data: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* Escapes regular expression special characters from a string by replacing them with their escaped counterparts.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} string The string to escape.
|
|
30
|
+
* @returns {string} The escaped string.
|
|
31
|
+
*/
|
|
32
|
+
export function escapeRegExp(string: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a value is a typed array.
|
|
35
|
+
* @param {*} val The value to check.
|
|
36
|
+
* @returns {boolean} True if the value is a `TypedArray`, false otherwise.
|
|
37
|
+
*
|
|
38
|
+
* Adapted from https://stackoverflow.com/a/71091338/13989043
|
|
39
|
+
*/
|
|
40
|
+
export function isTypedArray(val: any): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a value is an integer.
|
|
43
|
+
* @param {*} x The value to check.
|
|
44
|
+
* @returns {boolean} True if the value is a string, false otherwise.
|
|
45
|
+
*/
|
|
46
|
+
export function isIntegralNumber(x: any): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Calculates the dimensions of a nested array.
|
|
49
|
+
*
|
|
50
|
+
* @param {any[]} arr The nested array to calculate dimensions for.
|
|
51
|
+
* @returns {number[]} An array containing the dimensions of the input array.
|
|
52
|
+
*/
|
|
53
|
+
export function calculateDimensions(arr: any[]): number[];
|
|
54
|
+
/**
|
|
55
|
+
* Replicate python's .pop() method for objects.
|
|
56
|
+
* @param {Object} obj The object to pop from.
|
|
57
|
+
* @param {string} key The key to pop.
|
|
58
|
+
* @param {*} defaultValue The default value to return if the key does not exist.
|
|
59
|
+
* @returns {*} The value of the popped key.
|
|
60
|
+
* @throws {Error} If the key does not exist and no default value is provided.
|
|
61
|
+
*/
|
|
62
|
+
export function pop(obj: any, key: string, defaultValue?: any): any;
|
|
63
|
+
/**
|
|
64
|
+
* Efficiently merge arrays, creating a new copy.
|
|
65
|
+
* Adapted from https://stackoverflow.com/a/6768642/13989043
|
|
66
|
+
* @param {Array[]} arrs Arrays to merge.
|
|
67
|
+
* @returns {Array} The merged array.
|
|
68
|
+
*/
|
|
69
|
+
export function mergeArrays(...arrs: any[][]): any[];
|
|
70
|
+
/**
|
|
71
|
+
* Compute the Cartesian product of given arrays
|
|
72
|
+
* @param {...Array} a Arrays to compute the product
|
|
73
|
+
* @returns {Array} Returns the computed Cartesian product as an array
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
export function product(...a: any[][]): any[];
|
|
77
|
+
/**
|
|
78
|
+
* Calculates the index offset for a given index and window size.
|
|
79
|
+
* @param {number} i The index.
|
|
80
|
+
* @param {number} w The window size.
|
|
81
|
+
* @returns {number} The index offset.
|
|
82
|
+
*/
|
|
83
|
+
export function calculateReflectOffset(i: number, w: number): number;
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param {Object} o
|
|
87
|
+
* @param {string[]} props
|
|
88
|
+
* @returns {Object}
|
|
89
|
+
*/
|
|
90
|
+
export function pick(o: any, props: string[]): any;
|
|
91
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/utils/core.js"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,oEAJW,GAAG,GACD,IAAI,CAKhB;AAED;;;;;;GAMG;AACH,kDAGC;AAED;;;;;GAKG;AACH,qCAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;GAMG;AACH,wCAJa,OAAO,CAMnB;AAGD;;;;GAIG;AACH,0CAFa,OAAO,CAInB;AAED;;;;;GAKG;AACH,yCAHW,GAAG,EAAE,GACH,MAAM,EAAE,CAUpB;AAED;;;;;;;GAOG;AACH,mCALW,MAAM,2BAehB;AAED;;;;;GAKG;AACH,qCAHY,OAAO,SAKlB;AAED;;;;;GAKG;AACH,8CAIC;AAED;;;;;GAKG;AACH,0CAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;GAKG;AACH,oCAHW,MAAM,EAAE,OAYlB"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Custom data structures.
|
|
3
|
+
*
|
|
4
|
+
* These are only used internally, meaning an end-user shouldn't
|
|
5
|
+
* need to access anything here.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/data-structures
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Efficient Heap-based Implementation of a Priority Queue.
|
|
11
|
+
* It uses an array-based binary heap, where the root is at index `0`, and the
|
|
12
|
+
* children of node `i` are located at indices `2i + 1` and `2i + 2`, respectively.
|
|
13
|
+
*
|
|
14
|
+
* Adapted from the following sources:
|
|
15
|
+
* - https://stackoverflow.com/a/42919752/13989043 (original)
|
|
16
|
+
* - https://github.com/belladoreai/llama-tokenizer-js (minor improvements)
|
|
17
|
+
*/
|
|
18
|
+
export class PriorityQueue {
|
|
19
|
+
/**
|
|
20
|
+
* Create a new PriorityQueue.
|
|
21
|
+
* @param {function(any, any): boolean} comparator Comparator function to determine priority. Defaults to a MaxHeap.
|
|
22
|
+
*/
|
|
23
|
+
constructor(comparator?: (arg0: any, arg1: any) => boolean, maxSize?: number);
|
|
24
|
+
_heap: any[];
|
|
25
|
+
_comparator: (arg0: any, arg1: any) => boolean;
|
|
26
|
+
_maxSize: number;
|
|
27
|
+
/**
|
|
28
|
+
* The size of the queue
|
|
29
|
+
*/
|
|
30
|
+
get size(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Check if the queue is empty.
|
|
33
|
+
* @returns {boolean} `true` if the queue is empty, `false` otherwise.
|
|
34
|
+
*/
|
|
35
|
+
isEmpty(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Return the element with the highest priority in the queue.
|
|
38
|
+
* @returns {any} The highest priority element in the queue.
|
|
39
|
+
*/
|
|
40
|
+
peek(): any;
|
|
41
|
+
/**
|
|
42
|
+
* Add one or more elements to the queue.
|
|
43
|
+
* @param {...any} values The values to push into the queue.
|
|
44
|
+
* @returns {number} The new size of the queue.
|
|
45
|
+
*/
|
|
46
|
+
push(...values: any[]): number;
|
|
47
|
+
/**
|
|
48
|
+
* Add multiple elements to the queue.
|
|
49
|
+
* @param {any[]} values The values to push into the queue.
|
|
50
|
+
* @returns {number} The new size of the queue.
|
|
51
|
+
*/
|
|
52
|
+
extend(values: any[]): number;
|
|
53
|
+
/**
|
|
54
|
+
* Remove and return the element with the highest priority in the queue.
|
|
55
|
+
* @returns {any} The element with the highest priority in the queue.
|
|
56
|
+
*/
|
|
57
|
+
pop(): any;
|
|
58
|
+
/**
|
|
59
|
+
* Replace the element with the highest priority in the queue with a new value.
|
|
60
|
+
* @param {*} value The new value.
|
|
61
|
+
* @returns {*} The replaced value.
|
|
62
|
+
*/
|
|
63
|
+
replace(value: any): any;
|
|
64
|
+
/**
|
|
65
|
+
* Compute the index for the parent of the node at index `i`.
|
|
66
|
+
* @param {number} i The index of the node to get the parent of.
|
|
67
|
+
* @returns {number} The index of the parent node.
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
private _parent;
|
|
71
|
+
/**
|
|
72
|
+
* Compute the index for the left child of the node at index `i`.
|
|
73
|
+
* @param {number} i The index of the node to get the left child of.
|
|
74
|
+
* @returns {number} The index of the left child.
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
private _left;
|
|
78
|
+
/**
|
|
79
|
+
* Compute the index for the right child of the node at index `i`.
|
|
80
|
+
* @param {number} i The index of the node to get the right child of.
|
|
81
|
+
* @returns {number} The index of the right child.
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private _right;
|
|
85
|
+
/**
|
|
86
|
+
* Check if the element at index `i` is greater than the element at index `j`.
|
|
87
|
+
* @param {number} i The index of the first element to compare.
|
|
88
|
+
* @param {number} j The index of the second element to compare.
|
|
89
|
+
* @returns {boolean} `true` if the element at index `i` is greater than the element at index `j`, `false` otherwise.
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
private _greater;
|
|
93
|
+
/**
|
|
94
|
+
* Swap the elements at indices `i` and `j`.
|
|
95
|
+
* @param {number} i The index of the first element to swap.
|
|
96
|
+
* @param {number} j The index of the second element to swap.
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
private _swap;
|
|
100
|
+
/**
|
|
101
|
+
* Maintain the heap property by updating positions in the heap,
|
|
102
|
+
* starting at the last element and moving up the heap.
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
private _siftUp;
|
|
106
|
+
/**
|
|
107
|
+
* Helper function to sift up from a given node.
|
|
108
|
+
* @param {number} node The index of the node to start sifting up from.
|
|
109
|
+
*/
|
|
110
|
+
_siftUpFrom(node: number): void;
|
|
111
|
+
/**
|
|
112
|
+
* Maintain the heap property by updating positions in the heap,
|
|
113
|
+
* starting at the first element and moving down the heap.
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
116
|
+
private _siftDown;
|
|
117
|
+
/**
|
|
118
|
+
* Get the index of the smallest element in the heap. Since we use an array-based heap,
|
|
119
|
+
* the index can be computed without needing to traverse the heap.
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
private _smallest;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A trie structure to efficiently store and search for strings.
|
|
126
|
+
*/
|
|
127
|
+
export class CharTrie {
|
|
128
|
+
root: CharTrieNode;
|
|
129
|
+
/**
|
|
130
|
+
* Adds one or more `texts` to the trie.
|
|
131
|
+
* @param {string[]} texts The strings to add to the trie.
|
|
132
|
+
*/
|
|
133
|
+
extend(texts: string[]): void;
|
|
134
|
+
/**
|
|
135
|
+
* Adds text to the trie.
|
|
136
|
+
* @param {string} text The string to add to the trie.
|
|
137
|
+
*/
|
|
138
|
+
push(text: string): void;
|
|
139
|
+
/**
|
|
140
|
+
* Searches the trie for all strings with a common prefix of `text`.
|
|
141
|
+
* @param {string} text The common prefix to search for.
|
|
142
|
+
* @yields {string} Each string in the trie that has `text` as a prefix.
|
|
143
|
+
*/
|
|
144
|
+
commonPrefixSearch(text: string): Generator<string, void, unknown>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* A lattice data structure to be used for tokenization.
|
|
148
|
+
*/
|
|
149
|
+
export class TokenLattice {
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new TokenLattice instance.
|
|
152
|
+
*
|
|
153
|
+
* @param {string} sentence The input sentence to be tokenized.
|
|
154
|
+
* @param {number} bosTokenId The beginning-of-sequence token ID.
|
|
155
|
+
* @param {number} eosTokenId The end-of-sequence token ID.
|
|
156
|
+
*/
|
|
157
|
+
constructor(sentence: string, bosTokenId: number, eosTokenId: number);
|
|
158
|
+
sentence: string;
|
|
159
|
+
len: number;
|
|
160
|
+
bosTokenId: number;
|
|
161
|
+
eosTokenId: number;
|
|
162
|
+
nodes: TokenLatticeNode[];
|
|
163
|
+
beginNodes: any[][];
|
|
164
|
+
endNodes: any[][];
|
|
165
|
+
/**
|
|
166
|
+
* Inserts a new token node into the token lattice.
|
|
167
|
+
*
|
|
168
|
+
* @param {number} pos The starting position of the token.
|
|
169
|
+
* @param {number} length The length of the token.
|
|
170
|
+
* @param {number} score The score of the token.
|
|
171
|
+
* @param {number} tokenId The token ID of the token.
|
|
172
|
+
*/
|
|
173
|
+
insert(pos: number, length: number, score: number, tokenId: number): void;
|
|
174
|
+
/**
|
|
175
|
+
* Implements the Viterbi algorithm to compute the most likely sequence of tokens.
|
|
176
|
+
*
|
|
177
|
+
* @returns {TokenLatticeNode[]} The array of nodes representing the most likely sequence of tokens.
|
|
178
|
+
*/
|
|
179
|
+
viterbi(): TokenLatticeNode[];
|
|
180
|
+
/**
|
|
181
|
+
* @param {TokenLatticeNode} node
|
|
182
|
+
* @returns {string} The array of nodes representing the most likely sequence of tokens.
|
|
183
|
+
*/
|
|
184
|
+
piece(node: TokenLatticeNode): string;
|
|
185
|
+
/**
|
|
186
|
+
* @returns {Array} The array of nodes representing the most likely sequence of tokens.
|
|
187
|
+
*/
|
|
188
|
+
tokens(): any[];
|
|
189
|
+
/**
|
|
190
|
+
* @returns {Array} The array of nodes representing the most likely sequence of tokens.
|
|
191
|
+
*/
|
|
192
|
+
tokenIds(): any[];
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Represents a node in a character trie.
|
|
196
|
+
*/
|
|
197
|
+
declare class CharTrieNode {
|
|
198
|
+
/**
|
|
199
|
+
* Returns a new `CharTrieNode` instance with default values.
|
|
200
|
+
* @returns {CharTrieNode} A new `CharTrieNode` instance with `isLeaf` set to `false` and an empty `children` map.
|
|
201
|
+
*/
|
|
202
|
+
static default(): CharTrieNode;
|
|
203
|
+
/**
|
|
204
|
+
* Create a new CharTrieNode.
|
|
205
|
+
* @param {boolean} isLeaf Whether the node is a leaf node or not.
|
|
206
|
+
* @param {Map<string, CharTrieNode>} children A map containing the node's children, where the key is a character and the value is a `CharTrieNode`.
|
|
207
|
+
*/
|
|
208
|
+
constructor(isLeaf: boolean, children: Map<string, CharTrieNode>);
|
|
209
|
+
isLeaf: boolean;
|
|
210
|
+
children: Map<string, CharTrieNode>;
|
|
211
|
+
}
|
|
212
|
+
declare class TokenLatticeNode {
|
|
213
|
+
/**
|
|
214
|
+
* Represents a node in a token lattice for a given sentence.
|
|
215
|
+
* @param {number} tokenId The ID of the token associated with this node.
|
|
216
|
+
* @param {number} nodeId The ID of this node.
|
|
217
|
+
* @param {number} pos The starting position of the token in the sentence.
|
|
218
|
+
* @param {number} length The length of the token.
|
|
219
|
+
* @param {number} score The score associated with the token.
|
|
220
|
+
*/
|
|
221
|
+
constructor(tokenId: number, nodeId: number, pos: number, length: number, score: number);
|
|
222
|
+
tokenId: number;
|
|
223
|
+
nodeId: number;
|
|
224
|
+
pos: number;
|
|
225
|
+
length: number;
|
|
226
|
+
score: number;
|
|
227
|
+
prev: any;
|
|
228
|
+
backtraceScore: number;
|
|
229
|
+
/**
|
|
230
|
+
* Returns a clone of this node.
|
|
231
|
+
* @returns {TokenLatticeNode} A clone of this node.
|
|
232
|
+
*/
|
|
233
|
+
clone(): TokenLatticeNode;
|
|
234
|
+
}
|
|
235
|
+
export {};
|
|
236
|
+
//# sourceMappingURL=data-structures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-structures.d.ts","sourceRoot":"","sources":["../../src/utils/data-structures.js"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAGH;;;;;;;;GAQG;AACH;IAEI;;;OAGG;IACH,gCAFoB,GAAG,QAAE,GAAG,KAAG,OAAO,oBAMrC;IAHG,aAAe;IACf,oBAJgB,GAAG,QAAE,GAAG,KAAG,OAAO,CAIL;IAC7B,iBAAuB;IAG3B;;OAEG;IACH,mBAEC;IAED;;;OAGG;IACH,WAFa,OAAO,CAInB;IAED;;;OAGG;IACH,QAFa,GAAG,CAIf;IAED;;;;OAIG;IACH,gBAHe,GAAG,KACL,MAAM,CAIlB;IAED;;;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AAoB;IACpB,YAAc;IACd,eAAoB;IACpB,cAAkB;IAClB,UAAgB;IAChB,uBAAyB;IAG7B;;;OAGG;IACH,SAFa,gBAAgB,CAO5B;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../src/utils/devices.js"],"names":[],"mappings":"AACA;;;;;GAKG;yBAGU,MAAM,mBAAmB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function isWebGpuFp16Supported(): Promise<boolean>;
|
|
2
|
+
export const DATA_TYPES: Readonly<{
|
|
3
|
+
fp32: "fp32";
|
|
4
|
+
fp16: "fp16";
|
|
5
|
+
q8: "q8";
|
|
6
|
+
int8: "int8";
|
|
7
|
+
uint8: "uint8";
|
|
8
|
+
q4: "q4";
|
|
9
|
+
bnb4: "bnb4";
|
|
10
|
+
q4f16: "q4f16";
|
|
11
|
+
}>;
|
|
12
|
+
/** @typedef {keyof typeof DATA_TYPES} DataType */
|
|
13
|
+
export const DEFAULT_DEVICE_DTYPE_MAPPING: Readonly<{
|
|
14
|
+
cpu: "q8";
|
|
15
|
+
gpu: "fp32";
|
|
16
|
+
wasm: "q8";
|
|
17
|
+
webgpu: "fp32";
|
|
18
|
+
}>;
|
|
19
|
+
/** @type {Record<DataType, string>} */
|
|
20
|
+
export const DEFAULT_DTYPE_SUFFIX_MAPPING: Record<DataType, string>;
|
|
21
|
+
export type DataType = keyof typeof DATA_TYPES;
|
|
22
|
+
//# sourceMappingURL=dtypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dtypes.d.ts","sourceRoot":"","sources":["../../src/utils/dtypes.js"],"names":[],"mappings":"AAeW,0DAcN;AAGL;;;;;;;;;GASG;AACH,kDAAkD;AAElD;;;;;GAKG;AAEH,uCAAuC;AACvC,2CADW,OAAO,QAAQ,EAAE,MAAM,CAAC,CAUhC;uBAnBW,MAAM,iBAAiB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A base class for creating callable objects.
|
|
3
|
+
* See [here](https://stackoverflow.com/q/76073890) for more information.
|
|
4
|
+
*
|
|
5
|
+
* @type {new () => {(...args: any[]): any, _call(...args: any[]): any}}
|
|
6
|
+
*/
|
|
7
|
+
export const Callable: new () => {
|
|
8
|
+
(...args: any[]): any;
|
|
9
|
+
_call(...args: any[]): any;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/utils/generic.js"],"names":[],"mappings":"AACA;;;;;GAKG;AACH;cAF+B,GAAG,EAAE,GAAG,GAAG;mBAAiB,GAAG,EAAE,GAAG,GAAG;EA6BnE"}
|