Buckets:

hf-doc-build/doc-dev / optimum /pr_2481 /en /utils /dummy_input_generators.md
|
download
raw
10.6 kB

Dummy Input Generators

It is very common to have to generate dummy inputs to perform a task (tracing, exporting a model to some backend, testing model outputs, etc). The goal of DummyInputGenerator classes is to make this generation easy and re-usable.

Base class[[optimum.utils.DummyInputGenerator]]

optimum.utils.DummyInputGenerator[[optimum.utils.DummyInputGenerator]]

optimum.utils.DummyInputGenerator()

Source

Generates dummy inputs for the supported input names, in the requested framework.

concat_inputs[[optimum.utils.DummyInputGenerator.concat_inputs]]

concat_inputs(inputs, dim: int)

Source

Parameters:

inputs : The list of tensors in a given framework to concatenate.

dim (int) : The dimension along which to concatenate.

Returns:

The tensor of the concatenation.

Concatenates inputs together.

constant_tensor[[optimum.utils.DummyInputGenerator.constant_tensor]]

constant_tensor(shape: typing.List[int], value: typing.Union[int, float] = 1, dtype: typing.Optional[typing.Any] = None, framework: str = 'pt')

Source

Parameters:

shape (List[int]) : The shape of the constant tensor.

value (Union[int, float], defaults to 1) : The value to fill the constant tensor with.

dtype (Optional[Any], defaults to None) : The dtype of the constant tensor.

framework (str, defaults to "pt") : The requested framework.

Returns:

A constant tensor in the requested framework.

Generates a constant tensor.

generate[[optimum.utils.DummyInputGenerator.generate]]

generate(input_name: str, framework: str = 'pt', int_dtype: str = 'int64', float_dtype: str = 'fp32')

Source

Parameters:

input_name (str) : The name of the input to generate.

framework (str, defaults to "pt") : The requested framework.

int_dtype (str, defaults to "int64") : The dtypes of generated integer tensors.

float_dtype (str, defaults to "fp32") : The dtypes of generated float tensors.

Returns:

A tensor in the requested framework of the input.

Generates the dummy input matching input_name for the requested framework.

pad_input_on_dim[[optimum.utils.DummyInputGenerator.pad_input_on_dim]]

pad_input_on_dim(input_, dim: int, desired_length: typing.Optional[int] = None, padding_length: typing.Optional[int] = None, value: typing.Union[int, float] = 1, dtype: typing.Optional[typing.Any] = None)

Source

Parameters:

input_ : The tensor to pad.

dim (int) : The dimension along which to pad.

desired_length (Optional[int], defaults to None) : The desired length along the dimension after padding.

padding_length (Optional[int], defaults to None) : The length to pad along the dimension.

value (Union[int, float], defaults to 1) : The value to use for padding.

dtype (Optional[Any], defaults to None) : The dtype of the padding.

Returns:

The padded tensor.

Pads an input either to the desired length, or by a padding length.

random_float_tensor[[optimum.utils.DummyInputGenerator.random_float_tensor]]

random_float_tensor(shape: typing.List[int], min_value: float = 0, max_value: float = 1, framework: str = 'pt', dtype: str = 'fp32')

Source

Parameters:

shape (List[int]) : The shape of the random tensor.

min_value (float, defaults to 0) : The minimum value allowed.

max_value (float, defaults to 1) : The maximum value allowed.

framework (str, defaults to "pt") : The requested framework.

dtype (str, defaults to "fp32") : The dtype of the generated float tensor. Could be "fp32", "fp16", "bf16".

Returns:

A random tensor in the requested framework.

Generates a tensor of random floats in the [min_value, max_value) range.

random_int_tensor[[optimum.utils.DummyInputGenerator.random_int_tensor]]

random_int_tensor(shape: typing.List[int], max_value: int, min_value: int = 0, framework: str = 'pt', dtype: str = 'int64')

Source

Parameters:

shape (List[int]) : The shape of the random tensor.

max_value (int) : The maximum value allowed.

min_value (int, defaults to 0) : The minimum value allowed.

framework (str, defaults to "pt") : The requested framework.

dtype (str, defaults to "int64") : The dtype of the generated integer tensor. Could be "int64", "int32", "int8".

Returns:

A random tensor in the requested framework.

Generates a tensor of random integers in the [min_value, max_value) range.

random_mask_tensor[[optimum.utils.DummyInputGenerator.random_mask_tensor]]

random_mask_tensor(shape: typing.List[int], padding_side: str = 'right', framework: str = 'pt', dtype: str = 'int64')

Source

Parameters:

shape (List[int]) : The shape of the random tensor.

padding_side (str, defaults to "right") : The side on which the padding is applied.

framework (str, defaults to "pt") : The requested framework.

dtype (str, defaults to "int64") : The dtype of the generated integer tensor. Could be "int64", "int32", "int8".

Returns:

A random mask tensor either left padded or right padded in the requested framework.

Generates a mask tensor either right or left padded.

supports_input[[optimum.utils.DummyInputGenerator.supports_input]]

supports_input(input_name: str)

Source

Parameters:

input_name (str) : The name of the input to generate.

Returns: bool

A boolean specifying whether the input is supported.

Checks whether the DummyInputGenerator supports the generation of the requested input.

Existing dummy input generators[[optimum.utils.DummyTextInputGenerator]]

optimum.utils.DummyTextInputGenerator[[optimum.utils.DummyTextInputGenerator]]

optimum.utils.DummyTextInputGenerator(task: str, normalized_config: NormalizedTextConfig, batch_size: int = 2, sequence_length: int = 16, num_choices: int = 4, random_batch_size_range: typing.Optional[typing.Tuple[int, int]] = None, random_sequence_length_range: typing.Optional[typing.Tuple[int, int]] = None, random_num_choices_range: typing.Optional[typing.Tuple[int, int]] = None, padding_side: str = 'right', **kwargs)

Source

Generates dummy encoder text inputs.

optimum.utils.DummyDecoderTextInputGenerator[[optimum.utils.DummyDecoderTextInputGenerator]]

optimum.utils.DummyDecoderTextInputGenerator(task: str, normalized_config: NormalizedTextConfig, batch_size: int = 2, sequence_length: int = 16, num_choices: int = 4, random_batch_size_range: typing.Optional[typing.Tuple[int, int]] = None, random_sequence_length_range: typing.Optional[typing.Tuple[int, int]] = None, random_num_choices_range: typing.Optional[typing.Tuple[int, int]] = None, padding_side: str = 'right', **kwargs)

Source

Generates dummy decoder text inputs.

optimum.utils.DummyPastKeyValuesGenerator[[optimum.utils.DummyPastKeyValuesGenerator]]

optimum.utils.DummyPastKeyValuesGenerator(task: str, normalized_config: NormalizedTextConfig, batch_size: int = 2, sequence_length: int = 16, random_batch_size_range: typing.Optional[typing.Tuple[int, int]] = None, random_sequence_length_range: typing.Optional[typing.Tuple[int, int]] = None, **kwargs)

Source

Generates dummy past_key_values inputs.

optimum.utils.DummySeq2SeqPastKeyValuesGenerator[[optimum.utils.DummySeq2SeqPastKeyValuesGenerator]]

optimum.utils.DummySeq2SeqPastKeyValuesGenerator(task: str, normalized_config: typing.Union[optimum.utils.normalized_config.NormalizedSeq2SeqConfig, optimum.utils.normalized_config.NormalizedEncoderDecoderConfig], batch_size: int = 2, sequence_length: int = 16, encoder_sequence_length: typing.Optional[int] = None, random_batch_size_range: typing.Optional[typing.Tuple[int, int]] = None, random_sequence_length_range: typing.Optional[typing.Tuple[int, int]] = None, **kwargs)

Source

Generates dummy past_key_values inputs for seq2seq architectures.

optimum.utils.DummyBboxInputGenerator[[optimum.utils.DummyBboxInputGenerator]]

optimum.utils.DummyBboxInputGenerator(task: str, normalized_config: NormalizedConfig, batch_size: int = 2, sequence_length: int = 16, random_batch_size_range: typing.Optional[typing.Tuple[int, int]] = None, random_sequence_length_range: typing.Optional[typing.Tuple[int, int]] = None, **kwargs)

Source

Generates dummy bbox inputs.

optimum.utils.DummyVisionInputGenerator[[optimum.utils.DummyVisionInputGenerator]]

optimum.utils.DummyVisionInputGenerator(task: str, normalized_config: NormalizedVisionConfig, batch_size: int = 2, num_channels: int = 3, width: int = 64, height: int = 64, visual_seq_length: int = 16, **kwargs)

Source

Generates dummy vision inputs.

optimum.utils.DummyAudioInputGenerator[[optimum.utils.DummyAudioInputGenerator]]

optimum.utils.DummyAudioInputGenerator(task: str, normalized_config: NormalizedConfig, batch_size: int = 2, feature_size: int = 80, nb_max_frames: int = 3000, audio_sequence_length: int = 16000, **kwargs)

Source

Xet Storage Details

Size:
10.6 kB
·
Xet hash:
42cba1f31af7683788f73ca4c7210715412d591cc3edf7faeeba6f62889d2abc

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.