@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,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map a device to the execution providers to use for the given device.
|
|
3
|
+
* @param {import("../utils/devices.js").DeviceType} [device=null] (Optional) The device to run the inference on.
|
|
4
|
+
* @returns {import("../utils/devices.js").DeviceType[]} The execution providers to use for the given device.
|
|
5
|
+
*/
|
|
6
|
+
export function deviceToExecutionProviders(device?: import("../utils/devices.js").DeviceType): import("../utils/devices.js").DeviceType[];
|
|
7
|
+
/**
|
|
8
|
+
* Create an ONNX inference session.
|
|
9
|
+
* @param {Uint8Array} buffer The ONNX model buffer.
|
|
10
|
+
* @param {Object} session_options ONNX inference session options.
|
|
11
|
+
* @returns {Promise<import('onnxruntime-common').InferenceSession>} The ONNX inference session.
|
|
12
|
+
*/
|
|
13
|
+
export function createInferenceSession(buffer: Uint8Array, session_options: any): Promise<import('onnxruntime-common').InferenceSession>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if an object is an ONNX tensor.
|
|
16
|
+
* @param {any} x The object to check
|
|
17
|
+
* @returns {boolean} Whether the object is an ONNX tensor.
|
|
18
|
+
*/
|
|
19
|
+
export function isONNXTensor(x: any): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if ONNX's WASM backend is being proxied.
|
|
22
|
+
* @returns {boolean} Whether ONNX's WASM backend is being proxied.
|
|
23
|
+
*/
|
|
24
|
+
export function isONNXProxy(): boolean;
|
|
25
|
+
export { Tensor } from "onnxruntime-common";
|
|
26
|
+
//# sourceMappingURL=onnx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx.d.ts","sourceRoot":"","sources":["../../src/backends/onnx.js"],"names":[],"mappings":"AAiDA;;;;GAIG;AACH,oDAHW,OAAO,qBAAqB,EAAE,UAAU,GACtC,OAAO,qBAAqB,EAAE,UAAU,EAAE,CAYtD;AAWD;;;;;GAKG;AACH,+CAJW,UAAU,yBAER,QAAQ,OAAO,oBAAoB,EAAE,gBAAgB,CAAC,CAYlE;AAED;;;;GAIG;AACH,gCAHW,GAAG,GACD,OAAO,CAInB;AAwCD;;;GAGG;AACH,+BAFa,OAAO,CAKnB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {PretrainedConfig} config
|
|
4
|
+
* @returns {Record<string, number[]>}
|
|
5
|
+
*/
|
|
6
|
+
export function getKeyValueShapes(config: PretrainedConfig, { prefix, }?: {
|
|
7
|
+
prefix?: string;
|
|
8
|
+
}): Record<string, number[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Base class for all configuration classes. For more information, see the corresponding
|
|
11
|
+
* [Python documentation](https://huggingface.co/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig).
|
|
12
|
+
*/
|
|
13
|
+
export class PretrainedConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Loads a pre-trained config from the given `pretrained_model_name_or_path`.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} pretrained_model_name_or_path The path to the pre-trained config.
|
|
18
|
+
* @param {PretrainedOptions} options Additional options for loading the config.
|
|
19
|
+
* @throws {Error} Throws an error if the config.json is not found in the `pretrained_model_name_or_path`.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Promise<PretrainedConfig>} A new instance of the `PretrainedConfig` class.
|
|
22
|
+
*/
|
|
23
|
+
static from_pretrained(pretrained_model_name_or_path: string, { progress_callback, config, cache_dir, local_files_only, revision, }?: PretrainedOptions): Promise<PretrainedConfig>;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new PreTrainedTokenizer instance.
|
|
26
|
+
* @param {Object} configJSON The JSON of the config.
|
|
27
|
+
*/
|
|
28
|
+
constructor(configJSON: any);
|
|
29
|
+
max_position_embeddings: any;
|
|
30
|
+
model_type: any;
|
|
31
|
+
is_encoder_decoder: boolean;
|
|
32
|
+
normalized_config: any;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Helper class which is used to instantiate pretrained configs with the `from_pretrained` function.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const config = await AutoConfig.from_pretrained('Xenova/bert-base-uncased');
|
|
39
|
+
*/
|
|
40
|
+
export class AutoConfig {
|
|
41
|
+
/**
|
|
42
|
+
* Loads a pre-trained config from the given `pretrained_model_name_or_path`.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} pretrained_model_name_or_path The path to the pre-trained config.
|
|
45
|
+
* @param {PretrainedOptions} options Additional options for loading the config.
|
|
46
|
+
* @throws {Error} Throws an error if the config.json is not found in the `pretrained_model_name_or_path`.
|
|
47
|
+
*
|
|
48
|
+
* @returns {Promise<PretrainedConfig>} A new instance of the `PretrainedConfig` class.
|
|
49
|
+
*/
|
|
50
|
+
static from_pretrained(pretrained_model_name_or_path: string, { progress_callback, config, cache_dir, local_files_only, revision, }?: import("./utils/hub.js").PretrainedOptions): Promise<PretrainedConfig>;
|
|
51
|
+
}
|
|
52
|
+
export type PretrainedOptions = import('./utils/hub.js').PretrainedOptions;
|
|
53
|
+
/**
|
|
54
|
+
* Transformers.js-specific configuration, possibly present in config.json under the key `transformers.js_config`.
|
|
55
|
+
*/
|
|
56
|
+
export type TransformersJSConfig = {
|
|
57
|
+
kv_cache_dtype?: import('./transformers.js').DataType;
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=configs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../src/configs.js"],"names":[],"mappings":"AAiNA;;;;GAIG;AACH,0CAHW,gBAAgB;;IACd,OAAO,MAAM,EAAE,MAAM,EAAE,CAAC,CA6EpC;AACD;;;GAGG;AACH;IAiBI;;;;;;;;OAQG;IACH,sDANW,MAAM,0EACN,iBAAiB,GAGf,QAAQ,gBAAgB,CAAC,CAqBrC;IAxCD;;;OAGG;IACH,6BAMC;IAZD,6BAAwB;IAOpB,gBAAsB;IACtB,4BAA+B;IAG/B,uBAAkD;CAgCzD;AAED;;;;;GAKG;AACH;IArCI;;;;;;;;OAQG;IACH,6MAmBC;CAcJ;gCA9TY,OAAO,gBAAgB,EAAE,iBAAiB;;;;;qBAmUzC,OAAO,mBAAmB,EAAE,QAAQ"}
|
package/types/env.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A read-only object containing information about the APIs available in the current environment.
|
|
3
|
+
*/
|
|
4
|
+
export const apis: Readonly<{
|
|
5
|
+
/** Whether we are running in a browser environment */
|
|
6
|
+
IS_BROWSER_ENV: boolean;
|
|
7
|
+
/** Whether we are running in a web worker environment */
|
|
8
|
+
IS_WEBWORKER_ENV: boolean;
|
|
9
|
+
/** Whether the Cache API is available */
|
|
10
|
+
IS_WEB_CACHE_AVAILABLE: boolean;
|
|
11
|
+
/** Whether the WebGPU API is available */
|
|
12
|
+
IS_WEBGPU_AVAILABLE: boolean;
|
|
13
|
+
/** Whether the Node.js process API is available */
|
|
14
|
+
IS_PROCESS_AVAILABLE: boolean;
|
|
15
|
+
/** Whether we are running in a Node.js environment */
|
|
16
|
+
IS_NODE_ENV: boolean;
|
|
17
|
+
/** Whether the filesystem API is available */
|
|
18
|
+
IS_FS_AVAILABLE: boolean;
|
|
19
|
+
/** Whether the path API is available */
|
|
20
|
+
IS_PATH_AVAILABLE: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Global variable given visible to users to control execution. This provides users a simple way to configure Transformers.js.
|
|
24
|
+
* @typedef {Object} TransformersEnvironment
|
|
25
|
+
* @property {string} version This version of Transformers.js.
|
|
26
|
+
* @property {Object} backends Expose environment variables of different backends,
|
|
27
|
+
* allowing users to set these variables if they want to.
|
|
28
|
+
* @property {boolean} allowRemoteModels Whether to allow loading of remote files, defaults to `true`.
|
|
29
|
+
* If set to `false`, it will have the same effect as setting `local_files_only=true` when loading pipelines, models, tokenizers, processors, etc.
|
|
30
|
+
* @property {string} remoteHost Host URL to load models from. Defaults to the Hugging Face Hub.
|
|
31
|
+
* @property {string} remotePathTemplate Path template to fill in and append to `remoteHost` when loading models.
|
|
32
|
+
* @property {boolean} allowLocalModels Whether to allow loading of local files, defaults to `false` if running in-browser, and `true` otherwise.
|
|
33
|
+
* If set to `false`, it will skip the local file check and try to load the model from the remote host.
|
|
34
|
+
* @property {string} localModelPath Path to load local models from. Defaults to `/models/`.
|
|
35
|
+
* @property {boolean} useFS Whether to use the file system to load files. By default, it is `true` if available.
|
|
36
|
+
* @property {boolean} useBrowserCache Whether to use Cache API to cache models. By default, it is `true` if available.
|
|
37
|
+
* @property {boolean} useFSCache Whether to use the file system to cache files. By default, it is `true` if available.
|
|
38
|
+
* @property {string} cacheDir The directory to use for caching files with the file system. By default, it is `./.cache`.
|
|
39
|
+
* @property {boolean} useCustomCache Whether to use a custom cache system (defined by `customCache`), defaults to `false`.
|
|
40
|
+
* @property {Object} customCache The custom cache to use. Defaults to `null`. Note: this must be an object which
|
|
41
|
+
* implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache
|
|
42
|
+
*/
|
|
43
|
+
/** @type {TransformersEnvironment} */
|
|
44
|
+
export const env: TransformersEnvironment;
|
|
45
|
+
/**
|
|
46
|
+
* Global variable given visible to users to control execution. This provides users a simple way to configure Transformers.js.
|
|
47
|
+
*/
|
|
48
|
+
export type TransformersEnvironment = {
|
|
49
|
+
/**
|
|
50
|
+
* This version of Transformers.js.
|
|
51
|
+
*/
|
|
52
|
+
version: string;
|
|
53
|
+
/**
|
|
54
|
+
* Expose environment variables of different backends,
|
|
55
|
+
* allowing users to set these variables if they want to.
|
|
56
|
+
*/
|
|
57
|
+
backends: any;
|
|
58
|
+
/**
|
|
59
|
+
* Whether to allow loading of remote files, defaults to `true`.
|
|
60
|
+
* If set to `false`, it will have the same effect as setting `local_files_only=true` when loading pipelines, models, tokenizers, processors, etc.
|
|
61
|
+
*/
|
|
62
|
+
allowRemoteModels: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Host URL to load models from. Defaults to the Hugging Face Hub.
|
|
65
|
+
*/
|
|
66
|
+
remoteHost: string;
|
|
67
|
+
/**
|
|
68
|
+
* Path template to fill in and append to `remoteHost` when loading models.
|
|
69
|
+
*/
|
|
70
|
+
remotePathTemplate: string;
|
|
71
|
+
/**
|
|
72
|
+
* Whether to allow loading of local files, defaults to `false` if running in-browser, and `true` otherwise.
|
|
73
|
+
* If set to `false`, it will skip the local file check and try to load the model from the remote host.
|
|
74
|
+
*/
|
|
75
|
+
allowLocalModels: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Path to load local models from. Defaults to `/models/`.
|
|
78
|
+
*/
|
|
79
|
+
localModelPath: string;
|
|
80
|
+
/**
|
|
81
|
+
* Whether to use the file system to load files. By default, it is `true` if available.
|
|
82
|
+
*/
|
|
83
|
+
useFS: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Whether to use Cache API to cache models. By default, it is `true` if available.
|
|
86
|
+
*/
|
|
87
|
+
useBrowserCache: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Whether to use the file system to cache files. By default, it is `true` if available.
|
|
90
|
+
*/
|
|
91
|
+
useFSCache: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* The directory to use for caching files with the file system. By default, it is `./.cache`.
|
|
94
|
+
*/
|
|
95
|
+
cacheDir: string;
|
|
96
|
+
/**
|
|
97
|
+
* Whether to use a custom cache system (defined by `customCache`), defaults to `false`.
|
|
98
|
+
*/
|
|
99
|
+
useCustomCache: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* The custom cache to use. Defaults to `null`. Note: this must be an object which
|
|
102
|
+
* implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache
|
|
103
|
+
*/
|
|
104
|
+
customCache: any;
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.js"],"names":[],"mappings":"AAyCA;;GAEG;AACH;IACI,sDAAsD;;IAGtD,yDAAyD;;IAGzD,yCAAyC;;IAGzC,0CAA0C;;IAG1C,mDAAmD;;IAGnD,sDAAsD;;IAGtD,8CAA8C;;IAG9C,wCAAwC;;GAEzC;AAkBH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,sCAAsC;AACtC,kBADW,uBAAuB,CAiCjC;;;;;;;;aApDa,MAAM;;;;;;;;;;uBAGN,OAAO;;;;gBAEP,MAAM;;;;wBACN,MAAM;;;;;sBACN,OAAO;;;;oBAEP,MAAM;;;;WACN,OAAO;;;;qBACP,OAAO;;;;gBACP,OAAO;;;;cACP,MAAM;;;;oBACN,OAAO"}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class that holds a configuration for a generation task.
|
|
3
|
+
*/
|
|
4
|
+
export class GenerationConfig {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {GenerationConfig|import('../configs.js').PretrainedConfig} config
|
|
8
|
+
*/
|
|
9
|
+
constructor(config: GenerationConfig | import('../configs.js').PretrainedConfig);
|
|
10
|
+
/**
|
|
11
|
+
* The maximum length the generated tokens can have.
|
|
12
|
+
* Corresponds to the length of the input prompt + `max_new_tokens`.
|
|
13
|
+
* Its effect is overridden by `max_new_tokens`, if also set.
|
|
14
|
+
* @type {number}
|
|
15
|
+
* @default 20
|
|
16
|
+
*/
|
|
17
|
+
max_length: number;
|
|
18
|
+
/**
|
|
19
|
+
* The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt.
|
|
20
|
+
* @type {number}
|
|
21
|
+
* @default null
|
|
22
|
+
*/
|
|
23
|
+
max_new_tokens: number;
|
|
24
|
+
/**
|
|
25
|
+
* The minimum length of the sequence to be generated.
|
|
26
|
+
* Corresponds to the length of the input prompt + `min_new_tokens`.
|
|
27
|
+
* Its effect is overridden by `min_new_tokens`, if also set.
|
|
28
|
+
* @type {number}
|
|
29
|
+
* @default 0
|
|
30
|
+
*/
|
|
31
|
+
min_length: number;
|
|
32
|
+
/**
|
|
33
|
+
* The minimum numbers of tokens to generate, ignoring the number of tokens in the prompt.
|
|
34
|
+
* @type {number}
|
|
35
|
+
* @default null
|
|
36
|
+
*/
|
|
37
|
+
min_new_tokens: number;
|
|
38
|
+
/**
|
|
39
|
+
* Controls the stopping condition for beam-based methods, like beam-search. It accepts the following values:
|
|
40
|
+
* - `true`, where the generation stops as soon as there are `num_beams` complete candidates;
|
|
41
|
+
* - `false`, where an heuristic is applied and the generation stops when is it very unlikely to find better candidates;
|
|
42
|
+
* - `"never"`, where the beam search procedure only stops when there cannot be better candidates (canonical beam search algorithm).
|
|
43
|
+
* @type {boolean|"never"}
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
early_stopping: boolean | "never";
|
|
47
|
+
/**
|
|
48
|
+
* The maximum amount of time you allow the computation to run for in seconds.
|
|
49
|
+
* Generation will still finish the current pass after allocated time has been passed.
|
|
50
|
+
* @type {number}
|
|
51
|
+
* @default null
|
|
52
|
+
*/
|
|
53
|
+
max_time: number;
|
|
54
|
+
/**
|
|
55
|
+
* Whether or not to use sampling; use greedy decoding otherwise.
|
|
56
|
+
* @type {boolean}
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
do_sample: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Number of beams for beam search. 1 means no beam search.
|
|
62
|
+
* @type {number}
|
|
63
|
+
* @default 1
|
|
64
|
+
*/
|
|
65
|
+
num_beams: number;
|
|
66
|
+
/**
|
|
67
|
+
* Number of groups to divide `num_beams` into in order to ensure diversity among different groups of beams.
|
|
68
|
+
* See [this paper](https://arxiv.org/pdf/1610.02424.pdf) for more details.
|
|
69
|
+
* @type {number}
|
|
70
|
+
* @default 1
|
|
71
|
+
*/
|
|
72
|
+
num_beam_groups: number;
|
|
73
|
+
/**
|
|
74
|
+
* The values balance the model confidence and the degeneration penalty in contrastive search decoding.
|
|
75
|
+
* @type {number}
|
|
76
|
+
* @default null
|
|
77
|
+
*/
|
|
78
|
+
penalty_alpha: number;
|
|
79
|
+
/**
|
|
80
|
+
* Whether or not the model should use the past last key/values attentions (if applicable to the model) to speed up decoding.
|
|
81
|
+
* @type {boolean}
|
|
82
|
+
* @default true
|
|
83
|
+
*/
|
|
84
|
+
use_cache: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* The value used to modulate the next token probabilities.
|
|
87
|
+
* @type {number}
|
|
88
|
+
* @default 1.0
|
|
89
|
+
*/
|
|
90
|
+
temperature: number;
|
|
91
|
+
/**
|
|
92
|
+
* The number of highest probability vocabulary tokens to keep for top-k-filtering.
|
|
93
|
+
* @type {number}
|
|
94
|
+
* @default 50
|
|
95
|
+
*/
|
|
96
|
+
top_k: number;
|
|
97
|
+
/**
|
|
98
|
+
* If set to float < 1, only the smallest set of most probable tokens with probabilities that add up to `top_p` or higher are kept for generation.
|
|
99
|
+
* @type {number}
|
|
100
|
+
* @default 1.0
|
|
101
|
+
*/
|
|
102
|
+
top_p: number;
|
|
103
|
+
/**
|
|
104
|
+
* Local typicality measures how similar the conditional probability of predicting a target token next is to the expected conditional probability of predicting a random token next, given the partial text already generated.
|
|
105
|
+
* If set to float < 1, the smallest set of the most locally typical tokens with probabilities that add up to `typical_p` or higher are kept for generation.
|
|
106
|
+
* See [this paper](https://arxiv.org/pdf/2202.00666.pdf) for more details.
|
|
107
|
+
* @type {number}
|
|
108
|
+
* @default 1.0
|
|
109
|
+
*/
|
|
110
|
+
typical_p: number;
|
|
111
|
+
/**
|
|
112
|
+
* If set to float strictly between 0 and 1, only tokens with a conditional probability greater than `epsilon_cutoff` will be sampled.
|
|
113
|
+
* In the paper, suggested values range from 3e-4 to 9e-4, depending on the size of the model.
|
|
114
|
+
* See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details.
|
|
115
|
+
* @type {number}
|
|
116
|
+
* @default 0.0
|
|
117
|
+
*/
|
|
118
|
+
epsilon_cutoff: number;
|
|
119
|
+
/**
|
|
120
|
+
* Eta sampling is a hybrid of locally typical sampling and epsilon sampling.
|
|
121
|
+
* If set to float strictly between 0 and 1, a token is only considered if it is greater than either `eta_cutoff` or `sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits)))`.
|
|
122
|
+
* The latter term is intuitively the expected next token probability, scaled by `sqrt(eta_cutoff)`. In the paper, suggested values range from 3e-4 to 2e-3, depending on the size of the model.
|
|
123
|
+
* See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details.
|
|
124
|
+
* @type {number}
|
|
125
|
+
* @default 0.0
|
|
126
|
+
*/
|
|
127
|
+
eta_cutoff: number;
|
|
128
|
+
/**
|
|
129
|
+
* This value is subtracted from a beam's score if it generates a token same as any beam from other group at a particular time.
|
|
130
|
+
* Note that `diversity_penalty` is only effective if `group beam search` is enabled.
|
|
131
|
+
* @type {number}
|
|
132
|
+
* @default 0.0
|
|
133
|
+
*/
|
|
134
|
+
diversity_penalty: number;
|
|
135
|
+
/**
|
|
136
|
+
* The parameter for repetition penalty. 1.0 means no penalty.
|
|
137
|
+
* See [this paper](https://arxiv.org/pdf/1909.05858.pdf) for more details.
|
|
138
|
+
* @type {number}
|
|
139
|
+
* @default 1.0
|
|
140
|
+
*/
|
|
141
|
+
repetition_penalty: number;
|
|
142
|
+
/**
|
|
143
|
+
* The paramater for encoder_repetition_penalty.
|
|
144
|
+
* An exponential penalty on sequences that are not in the original input.
|
|
145
|
+
* 1.0 means no penalty.
|
|
146
|
+
* @type {number}
|
|
147
|
+
* @default 1.0
|
|
148
|
+
*/
|
|
149
|
+
encoder_repetition_penalty: number;
|
|
150
|
+
/**
|
|
151
|
+
* Exponential penalty to the length that is used with beam-based generation.
|
|
152
|
+
* It is applied as an exponent to the sequence length, which in turn is used to divide the score of the sequence.
|
|
153
|
+
* Since the score is the log likelihood of the sequence (i.e. negative), `length_penalty` > 0.0 promotes longer sequences, while `length_penalty` < 0.0 encourages shorter sequences.
|
|
154
|
+
* @type {number}
|
|
155
|
+
* @default 1.0
|
|
156
|
+
*/
|
|
157
|
+
length_penalty: number;
|
|
158
|
+
/**
|
|
159
|
+
* If set to int > 0, all ngrams of that size can only occur once.
|
|
160
|
+
* @type {number}
|
|
161
|
+
* @default 0
|
|
162
|
+
*/
|
|
163
|
+
no_repeat_ngram_size: number;
|
|
164
|
+
/**
|
|
165
|
+
* List of token ids that are not allowed to be generated.
|
|
166
|
+
* In order to get the token ids of the words that should not appear in the generated text, use
|
|
167
|
+
* `tokenizer(bad_words, { add_prefix_space: true, add_special_tokens: false }).input_ids`.
|
|
168
|
+
* @type {number[][]}
|
|
169
|
+
* @default null
|
|
170
|
+
*/
|
|
171
|
+
bad_words_ids: number[][];
|
|
172
|
+
/**
|
|
173
|
+
* List of token ids that must be generated.
|
|
174
|
+
* If given a `number[][]`, this is treated as a simple list of words that must be included, the opposite to `bad_words_ids`.
|
|
175
|
+
* If given `number[][][]`, this triggers a [disjunctive constraint](https://github.com/huggingface/transformers/issues/14081), where one can allow different forms of each word.
|
|
176
|
+
* @type {number[][]|number[][][]}
|
|
177
|
+
* @default null
|
|
178
|
+
*/
|
|
179
|
+
force_words_ids: number[][] | number[][][];
|
|
180
|
+
/**
|
|
181
|
+
* Whether to renormalize the logits after applying all the logits processors or warpers (including the custom ones).
|
|
182
|
+
* It's highly recommended to set this flag to `true` as the search algorithms suppose the score logits are normalized but some logit processors or warpers break the normalization.
|
|
183
|
+
* @type {boolean}
|
|
184
|
+
* @default false
|
|
185
|
+
*/
|
|
186
|
+
renormalize_logits: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Custom constraints that can be added to the generation to ensure that the output will contain the use of certain tokens as defined by `Constraint` objects, in the most sensible way possible.
|
|
189
|
+
* @type {Object[]}
|
|
190
|
+
* @default null
|
|
191
|
+
*/
|
|
192
|
+
constraints: any[];
|
|
193
|
+
/**
|
|
194
|
+
* The id of the token to force as the first generated token after the `decoder_start_token_id`.
|
|
195
|
+
* Useful for multilingual models like mBART where the first generated token needs to be the target language token.
|
|
196
|
+
* @type {number}
|
|
197
|
+
* @default null
|
|
198
|
+
*/
|
|
199
|
+
forced_bos_token_id: number;
|
|
200
|
+
/**
|
|
201
|
+
* The id of the token to force as the last generated token when `max_length` is reached.
|
|
202
|
+
* Optionally, use a list to set multiple *end-of-sequence* tokens.
|
|
203
|
+
* @type {number|number[]}
|
|
204
|
+
* @default null
|
|
205
|
+
*/
|
|
206
|
+
forced_eos_token_id: number | number[];
|
|
207
|
+
/**
|
|
208
|
+
* Whether to remove possible *nan* and *inf* outputs of the model to prevent the generation method to crash. Note that using `remove_invalid_values` can slow down generation.
|
|
209
|
+
* @type {boolean}
|
|
210
|
+
*/
|
|
211
|
+
remove_invalid_values: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* This Tuple adds an exponentially increasing length penalty, after a certain amount of tokens have been generated.
|
|
214
|
+
* The tuple shall consist of: `(start_index, decay_factor)` where `start_index` indicates where penalty starts and `decay_factor` represents the factor of exponential decay.
|
|
215
|
+
* @type {[number, number]}
|
|
216
|
+
* @default null
|
|
217
|
+
*/
|
|
218
|
+
exponential_decay_length_penalty: [number, number];
|
|
219
|
+
/**
|
|
220
|
+
* A list of tokens that will be suppressed at generation.
|
|
221
|
+
* The `SuppressTokens` logit processor will set their log probs to `-inf` so that they are not sampled.
|
|
222
|
+
* @type {number[]}
|
|
223
|
+
* @default null
|
|
224
|
+
*/
|
|
225
|
+
suppress_tokens: number[];
|
|
226
|
+
/**
|
|
227
|
+
* A list of tokens that will be suppressed at the beginning of the generation.
|
|
228
|
+
* The `SuppressBeginTokens` logit processor will set their log probs to `-inf` so that they are not sampled.
|
|
229
|
+
* @type {number[]}
|
|
230
|
+
* @default null
|
|
231
|
+
*/
|
|
232
|
+
begin_suppress_tokens: number[];
|
|
233
|
+
/**
|
|
234
|
+
* A list of pairs of integers which indicates a mapping from generation indices to token indices that will be forced before sampling.
|
|
235
|
+
* For example, `[[1, 123]]` means the second generated token will always be a token of index 123.
|
|
236
|
+
* @type {[number, number][]}
|
|
237
|
+
* @default null
|
|
238
|
+
*/
|
|
239
|
+
forced_decoder_ids: [number, number][];
|
|
240
|
+
/**
|
|
241
|
+
* The guidance scale for classifier free guidance (CFG). CFG is enabled by setting `guidance_scale > 1`.
|
|
242
|
+
* Higher guidance scale encourages the model to generate samples that are more closely linked to the input
|
|
243
|
+
* prompt, usually at the expense of poorer quality.
|
|
244
|
+
* @type {number}
|
|
245
|
+
* @default null
|
|
246
|
+
*/
|
|
247
|
+
guidance_scale: number;
|
|
248
|
+
/**
|
|
249
|
+
* The number of independently computed returned sequences for each element in the batch.
|
|
250
|
+
* @type {number}
|
|
251
|
+
* @default 1
|
|
252
|
+
*/
|
|
253
|
+
num_return_sequences: number;
|
|
254
|
+
/**
|
|
255
|
+
* Whether or not to return the attentions tensors of all attention layers.
|
|
256
|
+
* See `attentions` under returned tensors for more details.
|
|
257
|
+
* @type {boolean}
|
|
258
|
+
* @default false
|
|
259
|
+
*/
|
|
260
|
+
output_attentions: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Whether or not to return the hidden states of all layers.
|
|
263
|
+
* See `hidden_states` under returned tensors for more details.
|
|
264
|
+
* @type {boolean}
|
|
265
|
+
* @default false
|
|
266
|
+
*/
|
|
267
|
+
output_hidden_states: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Whether or not to return the prediction scores.
|
|
270
|
+
* See `scores` under returned tensors for more details.
|
|
271
|
+
* @type {boolean}
|
|
272
|
+
* @default false
|
|
273
|
+
*/
|
|
274
|
+
output_scores: boolean;
|
|
275
|
+
/**
|
|
276
|
+
* Whether or not to return a `ModelOutput` instead of a plain tuple.
|
|
277
|
+
* @type {boolean}
|
|
278
|
+
* @default false
|
|
279
|
+
*/
|
|
280
|
+
return_dict_in_generate: boolean;
|
|
281
|
+
/**
|
|
282
|
+
* The id of the *padding* token.
|
|
283
|
+
* @type {number}
|
|
284
|
+
* @default null
|
|
285
|
+
*/
|
|
286
|
+
pad_token_id: number;
|
|
287
|
+
/**
|
|
288
|
+
* The id of the *beginning-of-sequence* token.
|
|
289
|
+
* @type {number}
|
|
290
|
+
* @default null
|
|
291
|
+
*/
|
|
292
|
+
bos_token_id: number;
|
|
293
|
+
/**
|
|
294
|
+
* The id of the *end-of-sequence* token.
|
|
295
|
+
* Optionally, use a list to set multiple *end-of-sequence* tokens.
|
|
296
|
+
* @type {number|number[]}
|
|
297
|
+
* @default null
|
|
298
|
+
*/
|
|
299
|
+
eos_token_id: number | number[];
|
|
300
|
+
/**
|
|
301
|
+
* If set to int > 0, all ngrams of that size that occur in the `encoder_input_ids` cannot occur in the `decoder_input_ids`.
|
|
302
|
+
* @type {number}
|
|
303
|
+
* @default 0
|
|
304
|
+
*/
|
|
305
|
+
encoder_no_repeat_ngram_size: number;
|
|
306
|
+
/**
|
|
307
|
+
* If an encoder-decoder model starts decoding with a different token than *bos*, the id of that token.
|
|
308
|
+
* @type {number}
|
|
309
|
+
* @default null
|
|
310
|
+
*/
|
|
311
|
+
decoder_start_token_id: number;
|
|
312
|
+
/**
|
|
313
|
+
* Additional generation kwargs will be forwarded to the `generate` function of the model.
|
|
314
|
+
* Kwargs that are not present in `generate`'s signature will be used in the model forward pass.
|
|
315
|
+
* @type {Object}
|
|
316
|
+
* @default {}
|
|
317
|
+
*/
|
|
318
|
+
generation_kwargs: any;
|
|
319
|
+
}
|
|
320
|
+
//# sourceMappingURL=configuration_utils.d.ts.map
|
|
@@ -0,0 +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;IACH,gBAHU,MAAM,CAGK;IAErB;;;;OAIG;IACH,sBAHU,MAAM,CAGS;IAEzB;;;;;;OAMG;IACH,eAHU,MAAM,EAAE,EAAE,CAGC;IAErB;;;;;;OAMG;IACH,iBAHU,MAAM,EAAE,EAAE,GAAC,MAAM,EAAE,EAAE,EAAE,CAGV;IAEvB;;;;;OAKG;IACH,oBAHU,OAAO,CAGU;IAE3B;;;;OAIG;IACH,aAHU,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;;;;;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"}
|