# Dummy input generators

## 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](https://huggingface.co/docs/optimum/main/en/utils/dummy_input_generators#optimum.utils.DummyInputGenerator) classes is to make this generation easy and re-usable.

### Base class

#### class optimum.utils.DummyInputGenerator

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L112)

( )

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

**concat\_inputs**

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L255)

( inputsdim: int )

Parameters

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

Concatenates inputs together.

**constant\_tensor**

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L214)

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

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.

Generates a constant tensor.

**generate**

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L133)

( input\_name: strframework: str = 'pt'int\_dtype: str = 'int64'float\_dtype: str = 'fp32' )

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.

Generates the dummy input matching `input_name` for the requested framework.

**pad\_input\_on\_dim**

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L278)

( input\_dim: intdesired\_length: typing.Optional\[int] = Nonepadding\_length: typing.Optional\[int] = Nonevalue: typing.Union\[int, float] = 1dtype: typing.Optional\[typing.Any] = None )

Parameters

* **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.

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

**random\_float\_tensor**

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L183)

( shape: typing.List\[int]min\_value: float = 0max\_value: float = 1framework: str = 'pt'dtype: str = 'fp32' )

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”.

Generates a tensor of random floats in the \[min\_value, max\_value) range.

**random\_int\_tensor**

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L153)

( shape: typing.List\[int]max\_value: intmin\_value: int = 0framework: str = 'pt'dtype: str = 'int64' )

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”.

Generates a tensor of random integers in the \[min\_value, max\_value) range.

**supports\_input**

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L119)

( 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

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L324)

( task: strnormalized\_config: NormalizedTextConfigbatch\_size: int = 2sequence\_length: int = 16num\_choices: int = 4random\_batch\_size\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = Nonerandom\_sequence\_length\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = Nonerandom\_num\_choices\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = None\*\*kwargs )

Generates dummy encoder text inputs.

#### class optimum.utils.DummyDecoderTextInputGenerator

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L376)

( task: strnormalized\_config: NormalizedTextConfigbatch\_size: int = 2sequence\_length: int = 16num\_choices: int = 4random\_batch\_size\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = Nonerandom\_sequence\_length\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = Nonerandom\_num\_choices\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = None\*\*kwargs )

Generates dummy decoder text inputs.

#### class optimum.utils.DummyPastKeyValuesGenerator

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L439)

( task: strnormalized\_config: NormalizedTextConfigbatch\_size: int = 2sequence\_length: int = 16random\_batch\_size\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = Nonerandom\_sequence\_length\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = None\*\*kwargs )

Generates dummy past\_key\_values inputs.

#### class optimum.utils.DummySeq2SeqPastKeyValuesGenerator

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L486)

( task: strnormalized\_config: NormalizedSeq2SeqConfigbatch\_size: int = 2sequence\_length: int = 16encoder\_sequence\_length: typing.Optional\[int] = Nonerandom\_batch\_size\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = Nonerandom\_sequence\_length\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = None\*\*kwargs )

Generates dummy past\_key\_values inputs for seq2seq architectures.

#### class optimum.utils.DummyBboxInputGenerator

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L544)

( task: strnormalized\_config: NormalizedConfigbatch\_size: int = 2sequence\_length: int = 16random\_batch\_size\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = Nonerandom\_sequence\_length\_range: typing.Union\[typing.Tuple\[int, int], NoneType] = None\*\*kwargs )

Generates dummy bbox inputs.

#### class optimum.utils.DummyVisionInputGenerator

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L584)

( task: strnormalized\_config: NormalizedVisionConfigbatch\_size: int = 2num\_channels: int = 3width: int = 64height: int = 64\*\*kwargs )

Generates dummy vision inputs.

#### class optimum.utils.DummyAudioInputGenerator

[\<source>](https://github.com/huggingface/optimum/blob/main/optimum/utils/input_generators.py#L638)

( task: strnormalized\_config: NormalizedConfigbatch\_size: int = 2feature\_size: int = 80nb\_max\_frames: int = 3000audio\_sequence\_length: int = 16000\*\*kwargs )
