@huggingface/transformers
Advanced tools
Comparing version 3.2.3 to 3.2.4
{ | ||
"name": "@huggingface/transformers", | ||
"version": "3.2.3", | ||
"version": "3.2.4", | ||
"description": "State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!", | ||
@@ -27,3 +27,3 @@ "main": "./src/transformers.js", | ||
"format:check": "prettier --check .", | ||
"typegen": "tsc ./src/transformers.js --allowJs --declaration --emitDeclarationOnly --declarationMap --outDir types", | ||
"typegen": "tsc --build", | ||
"dev": "webpack serve --no-client-overlay", | ||
@@ -30,0 +30,0 @@ "build": "webpack && npm run typegen", |
@@ -20,19 +20,19 @@ import { FEATURE_EXTRACTOR_NAME } from "../utils/constants.js"; | ||
/** | ||
* Instantiate one of the processor classes of the library from a pretrained model. | ||
* Instantiate one of the feature extractor classes of the library from a pretrained model. | ||
* | ||
* The processor class to instantiate is selected based on the `image_processor_type` (or `feature_extractor_type`; legacy) | ||
* property of the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* The feature extractor class to instantiate is selected based on the `feature_extractor_type` property of | ||
* the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* | ||
* @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: | ||
* - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co. | ||
* - A string, the *model id* of a pretrained feature_extractor hosted inside a model repo on huggingface.co. | ||
* Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a | ||
* user or organization name, like `dbmdz/bert-base-german-cased`. | ||
* - A path to a *directory* containing processor files, e.g., `./my_model_directory/`. | ||
* @param {import('../utils/hub.js').PretrainedOptions} options Additional options for loading the processor. | ||
* - A path to a *directory* containing feature_extractor files, e.g., `./my_model_directory/`. | ||
* @param {import('../utils/hub.js').PretrainedOptions} options Additional options for loading the feature_extractor. | ||
* | ||
* @returns {Promise<FeatureExtractor>} A new instance of the Processor class. | ||
* @returns {Promise<FeatureExtractor>} A new instance of the Feature Extractor class. | ||
*/ | ||
static async from_pretrained(pretrained_model_name_or_path, options) { | ||
const preprocessorConfig = await getModelJSON(pretrained_model_name_or_path, FEATURE_EXTRACTOR_NAME, true, options); | ||
return new this(preprocessorConfig); | ||
const config = await getModelJSON(pretrained_model_name_or_path, FEATURE_EXTRACTOR_NAME, true, options); | ||
return new this(config); | ||
} | ||
@@ -39,0 +39,0 @@ } |
@@ -607,10 +607,16 @@ import { Callable } from "../utils/generic.js"; | ||
this.do_resize = config.do_resize ?? (this.size !== undefined); | ||
// @ts-expect-error TS2339 | ||
this.size_divisibility = config.size_divisibility ?? config.size_divisor; | ||
this.do_center_crop = config.do_center_crop; | ||
// @ts-expect-error TS2339 | ||
this.crop_size = config.crop_size; | ||
// @ts-expect-error TS2339 | ||
this.do_convert_rgb = config.do_convert_rgb ?? true; | ||
// @ts-expect-error TS2339 | ||
this.do_crop_margin = config.do_crop_margin; | ||
// @ts-expect-error TS2339 | ||
this.pad_size = config.pad_size; | ||
// @ts-expect-error TS2339 | ||
this.do_pad = config.do_pad; | ||
@@ -824,2 +830,3 @@ | ||
shortest_edge = size; | ||
// @ts-expect-error TS2339 | ||
longest_edge = this.config.max_size ?? shortest_edge; | ||
@@ -893,2 +900,3 @@ | ||
const { min_pixels, max_pixels } = size; | ||
// @ts-expect-error TS2339 | ||
const factor = this.config.patch_size * this.config.merge_size; | ||
@@ -909,2 +917,3 @@ return smart_resize(srcHeight, srcWidth, factor, min_pixels, max_pixels); | ||
return await image.resize(newWidth, newHeight, { | ||
// @ts-expect-error TS2322 | ||
resample: this.resample, | ||
@@ -960,2 +969,3 @@ }); | ||
if (this.do_thumbnail) { | ||
// @ts-expect-error TS2345 | ||
image = await this.thumbnail(image, this.size, this.resample); | ||
@@ -985,2 +995,3 @@ } | ||
// to emulate the behavior of the original Python code (w/ numpy). | ||
/** @type {Float32Array} */ | ||
let pixelData = Float32Array.from(image.data); | ||
@@ -987,0 +998,0 @@ let imgDims = [image.height, image.width, image.channels]; |
@@ -31,2 +31,3 @@ | ||
* @typedef {import('../utils/hub.js').PretrainedOptions & ProcessorProperties} PretrainedProcessorOptions | ||
* @typedef {import('../tokenizers.js').PreTrainedTokenizer} PreTrainedTokenizer | ||
*/ | ||
@@ -65,3 +66,3 @@ | ||
/** | ||
* @returns {import('../tokenizers.js').PreTrainedTokenizer|undefined} The tokenizer of the processor, if it exists. | ||
* @returns {PreTrainedTokenizer|undefined} The tokenizer of the processor, if it exists. | ||
*/ | ||
@@ -79,2 +80,7 @@ get tokenizer() { | ||
/** | ||
* @param {Parameters<PreTrainedTokenizer['apply_chat_template']>[0]} messages | ||
* @param {Parameters<PreTrainedTokenizer['apply_chat_template']>[1]} options | ||
* @returns {ReturnType<PreTrainedTokenizer['apply_chat_template']>} | ||
*/ | ||
apply_chat_template(messages, options = {}) { | ||
@@ -90,2 +96,6 @@ if (!this.tokenizer) { | ||
/** | ||
* @param {Parameters<PreTrainedTokenizer['batch_decode']>} args | ||
* @returns {ReturnType<PreTrainedTokenizer['batch_decode']>} | ||
*/ | ||
batch_decode(...args) { | ||
@@ -118,4 +128,4 @@ if (!this.tokenizer) { | ||
* | ||
* The processor class to instantiate is selected based on the `feature_extractor_type` property of the config object | ||
* (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* The processor class to instantiate is selected based on the `image_processor_type` (or `feature_extractor_type`; legacy) | ||
* property of the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* | ||
@@ -122,0 +132,0 @@ * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: |
@@ -73,11 +73,15 @@ | ||
case 'idefics3': | ||
// @ts-expect-error TS2339 | ||
init_normalized_config = getNormalizedConfig(config.text_config); | ||
break; | ||
case 'moondream1': | ||
// @ts-expect-error TS2339 | ||
init_normalized_config = getNormalizedConfig(config.phi_config); | ||
break; | ||
case 'musicgen': | ||
// @ts-expect-error TS2339 | ||
init_normalized_config = getNormalizedConfig(config.decoder); | ||
break; | ||
case 'multi_modality': | ||
// @ts-expect-error TS2339 | ||
init_normalized_config = getNormalizedConfig(config.language_config); | ||
@@ -203,2 +207,3 @@ break; | ||
case 'vision-encoder-decoder': | ||
// @ts-expect-error TS2339 | ||
const decoderConfig = getNormalizedConfig(config.decoder); | ||
@@ -205,0 +210,0 @@ |
@@ -29,3 +29,3 @@ /** | ||
const VERSION = '3.2.3'; | ||
const VERSION = '3.2.4'; | ||
@@ -32,0 +32,0 @@ // Check if various APIs are available (depends on environment) |
@@ -9,18 +9,2 @@ | ||
/** | ||
* Instantiate one of the feature extractor classes of the library from a pretrained model. | ||
* | ||
* The processor class to instantiate is selected based on the `feature_extractor_type` property of | ||
* the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* | ||
* @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: | ||
* - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co. | ||
* Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a | ||
* user or organization name, like `dbmdz/bert-base-german-cased`. | ||
* - A path to a *directory* containing processor files, e.g., `./my_model_directory/`. | ||
* @param {import('../../utils/hub.js').PretrainedOptions} options Additional options for loading the processor. | ||
* | ||
* @returns {Promise<AllFeatureExtractors.ImageProcessor>} A new instance of the Processor class. | ||
*/ | ||
/** @type {typeof FeatureExtractor.from_pretrained} */ | ||
@@ -27,0 +11,0 @@ static async from_pretrained(pretrained_model_name_or_path, options={}) { |
@@ -43,18 +43,2 @@ | ||
/** | ||
* Instantiate one of the processor classes of the library from a pretrained model. | ||
* | ||
* The processor class to instantiate is selected based on the `image_processor_type` (or `feature_extractor_type`; legacy) | ||
* property of the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* | ||
* @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: | ||
* - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co. | ||
* Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a | ||
* user or organization name, like `dbmdz/bert-base-german-cased`. | ||
* - A path to a *directory* containing processor files, e.g., `./my_model_directory/`. | ||
* @param {import('../../utils/hub.js').PretrainedOptions} options Additional options for loading the processor. | ||
* | ||
* @returns {Promise<Processor>} A new instance of the Processor class. | ||
*/ | ||
/** @type {typeof Processor.from_pretrained} */ | ||
@@ -61,0 +45,0 @@ static async from_pretrained(pretrained_model_name_or_path, options={}) { |
@@ -12,2 +12,3 @@ import { | ||
*/ | ||
// @ts-expect-error TS2339 | ||
this.crop_pct = this.config.crop_pct ?? (224 / 256); | ||
@@ -14,0 +15,0 @@ } |
@@ -8,2 +8,3 @@ import { | ||
super(config); | ||
// @ts-expect-error TS2339 | ||
this.include_top = this.config.include_top ?? true; | ||
@@ -10,0 +11,0 @@ if (this.include_top) { |
@@ -13,4 +13,7 @@ import { Processor } from "../../base/processing_utils.js"; | ||
const { | ||
// @ts-expect-error TS2339 | ||
tasks_answer_post_processing_type, | ||
// @ts-expect-error TS2339 | ||
task_prompts_without_inputs, | ||
// @ts-expect-error TS2339 | ||
task_prompts_with_input, | ||
@@ -17,0 +20,0 @@ } = this.image_processor.config; |
@@ -149,2 +149,4 @@ | ||
const end_offset = (i + 1) * pixel_attention_mask_stride; | ||
// @ts-expect-error | ||
pixel_attention_mask_data.fill(false, start_offset, end_offset); | ||
@@ -151,0 +153,0 @@ } |
@@ -16,2 +16,3 @@ | ||
}); | ||
// @ts-expect-error TS2339 | ||
this.constant_values = this.config.background_color.map(x => x * this.rescale_factor) | ||
@@ -18,0 +19,0 @@ } |
@@ -122,2 +122,4 @@ import { Processor } from "../../base/processing_utils.js"; | ||
*/ | ||
// @ts-expect-error The type of this method is not compatible with the one | ||
// in the base class. It might be a good idea to fix this. | ||
batch_decode([char_logits, bpe_logits, wp_logits]) { | ||
@@ -124,0 +126,0 @@ const [char_preds, char_scores] = this._decode_helper(char_logits, 'char'); |
@@ -44,2 +44,3 @@ import { Processor } from "../../base/processing_utils.js"; | ||
const bos_token = this.tokenizer.bos_token; | ||
// @ts-expect-error TS2339 | ||
const image_seq_length = this.image_processor.config.image_seq_length; | ||
@@ -46,0 +47,0 @@ let input_strings; |
@@ -17,3 +17,3 @@ import { Processor } from "../../base/processing_utils.js"; | ||
* @param {RawImage|RawImage[]} images | ||
* @param {...any} args | ||
* @param { { padding?: boolean, truncation?: boolean, num_crops?: number } | undefined } options | ||
* @returns {Promise<any>} | ||
@@ -20,0 +20,0 @@ */ |
@@ -55,2 +55,3 @@ import { FeatureExtractor, validate_audio_inputs } from '../../base/feature_extraction_utils.js'; | ||
for (let i = 0; i < scores.length; ++i) { | ||
/** @type {number[]} */ | ||
const probabilities = softmax(scores[i]); | ||
@@ -57,0 +58,0 @@ const [score, id] = max(probabilities); |
@@ -31,2 +31,3 @@ import { Processor } from "../../base/processing_utils.js"; | ||
if (image_grid_thw) { | ||
// @ts-expect-error TS2551 | ||
let merge_length = this.image_processor.config.merge_size ** 2; | ||
@@ -33,0 +34,0 @@ let index = 0; |
@@ -136,4 +136,4 @@ import { FeatureExtractor, validate_audio_inputs } from '../../base/feature_extraction_utils.js'; | ||
[1, numPaddedFrames], | ||
) | ||
padded_attention_mask.data.fill(1n, 0, num_frames); | ||
); | ||
/** @type {BigInt64Array} */ (padded_attention_mask.data).fill(1n, 0, num_frames); | ||
} | ||
@@ -140,0 +140,0 @@ } |
@@ -47,3 +47,3 @@ import { FeatureExtractor, validate_audio_inputs } from '../../base/feature_extraction_utils.js'; | ||
const data = features.data; | ||
const maxValue = max(data)[0]; | ||
const maxValue = max(/** @type {Float32Array} */(data))[0]; | ||
@@ -50,0 +50,0 @@ for (let i = 0; i < data.length; ++i) { |
@@ -39,2 +39,12 @@ import { createInferenceSession, isONNXProxy } from "../backends/onnx.js"; | ||
static get nearest_interpolate_4d() { | ||
if (!this._nearest_interpolate_4d) { | ||
this._nearest_interpolate_4d = wrap( | ||
[8, 10, 18, 0, 58, 129, 1, 10, 41, 10, 1, 120, 10, 0, 10, 0, 10, 1, 115, 18, 1, 121, 34, 6, 82, 101, 115, 105, 122, 101, 42, 18, 10, 4, 109, 111, 100, 101, 34, 7, 110, 101, 97, 114, 101, 115, 116, 160, 1, 3, 18, 1, 114, 90, 31, 10, 1, 120, 18, 26, 10, 24, 8, 1, 18, 20, 10, 3, 18, 1, 98, 10, 3, 18, 1, 99, 10, 3, 18, 1, 104, 10, 3, 18, 1, 119, 90, 15, 10, 1, 115, 18, 10, 10, 8, 8, 7, 18, 4, 10, 2, 8, 4, 98, 31, 10, 1, 121, 18, 26, 10, 24, 8, 1, 18, 20, 10, 3, 18, 1, 98, 10, 3, 18, 1, 99, 10, 3, 18, 1, 104, 10, 3, 18, 1, 119, 66, 2, 16, 21], | ||
this.session_options, | ||
'y', | ||
); | ||
} | ||
return this._nearest_interpolate_4d; | ||
} | ||
static get bilinear_interpolate_4d() { | ||
@@ -41,0 +51,0 @@ if (!this._bilinear_interpolate_4d) { |
@@ -0,1 +1,3 @@ | ||
/// <reference types="@webgpu/types" /> | ||
import { apis } from "../env.js"; | ||
@@ -2,0 +4,0 @@ |
@@ -124,3 +124,3 @@ | ||
const data = await fs.promises.readFile(this.filePath); | ||
return data.buffer; | ||
return /** @type {ArrayBuffer} */ (data.buffer); | ||
} | ||
@@ -127,0 +127,0 @@ |
@@ -228,4 +228,5 @@ | ||
* Returns the value and index of the minimum element in an array. | ||
* @param {number[]|TypedArray} arr array of numbers. | ||
* @returns {[number, number]} the value and index of the minimum element, of the form: [valueOfMin, indexOfMin] | ||
* @template {number[]|bigint[]|AnyTypedArray} T | ||
* @param {T} arr array of numbers. | ||
* @returns {T extends bigint[]|BigTypedArray ? [bigint, number] : [number, number]} the value and index of the minimum element, of the form: [valueOfMin, indexOfMin] | ||
* @throws {Error} If array is empty. | ||
@@ -243,3 +244,3 @@ */ | ||
} | ||
return [min, indexOfMin]; | ||
return /** @type {T extends bigint[]|BigTypedArray ? [bigint, number] : [number, number]} */([min, indexOfMin]); | ||
} | ||
@@ -250,4 +251,5 @@ | ||
* Returns the value and index of the maximum element in an array. | ||
* @param {number[]|AnyTypedArray} arr array of numbers. | ||
* @returns {[number, number]} the value and index of the maximum element, of the form: [valueOfMax, indexOfMax] | ||
* @template {number[]|bigint[]|AnyTypedArray} T | ||
* @param {T} arr array of numbers. | ||
* @returns {T extends bigint[]|BigTypedArray ? [bigint, number] : [number, number]} the value and index of the maximum element, of the form: [valueOfMax, indexOfMax] | ||
* @throws {Error} If array is empty. | ||
@@ -265,3 +267,3 @@ */ | ||
} | ||
return [Number(max), indexOfMax]; | ||
return /** @type {T extends bigint[]|BigTypedArray ? [bigint, number] : [number, number]} */([max, indexOfMax]); | ||
} | ||
@@ -268,0 +270,0 @@ |
@@ -12,2 +12,4 @@ /** | ||
interpolate_data, | ||
max, | ||
min, | ||
permute_data | ||
@@ -468,4 +470,2 @@ } from './maths.js'; | ||
// TODO add .max() and .min() methods | ||
/** | ||
@@ -764,2 +764,32 @@ * Returns the sum of each row of the input tensor in the given dimension dim. | ||
min(dim = null, keepdim = false) { | ||
if (dim !== null) { | ||
throw new Error("`dim !== null` not yet implemented."); | ||
} | ||
const value = min(this.data)[0]; | ||
return new Tensor(this.type, [value], []); | ||
} | ||
max(dim = null, keepdim = false) { | ||
if (dim !== null) { | ||
throw new Error("`dim !== null` not yet implemented."); | ||
} | ||
const value = max(this.data)[0]; | ||
return new Tensor(this.type, [value], []); | ||
} | ||
argmin(dim = null, keepdim = false) { | ||
if (dim !== null) { | ||
throw new Error("`dim !== null` not yet implemented."); | ||
} | ||
const index = min(this.data)[1]; | ||
return new Tensor('int64', [BigInt(index)], []); | ||
} | ||
argmax(dim = null, keepdim = false) { | ||
if (dim !== null) { | ||
throw new Error("`dim !== null` not yet implemented."); | ||
} | ||
const index = max(this.data)[1]; | ||
return new Tensor('int64', [BigInt(index)], []); | ||
} | ||
/** | ||
@@ -898,3 +928,3 @@ * Performs Tensor dtype conversion. | ||
* @param {[number, number]|[number, number, number]|[number, number, number, number]} [options.size=null] output spatial size. | ||
* @param {"bilinear"|"bicubic"} [options.mode='bilinear'] algorithm used for upsampling | ||
* @param {"nearest"|"bilinear"|"bicubic"} [options.mode='bilinear'] algorithm used for upsampling | ||
* @returns {Promise<Tensor>} The interpolated tensor. | ||
@@ -929,3 +959,5 @@ */ | ||
let op; | ||
if (mode === 'bilinear') { | ||
if (mode === 'nearest') { | ||
op = await TensorOpRegistry.nearest_interpolate_4d; | ||
} else if (mode === 'bilinear') { | ||
op = await TensorOpRegistry.bilinear_interpolate_4d; | ||
@@ -971,3 +1003,3 @@ } else if (mode === 'bicubic') { | ||
* @param {Tensor} x the input tensor | ||
* @param {number} k the k in "top-k" | ||
* @param {number} [k] the k in "top-k" | ||
* @returns {Promise<[Tensor, Tensor]>} the output tuple of (Tensor, LongTensor) of top-k elements and their indices. | ||
@@ -978,3 +1010,3 @@ */ | ||
if (k === null) { | ||
if (k == null) { | ||
k = x.dims.at(-1); | ||
@@ -1008,6 +1040,6 @@ } else { | ||
return await op({ | ||
x: data, | ||
s: arrayToIndexTensor(starts), | ||
e: arrayToIndexTensor(ends), | ||
a: arrayToIndexTensor(axes), | ||
x: data, | ||
s: arrayToIndexTensor(starts), | ||
e: arrayToIndexTensor(ends), | ||
a: arrayToIndexTensor(axes), | ||
t: arrayToIndexTensor(steps ?? new Array(axes.length).fill(1)), | ||
@@ -1014,0 +1046,0 @@ }); |
@@ -17,15 +17,15 @@ /** | ||
/** | ||
* Instantiate one of the processor classes of the library from a pretrained model. | ||
* Instantiate one of the feature extractor classes of the library from a pretrained model. | ||
* | ||
* The processor class to instantiate is selected based on the `image_processor_type` (or `feature_extractor_type`; legacy) | ||
* property of the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* The feature extractor class to instantiate is selected based on the `feature_extractor_type` property of | ||
* the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* | ||
* @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: | ||
* - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co. | ||
* - A string, the *model id* of a pretrained feature_extractor hosted inside a model repo on huggingface.co. | ||
* Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a | ||
* user or organization name, like `dbmdz/bert-base-german-cased`. | ||
* - A path to a *directory* containing processor files, e.g., `./my_model_directory/`. | ||
* @param {import('../utils/hub.js').PretrainedOptions} options Additional options for loading the processor. | ||
* - A path to a *directory* containing feature_extractor files, e.g., `./my_model_directory/`. | ||
* @param {import('../utils/hub.js').PretrainedOptions} options Additional options for loading the feature_extractor. | ||
* | ||
* @returns {Promise<FeatureExtractor>} A new instance of the Processor class. | ||
* @returns {Promise<FeatureExtractor>} A new instance of the Feature Extractor class. | ||
*/ | ||
@@ -32,0 +32,0 @@ static from_pretrained(pretrained_model_name_or_path: string, options: import("../utils/hub.js").PretrainedOptions): Promise<FeatureExtractor>; |
@@ -8,2 +8,3 @@ declare const Processor_base: new () => { | ||
* @typedef {import('../utils/hub.js').PretrainedOptions & ProcessorProperties} PretrainedProcessorOptions | ||
* @typedef {import('../tokenizers.js').PreTrainedTokenizer} PreTrainedTokenizer | ||
*/ | ||
@@ -19,4 +20,4 @@ /** | ||
* | ||
* The processor class to instantiate is selected based on the `feature_extractor_type` property of the config object | ||
* (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* The processor class to instantiate is selected based on the `image_processor_type` (or `feature_extractor_type`; legacy) | ||
* property of the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) | ||
* | ||
@@ -46,5 +47,5 @@ * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: | ||
/** | ||
* @returns {import('../tokenizers.js').PreTrainedTokenizer|undefined} The tokenizer of the processor, if it exists. | ||
* @returns {PreTrainedTokenizer|undefined} The tokenizer of the processor, if it exists. | ||
*/ | ||
get tokenizer(): import("../tokenizers.js").PreTrainedTokenizer | undefined; | ||
get tokenizer(): PreTrainedTokenizer | undefined; | ||
/** | ||
@@ -54,18 +55,14 @@ * @returns {import('./feature_extraction_utils.js').FeatureExtractor|undefined} The feature extractor of the processor, if it exists. | ||
get feature_extractor(): import("./feature_extraction_utils.js").FeatureExtractor | undefined; | ||
apply_chat_template(messages: any, options?: {}): string | number[] | number[][] | import("../transformers.js").Tensor | { | ||
/** | ||
* List of token ids to be fed to a model. | ||
*/ | ||
input_ids: number[] | number[][] | import("../transformers.js").Tensor; | ||
/** | ||
* List of indices specifying which tokens should be attended to by the model. | ||
*/ | ||
attention_mask: number[] | number[][] | import("../transformers.js").Tensor; | ||
/** | ||
* List of token type ids to be fed to a model. | ||
*/ | ||
token_type_ids?: number[] | number[][] | import("../transformers.js").Tensor; | ||
}; | ||
batch_decode(...args: any[]): string[]; | ||
/** | ||
* @param {Parameters<PreTrainedTokenizer['apply_chat_template']>[0]} messages | ||
* @param {Parameters<PreTrainedTokenizer['apply_chat_template']>[1]} options | ||
* @returns {ReturnType<PreTrainedTokenizer['apply_chat_template']>} | ||
*/ | ||
apply_chat_template(messages: Parameters<PreTrainedTokenizer["apply_chat_template"]>[0], options?: Parameters<PreTrainedTokenizer["apply_chat_template"]>[1]): ReturnType<PreTrainedTokenizer["apply_chat_template"]>; | ||
/** | ||
* @param {Parameters<PreTrainedTokenizer['batch_decode']>} args | ||
* @returns {ReturnType<PreTrainedTokenizer['batch_decode']>} | ||
*/ | ||
batch_decode(batch: number[][] | import("../transformers.js").Tensor, decode_args?: any): ReturnType<PreTrainedTokenizer["batch_decode"]>; | ||
/** | ||
* Calls the feature_extractor function with the given input. | ||
@@ -83,3 +80,4 @@ * @param {any} input The input to extract features from. | ||
export type PretrainedProcessorOptions = import("../utils/hub.js").PretrainedOptions & ProcessorProperties; | ||
export type PreTrainedTokenizer = import("../tokenizers.js").PreTrainedTokenizer; | ||
export {}; | ||
//# sourceMappingURL=processing_utils.d.ts.map |
@@ -1,2 +0,2 @@ | ||
type GenerationFunctionParameters = { | ||
export type GenerationFunctionParameters = { | ||
/** | ||
@@ -3,0 +3,0 @@ * (`Tensor` of varying shape depending on the modality, *optional*): |
@@ -8,6 +8,10 @@ export class Phi3VProcessor extends Processor { | ||
* @param {RawImage|RawImage[]} images | ||
* @param {...any} args | ||
* @param { { padding?: boolean, truncation?: boolean, num_crops?: number } | undefined } options | ||
* @returns {Promise<any>} | ||
*/ | ||
_call(text: string | string[], images?: RawImage | RawImage[], { padding, truncation, num_crops, }?: any[]): Promise<any>; | ||
_call(text: string | string[], images?: RawImage | RawImage[], { padding, truncation, num_crops, }?: { | ||
padding?: boolean; | ||
truncation?: boolean; | ||
num_crops?: number; | ||
} | undefined): Promise<any>; | ||
} | ||
@@ -14,0 +18,0 @@ import { Processor } from "../../base/processing_utils.js"; |
@@ -72,3 +72,3 @@ export class WhisperGenerationConfig extends GenerationConfig { | ||
} | ||
export type WhisperGenerationFunctionParameters = any & { | ||
export type WhisperGenerationFunctionParameters = import("../../generation/parameters.js").GenerationFunctionParameters & { | ||
generation_config: WhisperGenerationConfig; | ||
@@ -75,0 +75,0 @@ } & WhisperGenerationConfig; |
export class TensorOpRegistry { | ||
static session_options: {}; | ||
static get nearest_interpolate_4d(): Promise<(arg0: Record<string, Tensor>) => Promise<Tensor>>; | ||
static get bilinear_interpolate_4d(): Promise<(arg0: Record<string, Tensor>) => Promise<Tensor>>; | ||
@@ -4,0 +5,0 @@ static get bicubic_interpolate_4d(): Promise<(arg0: Record<string, Tensor>) => Promise<Tensor>>; |
@@ -106,3 +106,3 @@ /** | ||
headers: Headers; | ||
exists: any; | ||
exists: boolean; | ||
status: number; | ||
@@ -109,0 +109,0 @@ statusText: string; |
@@ -132,4 +132,4 @@ export class RawImage { | ||
*/ | ||
save(path: string): Promise<any>; | ||
toSharp(): any; | ||
save(path: string): Promise<sharp.OutputInfo>; | ||
toSharp(): sharp.Sharp; | ||
} | ||
@@ -141,2 +141,3 @@ /** | ||
import { Tensor } from './tensor.js'; | ||
import sharp from 'sharp'; | ||
//# sourceMappingURL=image.d.ts.map |
@@ -64,14 +64,16 @@ /** | ||
* Returns the value and index of the minimum element in an array. | ||
* @param {number[]|TypedArray} arr array of numbers. | ||
* @returns {[number, number]} the value and index of the minimum element, of the form: [valueOfMin, indexOfMin] | ||
* @template {number[]|bigint[]|AnyTypedArray} T | ||
* @param {T} arr array of numbers. | ||
* @returns {T extends bigint[]|BigTypedArray ? [bigint, number] : [number, number]} the value and index of the minimum element, of the form: [valueOfMin, indexOfMin] | ||
* @throws {Error} If array is empty. | ||
*/ | ||
export function min(arr: number[] | TypedArray): [number, number]; | ||
export function min<T extends number[] | bigint[] | AnyTypedArray>(arr: T): T extends bigint[] | BigTypedArray ? [bigint, number] : [number, number]; | ||
/** | ||
* Returns the value and index of the maximum element in an array. | ||
* @param {number[]|AnyTypedArray} arr array of numbers. | ||
* @returns {[number, number]} the value and index of the maximum element, of the form: [valueOfMax, indexOfMax] | ||
* @template {number[]|bigint[]|AnyTypedArray} T | ||
* @param {T} arr array of numbers. | ||
* @returns {T extends bigint[]|BigTypedArray ? [bigint, number] : [number, number]} the value and index of the maximum element, of the form: [valueOfMax, indexOfMax] | ||
* @throws {Error} If array is empty. | ||
*/ | ||
export function max(arr: number[] | AnyTypedArray): [number, number]; | ||
export function max<T extends number[] | bigint[] | AnyTypedArray>(arr: T): T extends bigint[] | BigTypedArray ? [bigint, number] : [number, number]; | ||
/** | ||
@@ -78,0 +80,0 @@ * Performs median filter on the provided data. Padding is done by mirroring the data. |
@@ -23,3 +23,3 @@ /** | ||
* @param {[number, number]|[number, number, number]|[number, number, number, number]} [options.size=null] output spatial size. | ||
* @param {"bilinear"|"bicubic"} [options.mode='bilinear'] algorithm used for upsampling | ||
* @param {"nearest"|"bilinear"|"bicubic"} [options.mode='bilinear'] algorithm used for upsampling | ||
* @returns {Promise<Tensor>} The interpolated tensor. | ||
@@ -29,3 +29,3 @@ */ | ||
size?: [number, number] | [number, number, number] | [number, number, number, number]; | ||
mode?: "bilinear" | "bicubic"; | ||
mode?: "nearest" | "bilinear" | "bicubic"; | ||
}): Promise<Tensor>; | ||
@@ -52,6 +52,6 @@ /** | ||
* @param {Tensor} x the input tensor | ||
* @param {number} k the k in "top-k" | ||
* @param {number} [k] the k in "top-k" | ||
* @returns {Promise<[Tensor, Tensor]>} the output tuple of (Tensor, LongTensor) of top-k elements and their indices. | ||
*/ | ||
export function topk(x: Tensor, k: number): Promise<[Tensor, Tensor]>; | ||
export function topk(x: Tensor, k?: number): Promise<[Tensor, Tensor]>; | ||
/** | ||
@@ -434,2 +434,6 @@ * Slice a multidimensional float32 tensor. | ||
mean(dim?: any, keepdim?: boolean): Tensor; | ||
min(dim?: any, keepdim?: boolean): Tensor; | ||
max(dim?: any, keepdim?: boolean): Tensor; | ||
argmin(dim?: any, keepdim?: boolean): Tensor; | ||
argmax(dim?: any, keepdim?: boolean): Tensor; | ||
/** | ||
@@ -436,0 +440,0 @@ * Performs Tensor dtype conversion. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41426689
311
141623