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

class optimum.utils.input_generators.DummyInputGenerator

< >

( )

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

concat_inputs

< >

( inputs dim: int )

Parameters

  • dim (int) — The dimension along which to concatenate.

Concatenates inputs together.

constant_tensor

< >

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

Parameters

  • shape (List[int]) — The shape of the constant tensor.
  • value (Union[int, float], optional, defaults to 1) — The value to fill the constant tensor with.
  • dtype (Any, optional) — The dtype of the constant tensor.
  • framework (str, optional, defaults to "pt") — The requested framework.

Generates a constant tensor.

generate

< >

( input_name: str framework: str = 'pt' )

Parameters

  • input_name (str) — The name of the input to generate.
  • framework (str, optional, defaults to "pt") — The requested framework.

Generates the dummy input matching input_name for the requested framework.

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 )

Parameters

  • dim (int) — The dimension along which to pad.
  • desired_length (int, optional) — The desired length along the dimension after padding.
  • padding_length (int, optional) — The length to pad along the dimension.
  • value (Union[int, float], optional, defaults to 1) — The value to use for padding.
  • dtype (Any, optional) — The dtype of the padding.

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

random_float_tensor

< >

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

Parameters

  • shape (List[int]) — The shape of the random tensor.
  • min_value (float, optional, defaults to 0) — The minimum value allowed.
  • max_value (float, optional, defaults to 1) — The maximum value allowed.
  • framework (str, optional, defaults to "pt") — The requested framework.

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

random_int_tensor

< >

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

Parameters

  • shape (List[int]) — The shape of the random tensor.
  • max_value (int) — The maximum value allowed.
  • min_value (int, optional, defaults to 0) — The minimum value allowed.
  • framework (str, optional, defaults to "pt") — The requested framework.

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

supports_input

< >

( input_name: str ) bool

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

class 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.Union[typing.Tuple[int, int], NoneType] = None random_sequence_length_range: typing.Union[typing.Tuple[int, int], NoneType] = None random_num_choices_range: typing.Union[typing.Tuple[int, int], NoneType] = None )

Generates dummy encoder text inputs.

class 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.Union[typing.Tuple[int, int], NoneType] = None random_sequence_length_range: typing.Union[typing.Tuple[int, int], NoneType] = None random_num_choices_range: typing.Union[typing.Tuple[int, int], NoneType] = None )

Generates dummy decoder text inputs.

class optimum.utils.DummyPastKeyValuesGenerator

< >

( task: str normalized_config: NormalizedTextConfig batch_size: int = 2 sequence_length: int = 16 random_batch_size_range: typing.Union[typing.Tuple[int, int], NoneType] = None random_sequence_length_range: typing.Union[typing.Tuple[int, int], NoneType] = None )

Generates dummy past_key_values inputs.

class optimum.utils.DummySeq2SeqPastKeyValuesGenerator

< >

( task: str normalized_config: NormalizedSeq2SeqConfig batch_size: int = 2 sequence_length: int = 16 encoder_sequence_length: typing.Optional[int] = None random_batch_size_range: typing.Union[typing.Tuple[int, int], NoneType] = None random_sequence_length_range: typing.Union[typing.Tuple[int, int], NoneType] = None )

Generates dummy past_key_values inputs for seq2seq architectures.

class optimum.utils.DummyBboxInputGenerator

< >

( task: str normalized_config: NormalizedConfig batch_size: int = 2 sequence_length: int = 16 random_batch_size_range: typing.Union[typing.Tuple[int, int], NoneType] = None random_sequence_length_range: typing.Union[typing.Tuple[int, int], NoneType] = None )

Generates dummy bbox inputs.

class optimum.utils.DummyVisionInputGenerator

< >

( task: str normalized_config: NormalizedVisionConfig batch_size: int = 2 num_channels: int = 3 width: int = 224 height: int = 224 )

Generates dummy vision inputs.

class optimum.utils.DummyAudioInputGenerator

< >

( task: str normalized_config: NormalizedConfig batch_size: int = 2 feature_size: int = 80 nb_max_frames: int = 3000 sequence_length: int = 16000 )