GenAI-Perf 分析子命令#
analyze
子命令用于扫描 PA 或 GenAI-Perf 刺激,允许用户通过单个命令分析多个场景。为 artifacts 目录中分析的每个场景创建一个子目录,其中包含与等效 profile 命令相同的所有文件(输入刺激、输出 JSON 和 CSV)。此外,还会创建一个顶层 CSV 报告,其中汇总了所有运行场景的结果。
分析 CLI#
analyze
子命令使用与 profile
相同的 CLI 选项,以及以下附加选项,这些选项用于指定您希望扫描的刺激类型和范围
--sweep-type
- 您希望扫描的刺激类型#
当前支持的刺激值包括 batch_size
、concurrency
、request_rate
、input_sequence_length
和 num_dataset_entries
--sweep-range
- 刺激将扫描的范围#
这可以表示为 min:max
或 min:max:step
。如果未指定 step
,则我们假定范围为 2 的幂值的 min/max。例如,8:256
将扫描 8,16,32,64,128,256
--sweep-list
- 刺激将扫描的以逗号分隔的值列表#
CLI 示例#
genai-perf analyze -m <model> --sweep-type concurrency --sweep-range 1:256
这将扫描并发值 1、2、4、8、16、32、64、128 和 256
genai-perf analyze -m <model> --sweep-type request_rate --sweep-range 100:500:50
这将扫描请求速率,值为 100、150、…、450、500
genai-perf analyze -m <model> --sweep-type input_sequence_length --sweep-list 100,150,200,400
这将扫描 ISL,值为 100、150、200 和 400
Artifact 目录和摘要 CSV 报告#
与运行 profile
时一样,将为分析的每个场景创建一个 artifact 目录。artifact 目录的名称为:<model_name>-<service-kind>-<backend>-<sweep_type><sweep_value>
示例#
对于此命令
genai-perf analyze -m gpt2 --service-kind triton --backend vllm --sweep-type num_dataset_entries --sweep-range 100:200:50
将创建以下 artifact 目录
artifacts/gpt2-triton-vllm-num_dataset_entries100/
artifacts/gpt2-triton-vllm-num_dataset_entries150/
artifacts/gpt2-triton-vllm-num_dataset_entries200/
每个 artifact 目录都包含 inputs.json
、profile_export.json
和 profile_export_genai_perf.csv
,就像您为每个场景单独运行 profile
一样。
摘要报告 CSV#
在 CWD 中,将创建一个摘要报告 CSV (analyze_export_genai_perf.csv
)。在第一个表中,每行是一个不同的分析场景,而列显示 p99 性能指标。在第二个表中,行再次是分析的场景,而列是 p99 GPU 遥测指标。
示例摘要报告 CSV#
Config Name,Concurrency,ISL,Num Dataset Entries,p99 Time To First Token (ms),p99 Inter Token Latency (ms),p99 Request Latency (ms),p99 Output Sequence Length (tokens),Avg. Output Token Throughput (tokens/sec),Request Throughput (requests/sec)
gpt2_run_config_2,1,201,200,33.54,7.16,779.75,132.10,149.63,1.32
gpt2_run_config_1,1,201,150,33.13,7.29,778.62,126.16,147.93,1.32
gpt2_run_config_0,1,201,100,82.02,7.53,879.20,124.55,145.93,1.30
Config Name,GPU,p99 GPU Power Usage (W),p99 GPU Energy Consumption (MJ),p99 GPU Utilization (%),p99 GPU Memory Used (GB),Avg. GPU Power Limit (W),Avg. GPU Total Memory (GB)
gpt2_run_config_2,gpu0,64.46,1.73,20.00,22.63,280.00,25.77
gpt2_run_config_1,gpu0,64.49,1.73,20.00,22.63,280.00,25.77
gpt2_run_config_0,gpu0,63.09,1.72,20.00,22.63,280.00,25.77
检查点#
analyze
的一项新功能是能够保存和恢复先前运行的场景的结果。这通过读取 checkpoint.json
(位于 CWD 中)来完成。此检查点文件包含 GenAI-Perf 从先前运行的 analyze
中恢复其状态并跳过任何先前已分析的场景所需的所有信息。
示例#
genai-perf analyze -m gpt2 --service-kind triton --backend vllm --sweep-type num_dataset_entries --sweep-range 100:200:50
此命令将分析三个场景:num_dataset_entries 的值为 100、150 和 200。
在后续使用此命令的重新运行时
genai-perf analyze -m gpt2 --service-kind triton --backend vllm --sweep-type num_dataset_entries --sweep-range 100:300:50
前 3 个场景将不会被重新分析,您将看到以下消息
gpt2_run_config_0:num_dataset_entries100 found in checkpoint - skipping profiling...
gpt2_run_config_1:num_dataset_entries150 found in checkpoint - skipping profiling...
gpt2_run_config_2:num_dataset_entries200 found in checkpoint - skipping profiling...
注意:如果您想重新分析所有场景,请在运行 analyze 之前首先删除检查点文件(和 artifacts)。
读取检查点和使用 Results API#
对于那些想要处理 analyze
的结果的人,您现在除了使用 CSV 文件之外,还有另一个选择:GenAI-Perf 现在为您提供读取检查点文件并使用下面提供的 API 访问数据的选项。
Results、RunConfigs 和 Records 类#
Results 类保存 analyze
期间运行的所有场景,每个场景都分配了 RunConfig 类的实例。RunConfig 类保存有关此场景使用的 GenAI-Perf 和 PA 配置的信息,以及性能和 GPU 遥测指标。这些指标保存在 Record 类的实例中(每个捕获的指标一个 Record)。
总结一下
Results - RunConfigs 列表(每个场景一个)
RunConfig - 包含 GenAI-Perf 和 PA 配置信息,以及性能和 GPU 遥测 Records
Records - 包含测量的性能或遥测指标
Record 类#
Records 是 GenAI-Perf 用于在检查点中存储指标的类。GenAI-Perf 可以捕获的每种指标类型都有一个唯一的 Record。这些指标的完整列表可以在 genai-perf/genai_perf/record/types/
中找到。
每个 record 都包含一个唯一的标签,使用 API 时需要该标签才能访问 record 的值。例如,如果您想查找 p99 首个令牌延迟时间,您将使用:TimeToFirstTokenP99.tag
(在 time_to_first_token_p99.py
中找到)
Results API#
Results 类存储场景 (RunConfigs) 列表,并根据指标目标进行排序。要设置目标,您可以使用 set_gpu_metric_objectives
(用于 GPU 遥测指标)或 set_perf_metric_objectives
(用于性能指标)。
目标的格式如下
{<ModelName>: {<RecordTag>: <Weighting>}}
如果仅设置一个目标,则权重无关紧要(只需将其设置为 1),但您可以指定多个目标,并通过赋予更高的权重来偏向一个目标而不是另一个目标。
示例#
results.set_perf_metric_objectives({"gpt2": {TimetoFirstTokenP99.tag: 1}})
将目标设置为 p99 首个令牌延迟时间。
results.set_gpu_metric_objectives({"gpt2": {GPUPowerUsageP99.tag: 1}})
将目标设置为 p99 GPU 功耗
results.set_perf_metric_objectives({"gpt2": {TimetoFirstTokenAvg.tag: 1, InterTokenLatencyP90.tag: 3}})
设置目标,其中令牌间延迟(p90)与首个令牌延迟时间(平均值)的偏差比为 3:1
约束#
除了设置目标之外,您还可以设置约束,这些约束将过滤在使用 get_results_<passing/failing>_constriants
方法时返回的 Results。
约束使用 Model/RunConstraints 类设置。以下是如何设置约束以仅返回首个令牌延迟时间低于 10 毫秒的 RunConfigs 的示例
model_constraints = ModelConstraints({TimetoFirstTokenP99.tag: 10})
run_constraints = RunConstraints("gpt2": model_constraints)
results.set_constraints(run_constraints)
passing_results = results.get_results_passing_constraints()
RunConfig API#
RunConfig API 包含可以返回以下内容的方法
为此场景设置的 GenAI-Perf/PA 参数
所有或特定的 GPU 遥测指标
所有或特定的性能指标
以下是一些 RunConfig API 用法的示例
# Returns a dictionary of `{parameter_name: value}`
run_config.get_genai_perf_parameters()
run_config.get_perf_analyzer_parameters()
# Returns a dictionary of `{GpuId: GpuRecords}`
run_config.get_all_gpu_metrics()
# Returns a dictionary of `{ModelName: PerfRecords}`
run_config.get_all_perf_metrics()
# Returns a list of PerfRecords for the gpt2 model
run_config.get_model_perf_metrics("gpt2")
# Returns the PerfRecord for the Time-to-First Token (p99) latency for the gpt2 model
run_config.get_model_perf_metric("gpt2", TimeToFirstTokenP99.tag)
# Returns the value of Time-to-First Token (p99) latency for the gpt2 model
run_config.get_model_perf_metric_value("gpt2", TimeToFirstTokenP99.tag)
# Returns the value of Avg. GPU Power Usage for the GPU with ID gpu0
run_config.get_gpu_metric_value("gpu0", GPUPowerUsageAvg.tag)
示例 Python 代码#
以下是一些示例 python 代码,演示了如何读取检查点以及如何使用 API 访问数据
from genai_perf.checkpoint.checkpoint import Checkpoint
from genai_perf.config.input.config_command import ConfigCommand
from genai_perf.config.run.results import Results
from genai_perf.record.types.input_sequence_length_p99 import InputSequenceLengthP99
from genai_perf.record.types.time_to_first_token_p99 import TimeToFirstTokenP99
# Read in the Checkpoint
model_name = "gpt2"
config = ConfigCommand(model_names=[model_name])
checkpoint = Checkpoint(config)
results = checkpoint.results
# Sort results based on Time-to-First Token latency
results.set_perf_metric_objectives({model_name: {TimeToFirstTokenP99.tag: 1}})
# Create lists of ISL along with their corresponding Time-to-First token latency (sorted by lowest latency)
isl = []
ttftl = []
for run_config in results.run_configs:
isl.append = run_config.get_model_perf_metric_value(model_name, InputSequenceLengthP99.tag)
ttftl.append = run_config.get_model_perf_metric_value(model_name, TimeToFirstTokenP99.tag)