base_benchmark
最后更新
modelconverter.platforms.base_benchmark用于设备上基准测试的平台无关脚手架。每个平台都使用自己的运行时测量吞吐量和延迟,但周围的工作是相同的:将模型解析为模型文件的路径或 URL,或 HubAI slug,针对每种配置运行一次,并报告收集到的数字。共享部分位于 Benchmark 中,每个平台的基准测试都继承自它。类
Benchmark
方法
init
Python
1def __init__(model_path: str):model_path(str): 模型文件的本地路径或 URL,以支持的扩展名之一结尾,或 HubAI 模型 slug,格式为[team_name/]model_name:variant[:model_instance]。URL 会首先下载。
ValueError: 如果model_path既不是支持的模型文件,也不是 HubAI 上可用模型的 slug。
benchmark
Python
1def benchmark(configuration: Configuration) -> Result:configuration(Configuration): 用于基准测试的选项。
Result: 测量的指标。必须包含"fps"条目,并且可以包含"latency"条目。
print_results
Python
1def print_results(results: list[tuple[Configuration, Result]]):results(list[tuple[Configuration, Result]]): 要打印的配置/结果对。不能为空。
run
Python
1def run(full: bool = True, save: bool = False, **kwargs: ConfigValue):full(bool): 如果为True,则对 all_configurations 中的每个配置进行基准测试。如果为False,则仅对 default_configuration 进行基准测试。save(bool): 如果为True,则结果除了打印之外还会写入 CSV 文件。**kwargs(ConfigValue): 单个配置选项的覆盖。具有非None默认值的选项的覆盖将被转换为该默认值的类型,除非默认值为布尔值。在完整运行中,覆盖仅应用于未自行设置选项的配置。
save_results
Python
1def save_results(results: list[tuple[Configuration, Result]]):<model_name>_benchmark_results.csv,并写入当前工作目录。嵌套的 power 列首先拆分为 power_system 和 power_processor。参数results(list[tuple[Configuration, Result]]): 要保存的配置/结果对。不能为空。
属性
all_configurations
default_configuration
model_name
model_path
函数
get_input_fps
Python
1def get_input_fps(configuration: Configuration) -> float:-1 允许基准测试在没有速率限制的情况下运行。否则,该值必须是正的有限数字。get_option
Python
1def get_option(configuration: Configuration, key: str, option_type: type[OptionT]) -> OptionT:configuration(Configuration): 单个基准测试运行的选项。key(str): 选项的名称。option_type(type[OptionT]): 选项的必要类型。
OptionT: 选项的值。
TypeError: 如果选项缺失或类型不同。
get_optional_option
Python
1def get_optional_option(configuration: Configuration, key: str, option_type: type[OptionT]) -> OptionT | None:configuration(Configuration): 单个基准测试运行的选项。key(str): 选项的名称。option_type(type[OptionT]): 选项的必要类型。
OptionT | None: 选项的值,如果未设置则为None。
TypeError: 如果选项类型不同。