Optimum 文档

虚拟输入生成器

您正在查看 main 版本,该版本需要从源码安装。如果您想要常规 pip 安装,请查看最新的稳定版本 (v1.23.1)。
Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

虚拟输入生成器

在执行任务(追踪、将模型导出到某些后端、测试模型输出等)时,通常需要生成虚拟输入。DummyInputGenerator 类的目标是使此生成过程变得简单且可重用。

基类

class optimum.utils.DummyInputGenerator

< >

( )

为支持的输入名称在请求的框架中生成虚拟输入。

concat_inputs

< >

( inputs dim: int )

参数

  • dim (int) — 要沿其连接的维度。

将输入连接在一起。

constant_tensor

< >

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

参数

  • shape (List[int]) — 常量张量的形状。
  • value (Union[int, float], 默认为 1) — 用于填充常量张量的值。
  • dtype (Optional[Any], 默认为 None) — 常量张量的数据类型。
  • framework (str, 默认为 "pt") — 请求的框架。

生成一个常量张量。

generate

< >

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

参数

  • input_name (str) — 要生成的输入的名称。
  • framework (str, 默认为 "pt") — 请求的框架。
  • int_dtype (str, 默认为 "int64") — 生成的整数张量的数据类型。
  • float_dtype (str, 默认为 "fp32") — 生成的浮点张量的数据类型。

为请求的框架生成与 input_name 匹配的虚拟输入。

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 )

参数

  • dim (int) — 要沿其填充的维度。
  • desired_length (Optional[int], 默认为 None) — 填充后沿维度的期望长度。
  • padding_length (Optional[int], 默认为 None) — 沿维度填充的长度。
  • value (Union[int, float], 默认为 1) — 用于填充的值。
  • dtype (Optional[Any], 默认为 None) — 填充的数据类型。

将输入填充到期望的长度或填充长度。

random_float_tensor

< >

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

参数

  • shape (List[int]) — 随机张量的形状。
  • min_value (float, 默认为 0) — 允许的最小值。
  • max_value (float, 默认为 1) — 允许的最大值。
  • framework (str, 默认为 "pt") — 请求的框架。
  • dtype (str, 默认为 "fp32") — 生成的浮点张量的数据类型。可以是 “fp32”, “fp16”, “bf16”。

生成 [min_value, max_value) 范围内的随机浮点张量。

random_int_tensor

< >

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

参数

  • shape (List[int]) — 随机张量的形状。
  • max_value (int) — 允许的最大值。
  • min_value (int, 默认为 0) — 允许的最小值。
  • framework (str, 默认为 "pt") — 请求的框架。
  • dtype (str, 默认为 "int64") — 生成的整数张量的数据类型。可以是 “int64”, “int32”, “int8”。

生成 [min_value, max_value) 范围内的随机整数张量。

random_mask_tensor

< >

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

参数

  • shape (List[int]) — 随机张量的形状。
  • padding_side (str, 默认为 “right”) — 应用填充的一侧。
  • framework (str, 默认为 "pt") — 请求的框架。
  • dtype (str, 默认为 "int64") — 生成的整数张量的数据类型。可以是 “int64”, “int32”, “int8”。

生成右侧或左侧填充的掩码张量。

supports_input

< >

( input_name: str ) bool

参数

  • input_name (str) — 要生成的输入的名称。

返回

bool

一个布尔值,指定是否支持该输入。

检查 DummyInputGenerator 是否支持生成请求的输入。

现有的虚拟输入生成器

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 padding_side: str = 'right' **kwargs )

生成虚拟编码器文本输入。

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 padding_side: str = 'right' **kwargs )

生成虚拟解码器文本输入。

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 **kwargs )

生成虚拟 past_key_values 输入。

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

为 seq2seq 架构生成虚拟 past_key_values 输入。

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 **kwargs )

生成虚拟 bbox 输入。

optimum.utils.DummyVisionInputGenerator

< >

( task: str normalized_config: NormalizedVisionConfig batch_size: int = 2 num_channels: int = 3 width: int = 64 height: int = 64 **kwargs )

生成虚拟视觉输入。

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 )

< > 在 GitHub 上更新