Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typegen #28

Merged
merged 92 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
84acd1d
add generated type declaration files
kungfooman Mar 18, 2023
925f80c
changes for type-checking and some JSDoc comments
kungfooman Mar 18, 2023
9009e9c
fix: add jsdoc to utils.js
chelouche9 Mar 18, 2023
79c4049
make ts as dev dep
chelouche9 Mar 19, 2023
542aa09
pr fixes
chelouche9 Mar 20, 2023
ca72d93
add jsdoc for smaples.js
chelouche9 Mar 20, 2023
660440e
add jsdoc for tokenizers.js
chelouche9 Mar 20, 2023
ce7caf3
add jsdoc for tensor_utils.js
chelouche9 Mar 20, 2023
6c302ad
remove @class and @constructor
chelouche9 Mar 20, 2023
1565938
Update src/tensor_utils.js
xenova Mar 21, 2023
90d4663
add jsdoc for tensor_generation.js
chelouche9 Mar 21, 2023
cb95db3
add jsdoc for fft.js
chelouche9 Mar 21, 2023
0644cb8
add jsdoc for pipelines.js
chelouche9 Mar 22, 2023
8a4791c
add jsdoc for processors.js
chelouche9 Mar 22, 2023
13677bd
add jsdoc for models.js
chelouche9 Mar 23, 2023
54b1c80
Update src/processors.js
chelouche9 Mar 27, 2023
ff3689e
Export image type from image_utils.js
xenova Mar 30, 2023
6f34126
Fix `ReferenceError` in `fram_wave`
xenova Mar 30, 2023
aff87ba
Add JSDoc for `ForcedEOSTokenLogitsProcessor`
xenova Mar 30, 2023
46376c0
Do not add `ForcedEOSTokenLogitsProcessor` when creating logits proce…
xenova Mar 30, 2023
9eec14f
Add default value for `options.topk` call parameter
xenova Mar 30, 2023
6561328
Reference WhisperTokenizer's LANGUAGE property directly
xenova Mar 30, 2023
3a7508a
Fix indentation for utils.js
xenova Mar 30, 2023
2599813
Update logits processor type
xenova Mar 30, 2023
a424dfc
Update types for tokenizers.js
xenova Mar 30, 2023
faec5c6
Remove `T5ForConditionalGeneration` import/export
xenova Mar 30, 2023
5ba434b
Use Tensor for type of logits
xenova Mar 30, 2023
c74d596
Add guard before assigning `this.generation_config` to `gen_config`
xenova Mar 30, 2023
d39d1da
Update JSDoc for pipelines.js
xenova Mar 30, 2023
9711d95
Use for loop instead of for...in
xenova Mar 30, 2023
328443b
Update package-lock.json
xenova Mar 30, 2023
6932731
fix remaining errors
chelouche9 Apr 2, 2023
2708fbf
fix pr
chelouche9 Apr 2, 2023
e0ee214
fix pr
chelouche9 Apr 2, 2023
92fb142
fix
chelouche9 Apr 3, 2023
d25ee88
fix
chelouche9 Apr 3, 2023
5ed82e6
fix
chelouche9 Apr 3, 2023
09d39d8
fix
chelouche9 Apr 3, 2023
dcad0a0
Update src/fft.js
chelouche9 Apr 3, 2023
cca4620
Update src/pipelines.js
chelouche9 Apr 3, 2023
3840b48
pr fixes
chelouche9 Apr 3, 2023
44693cd
pr fixes 2
chelouche9 Apr 3, 2023
9ffaf4b
Update src/pipelines.js
chelouche9 Apr 4, 2023
69b8360
Update src/pipelines.js
chelouche9 Apr 4, 2023
817c3e9
Update src/pipelines.js
chelouche9 Apr 4, 2023
ddfe9ee
Update src/pipelines.js
chelouche9 Apr 4, 2023
f98ac17
Update src/pipelines.js
chelouche9 Apr 4, 2023
84982e3
Update src/pipelines.js
chelouche9 Apr 4, 2023
95fe43d
Update src/pipelines.js
chelouche9 Apr 4, 2023
00b563e
Update src/processors.js
chelouche9 Apr 4, 2023
6558445
Update src/tensor_utils.js
chelouche9 Apr 4, 2023
94adadb
Update src/tokenizers.js
chelouche9 Apr 4, 2023
c41283e
Update src/tokenizers.js
chelouche9 Apr 4, 2023
17f16d1
Update src/tokenizers.js
chelouche9 Apr 4, 2023
a9eea47
Merge branch 'main' into pr/28
xenova Apr 4, 2023
f2baaf9
Fix typo
xenova Apr 4, 2023
9614883
Update TODO comment
xenova Apr 4, 2023
dca9597
Add `@ts-ignore` to certain imports
xenova Apr 4, 2023
ba064ff
Update fft comments
xenova Apr 4, 2023
8b255c2
Add JSDoc for `NoRepeatNGramLogitsProcessor`
xenova Apr 4, 2023
3665217
Update `NoRepeatNGramLogitsProcessor` JSDoc
xenova Apr 4, 2023
c3ab104
Add JSDoc for `RepetitionPenaltyLogitsProcessor`
xenova Apr 4, 2023
715565b
Update `image_utils.js` comments
xenova Apr 4, 2023
21b5cdf
Fix typo
xenova Apr 4, 2023
be9364e
Do not set encoder-decoder properties to undefined
xenova Apr 4, 2023
e34eac1
Update model constructor JSDocs
xenova Apr 4, 2023
15157a1
Reference WhisperTokenizer's LANGUAGE property directly
xenova Apr 4, 2023
8c2a7cc
Update types for tokenizers.js
xenova Apr 4, 2023
5f0d592
Remove `T5ForConditionalGeneration` import/export
xenova Apr 4, 2023
7269c82
Add guard before assigning `this.generation_config` to `gen_config`
xenova Apr 4, 2023
3cc7665
Refactor Question Answering pipeline call function
xenova Apr 4, 2023
deff2ea
Use for loop instead of for...in
xenova Apr 4, 2023
5fc819e
Fix `FileResponse` clone method
xenova Apr 4, 2023
18bc7d6
Call `super()` in `Callable` constructor
xenova Apr 4, 2023
93fb872
Reorder JSDoc
xenova Apr 4, 2023
ef0093d
Update `Callable` JSDoc
xenova Apr 4, 2023
362a489
Ignore `_call` warning on closure
xenova Apr 4, 2023
74921cf
Remove `tokenizer.batch_decode` from JSDoc
xenova Apr 4, 2023
0b9ace8
Add `cleanup` property to word piece decoders
xenova Apr 4, 2023
2576c32
Allow attention mask to be array or Tensor
xenova Apr 4, 2023
e4cb674
Add JSDoc for tokenizers.js
xenova Apr 4, 2023
8c605b4
Throw an error if `text_pair` is not the same type as `text` (when sp…
xenova Apr 4, 2023
7aab9aa
Make `NoRepeatNGramLogitsProcessor` helper functions part of the class
xenova Apr 4, 2023
996b6e1
Add JSDocs for `NoRepeatNGramLogitsProcessor`
xenova Apr 4, 2023
b102a10
Add JSDoc for `LogitsProcessorList` constructor
xenova Apr 4, 2023
5f25ed2
Add JSDoc for `BartForSequenceClassification`
xenova Apr 4, 2023
060ca3d
Update model constructor JSDocs
xenova Apr 4, 2023
94d7b62
Update `PreTrainedModel` constructor JSDocs
xenova Apr 4, 2023
8d19f15
Remove old comment
xenova Apr 4, 2023
216eb54
Allow construction of AutoModel for marian models
xenova Apr 4, 2023
9211158
Remove duplicated comments
xenova Apr 4, 2023
6c41fc0
Update JSDocs
xenova Apr 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dist/types/backends/onnx.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export let ONNX: any;
export const executionProviders: string[];
12 changes: 12 additions & 0 deletions dist/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export namespace env {
export { onnx_env as onnx };
export const remoteModels: boolean;
export const remoteURL: string;
export { localURL };
export { CACHE_AVAILABLE as useCache };
export { FS_AVAILABLE as useFS };
}
declare const localURL: string;
declare const CACHE_AVAILABLE: boolean;
declare const FS_AVAILABLE: boolean;
export {};
140 changes: 140 additions & 0 deletions dist/types/fft.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
export = FFT;
/**
* FFT class provides functionality for performing Fast Fourier Transform on arrays
*/
declare class FFT {
/**
* @param {number} size - The size of the input array. Must be a power of two and bigger than 1.
* @throws {Error} FFT size must be a power of two and bigger than 1.
*/
constructor(size: number);
size: number;
_csize: number;
table: Float64Array;
_width: number;
_bitrev: Int32Array;
/**
* Create a complex number array with size `2 * size`
*
* @returns {Float64Array} - A complex number array with size `2 * size`
*/
createComplexArray(): Float64Array;
/**
* Converts a complex number representation stored in a Float64Array to an array of real numbers.
*
* @param {Float64Array} complex - The complex number representation to be converted.
* @param {number[]} [storage] - An optional array to store the result in.
* @returns {number[]} An array of real numbers representing the input complex number representation.
*/
fromComplexArray(complex: Float64Array, storage?: number[]): number[];
/**
* Convert a real-valued input array to a complex-valued output array.
* @param {Float64Array} input - The real-valued input array.
* @param {Float64Array} [storage] - Optional buffer to store the output array.
* @returns {Float64Array} The complex-valued output array.
*/
toComplexArray(input: Float64Array, storage?: Float64Array): Float64Array;
/**
* Completes the spectrum by adding its mirrored negative frequency components.
* @param {Float64Array} spectrum - The input spectrum.
* @returns {void}
*/
completeSpectrum(spectrum: Float64Array): void;
/**
* Performs a Fast Fourier Transform (FFT) on the given input data and stores the result in the output buffer.
*
* @param {Float64Array} out - The output buffer to store the result.
* @param {Float64Array} data - The input data to transform.
*
* @throws {Error} Input and output buffers must be different.
*
* @returns {void}
*/
transform(out: Float64Array, data: Float64Array): void;
/**
* Performs a real-valued forward FFT on the given input buffer and stores the result in the given output buffer.
* The input buffer must contain real values only, while the output buffer will contain complex values. The input and
* output buffers must be different.
*
* @param {Float64Array} out - The output buffer.
* @param {Float64Array} data - The input buffer containing real values.
*
* @throws {Error} If the input and output buffers are the same.
*/
realTransform(out: Float64Array, data: Float64Array): void;
/**
* Performs an inverse FFT transformation on the given `data` array, and stores the result in `out`.
* The `out` array must be a different buffer than the `data` array. The `out` array will contain the
* result of the transformation. The `data` array will not be modified.
*
* @param {Float64Array} out - The output buffer for the transformed data.
* @param {Float64Array} data - The input data to transform.
* @throws {Error} If `out` and `data` refer to the same buffer.
* @returns {void}
*/
inverseTransform(out: Float64Array, data: Float64Array): void;
/**
* Performs a radix-4 implementation of a discrete Fourier transform on a given set of data.
*
* @param {Float64Array} out - The output buffer for the transformed data.
* @param {Float64Array} data - The input buffer of data to be transformed.
* @param {number} inv - A scaling factor to apply to the transform.
* @returns {void}
*/
_transform4(out: Float64Array, data: Float64Array, inv: number): void;
/**
* Performs a radix-2 implementation of a discrete Fourier transform on a given set of data.
*
* @param {Float64Array} data - The input buffer of data to be transformed.
* @param {Float64Array} out - The output buffer for the transformed data.
* @param {number} outOff - The offset at which to write the output data.
* @param {number} off - The offset at which to begin reading the input data.
* @param {number} step - The step size for indexing the input data.
* @returns {void}
*/
_singleTransform2(data: Float64Array, out: Float64Array, outOff: number, off: number, step: number): void;
/**
* Performs radix-4 transformation on input data of length 8
*
* @param {Float64Array} data - Input data array of length 8
* @param {Float64Array} out - Output data array of length 8
* @param {number} outOff - Index of output array to start writing from
* @param {number} off - Index of input array to start reading from
* @param {number} step - Step size between elements in input array
* @param {number} inv - Scaling factor for inverse transform
*
* @returns {void}
*/
_singleTransform4(data: Float64Array, out: Float64Array, outOff: number, off: number, step: number, inv: number): void;
/**
* Real input radix-4 implementation
* @param {Float64Array} out - Output array for the transformed data
* @param {Float64Array} data - Input array of real data to be transformed
* @param {number} inv - The scale factor used to normalize the inverse transform
*/
_realTransform4(out: Float64Array, data: Float64Array, inv: number): void;
/**
* Performs a single real input radix-2 transformation on the provided data
*
* @param {Float64Array} data - The input data array
* @param {Float64Array} out - The output data array
* @param {number} outOff - The output offset
* @param {number} off - The input offset
* @param {number} step - The step
*
* @returns {void}
*/
_singleRealTransform2(data: Float64Array, out: Float64Array, outOff: number, off: number, step: number): void;
/**
* Computes a single real-valued transform using radix-4 algorithm.
* This method is only called for len=8.
*
* @param {Float64Array} data - The input data array.
* @param {Float64Array} out - The output data array.
* @param {number} outOff - The offset into the output array.
* @param {number} off - The offset into the input array.
* @param {number} step - The step size for the input array.
* @param {number} inv - The value of inverse.
*/
_singleRealTransform4(data: Float64Array, out: Float64Array, outOff: number, off: number, step: number, inv: number): void;
}
233 changes: 233 additions & 0 deletions dist/types/generation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/**
* Base class for processing logits.
* @extends Callable
*/
export class LogitsProcessor extends Callable {
/**
* Apply the processor to the input logits.
*
* @abstract
* @param {Array} input_ids The input ids.
* @param {Tensor} logits The logits to process.
* @throws {Error} Throws an error if `_call` is not implemented in the subclass.
*/
_call(input_ids: any[], logits: Tensor): void;
}
/**
* A class representing a list of logits processors. A logits processor is a function that modifies the logits
* output of a language model. This class provides methods for adding new processors and applying all processors to a
* batch of logits.
*
* @extends Callable
*/
export class LogitsProcessorList extends Callable {
processors: any[];
/**
* Adds a new logits processor to the list.
*
* @param {function} item - The logits processor function to add.
*/
push(item: Function): void;
/**
* Adds multiple logits processors to the list.
*
* @param {function[]} items - The logits processor functions to add.
*/
extend(items: Function[]): void;
/**
* Applies all logits processors in the list to a batch of logits, modifying them in-place.
*
* @param {number[]} input_ids - The input IDs for the language model.
* @param {number[][]} batchedLogits - A 2D array of logits, where each row corresponds to a single
* input sequence in the batch.
*/
_call(input_ids: number[], batchedLogits: number[][]): void;
[Symbol.iterator](): IterableIterator<any>;
}
export class GenerationConfig {
constructor(kwargs?: {});
/**
* Create a GenerationConfig object
* @constructor
* @param {Object} [kwargs={}] - The configuration parameters
* @param {number} [kwargs.max_length=20] - The maximum length of the generated text
* @param {number} [kwargs.max_new_tokens=null] - The maximum number of new tokens to generate
* @param {number} [kwargs.min_length=0] - The minimum length of the generated text
* @param {number} [kwargs.min_new_tokens=null] - The minimum number of new tokens to generate
* @param {boolean} [kwargs.early_stopping=false] - Whether to stop generation early if a stop token is encountered
* @param {number} [kwargs.max_time=null] - The maximum amount of time to spend generating text
* @param {boolean} [kwargs.do_sample=false] - Whether to use sampling when generating text
* @param {number} [kwargs.num_beams=1] - The number of beams to use when generating text
* @param {number} [kwargs.num_beam_groups=1] - The number of beam groups to use when generating text
* @param {number} [kwargs.penalty_alpha=null] - The value of the alpha penalty to use when generating text
* @param {boolean} [kwargs.use_cache=true] - Whether to use cache when generating text
* @param {number} [kwargs.temperature=1.0] - The temperature to use when generating text
* @param {number} [kwargs.top_k=50] - The value of k to use when generating text
* @param {number} [kwargs.top_p=1.0] - The value of p to use when generating text
* @param {number} [kwargs.typical_p=1.0] - The typical value of p to use when generating text
* @param {number} [kwargs.epsilon_cutoff=0.0] - The value of epsilon cutoff to use when generating text
* @param {number} [kwargs.eta_cutoff=0.0] - The value of eta cutoff to use when generating text
* @param {number} [kwargs.diversity_penalty=0.0] - The value of diversity penalty to use when generating text
* @param {number} [kwargs.repetition_penalty=1.0] - The value of repetition penalty to use when generating text
* @param {number} [kwargs.encoder_repetition_penalty=1.0] - The value of encoder repetition penalty to use when generating text
* @param {number} [kwargs.length_penalty=1.0] - The value of length
* @param {number} [kwargs.no_repeat_ngram_size=0] - The size of the n-grams to avoid repeating in the generated output.
* @param {?number[]} [kwargs.bad_words_ids=null] - An array of IDs representing tokens that should not be generated.
* @param {?number[]} [kwargs.force_words_ids=null] - An array of IDs representing tokens that must be generated.
* @param {boolean} [kwargs.renormalize_logits=false] - Whether or not to renormalize the logits before generating new tokens.
* @param {?Object[]} [kwargs.constraints=null] - An array of constraint objects to apply during generation.
*/
max_length: any;
max_new_tokens: any;
min_length: any;
min_new_tokens: any;
early_stopping: any;
max_time: any;
do_sample: any;
num_beams: any;
num_beam_groups: any;
penalty_alpha: any;
use_cache: any;
temperature: any;
top_k: any;
top_p: any;
typical_p: any;
epsilon_cutoff: any;
eta_cutoff: any;
diversity_penalty: any;
repetition_penalty: any;
encoder_repetition_penalty: any;
length_penalty: any;
no_repeat_ngram_size: any;
bad_words_ids: any;
force_words_ids: any;
renormalize_logits: any;
constraints: any;
forced_bos_token_id: any;
forced_eos_token_id: any;
remove_invalid_values: any;
exponential_decay_length_penalty: any;
suppress_tokens: any;
begin_suppress_tokens: any;
forced_decoder_ids: any;
num_return_sequences: any;
output_attentions: any;
output_hidden_states: any;
output_scores: any;
return_dict_in_generate: any;
pad_token_id: any;
bos_token_id: any;
eos_token_id: any;
encoder_no_repeat_ngram_size: any;
decoder_start_token_id: any;
generation_kwargs: any;
}
/**
* A LogitsProcessor that forces a BOS token at the beginning of the generated sequence.
* @extends LogitsProcessor
*/
export class ForcedBOSTokenLogitsProcessor extends LogitsProcessor {
/**
* Create a ForcedBOSTokenLogitsProcessor.
* @param {number} bos_token_id - The ID of the beginning-of-sequence token to be forced.
*/
constructor(bos_token_id: number);
bos_token_id: number;
/**
* Apply the BOS token forcing to the logits.
* @param {Array} input_ids - The input IDs.
* @param {Object} logits - The logits.
* @returns {Object} The logits with BOS token forcing.
*/
_call(input_ids: any[], logits: any): any;
}
/**
* A logits processor that forces end-of-sequence token probability to 1.
*
* @extends LogitsProcessor
*/
export class ForcedEOSTokenLogitsProcessor extends LogitsProcessor {
/**
* Create a ForcedEOSTokenLogitsProcessor.
* @param {number} max_length - Max length of the sequence.
* @param {number} forced_eos_token_id - The ID of the end-of-sequence token to be forced.
*/
constructor(max_length: number, forced_eos_token_id: number);
max_length: number;
forced_eos_token_id: number;
/**
* Apply the processor to input_ids and logits.
*
* @param {number[]} input_ids - The input ids.
* @param {any} logits - The logits tensor.
*/
_call(input_ids: number[], logits: any): void;
}
/**
* A LogitsProcessor that handles adding timestamps to generated text.
* @extends LogitsProcessor
*/
export class WhisperTimeStampLogitsProcessor extends LogitsProcessor {
/**
* Constructs a new WhisperTimeStampLogitsProcessor.
* @param {object} generate_config - The config object passed to the `generate()` method of a transformer model.
* @param {number} generate_config.eos_token_id - The ID of the end-of-sequence token.
* @param {number} generate_config.no_timestamps_token_id - The ID of the token used to indicate that a token should not have a timestamp.
* @param {number[][]} [generate_config.forced_decoder_ids] - An array of two-element arrays representing decoder IDs that are forced to appear in the output. The second element of each array indicates whether the token is a timestamp.
* @param {number} [generate_config.max_initial_timestamp_index] - The maximum index at which an initial timestamp can appear.
*/
constructor(generate_config: {
eos_token_id: number;
no_timestamps_token_id: number;
forced_decoder_ids?: number[][];
max_initial_timestamp_index?: number;
});
eos_token_id: number;
no_timestamps_token_id: number;
timestamp_begin: number;
begin_index: number;
max_initial_timestamp_index: number;
/**
* Modify the logits to handle timestamp tokens.
* @param {Array} input_ids - The input sequence of tokens.
* @param {Tensor} logits - The logits output by the model.
* @returns {Tensor} - The modified logits.
*/
_call(input_ids: any[], logits: Tensor): Tensor;
}
/**
* A logits processor that forces a specific token to be generated by the decoder.
*
* @extends LogitsProcessor
*/
export class ForceTokensLogitsProcessor extends LogitsProcessor {
/**
* Constructs a new instance of `ForceTokensLogitsProcessor`.
*
* @param {Array} forced_decoder_ids The ids of tokens that should be forced.
*/
constructor(forced_decoder_ids: any[]);
force_token_map: {
[k: string]: any;
};
/**
* Apply the processor to the input logits.
*
* @param {Array} input_ids The input ids.
* @param {any} logits The logits to process.
* @returns {Array} The processed logits.
*/
_call(input_ids: any[], logits: any): any[];
}
export class NoRepeatNGramLogitsProcessor extends LogitsProcessor {
constructor(no_repeat_ngram_size: any);
no_repeat_ngram_size: any;
_call(input_ids: any, logits: any): any;
}
export class RepetitionPenaltyLogitsProcessor extends LogitsProcessor {
constructor(penalty: any);
penalty: any;
_call(input_ids: any, logits: any): any;
}
import { Callable } from "./utils.js";
import { Tensor } from "./tensor_utils.js";
8 changes: 8 additions & 0 deletions dist/types/image_utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
*
* @param {string} url
* @returns {Promise<any>}
*/
export function loadImage(url: string): Promise<any>;
export const Jimp: any;
export const ImageType: any;
Loading