CANN/ops-transformer quant_lightning_indexer_v2算子测试框架

📅 2026/7/15 9:39:24
CANN/ops-transformer quant_lightning_indexer_v2算子测试框架
quant_lightning_indexer_v2算子测试框架【免费下载链接】ops-transformer本项目是CANN提供的transformer类大模型算子库实现网络在NPU上加速计算。项目地址: https://gitcode.com/cann/ops-transformer功能说明基于pytest测试框架实现quant_lightning_indexer_v2算子的功能验证CPU侧复现算子功能用以生成golden数据NPU侧通过torch_npu进行算子直调获取实际数据精度对比进行CPU与NPU结果的精度对比验证算子功能双模式执行隔离支持直接pytest多进程执行和shell层进程隔离两种批量模式性能采集支持挂载msprof采集算子性能数据并汇总输出运行模式切换支持eager直接调用和graphtorch.compile torchair两种算子调用模式当前实现范围参数限制数据格式:query_layoutBSND、TNDkey_layout: PA_BBND、BSND、TND数据类型:qk_dtype: FLOAT8_E4M3FN、INT8、HIFLOAT8dequant_dtype: FP32Ascend950、FP16Ascend910_93actual_seq_dtype: INT32运行模式:eager直接调用torch.ops.cann_ops_transformer.quant_lightning_indexergraph通过torch.compiletorchair后端编译执行需torchair支持环境配置前置要求1、 确认torch_npu为最新版本 2、 激活CANN包和自定义算子包 3、 graph模式需要安装torchair编译器后端custom包调用支持custom包调用文件结构pytest文件结构说明test_run.sh # 执行脚本支持single/batch两种命令batch_isolated_run.sh # 批量隔离执行脚本shell层进程隔离msprof性能采集quant_lightning_indexer_v2_golden.py # cpu侧算子golden实现quant_lightning_indexer_v2_acl_graph.py # graph模式torchair后端实现result_compare_method.py # cpu golden与npu输出精度对比collect_perf_data.py # msprof性能数据收集与汇总pytest.ini # 创建测试标记单用例测试test_quant_lightning_indexer_v2_single.py # pytest测试单用例运行主程序test_quant_lightning_indexer_v2_paramset.py # 单用例入参配置按芯片型号自动选择用例批量测试test_quant_lightning_indexer_v2_batch.py # 用例批量测试主程序并生成excel文件保存结果./batch/quant_lightning_indexer_v2_pt_loadprocess.py # 读取pt文件并调用算子获取npu输出./batch/quant_lightning_indexer_v2_pt_save.py # 读取excel表格批量生成用例pt文件./batch/replace_path.py # test_quant_lightning_indexer_v2_batch.py占位符替换架构说明single 模式qliv2_output_acl_graph调用qliv2_output_single(is_batchTrue)即时生成数据 →torch.compiletorchair执行batch 模式qliv2_output_acl_graph_from_pt直接从 .pt 文件读取 pre-computed 数据 → 共用同一torch.compile路径跳过重复生成两路共用_qliv2_prepare_tensors_and_metadata和_qliv2_run_compiled_graph统一使用fullgraphFalse使用方法在pytest文件夹路径下执行运行测试用例单用例调测1、手动配置test_quant_lightning_indexer_v2_paramset.py的ENABLED_PARAMS参数2、执行指令bash test_run.sh single用例的批量生成与测试方式Atest_run.sh 批量执行1、excel路径下存放用例excel表格2、test_run.sh中设置读取的用例excel表格路径PATH1和pt文件存放路径PATH23、执行指令bash test_run.sh batch # eager模式默认 bash test_run.sh batch eager # 显式指定eager模式 bash test_run.sh batch graph # graph模式方式B手工分步执行1、生成pt文件python3 batch/quant_lightning_indexer_v2_pt_save.py excel/test_cases.xlsx pt_path2、替换测试脚本路径python3 batch/replace_path.py test_quant_lightning_indexer_v2_batch.py pt_path3、执行测试python3 -m pytest -rA -s test_quant_lightning_indexer_v2_batch.py -v -m ci -W ignore::UserWarning -W ignore::DeprecationWarning4、恢复测试脚本cp test_quant_lightning_indexer_v2_batch.py.bak test_quant_lightning_indexer_v2_batch.py方式C批量隔离执行推荐用于性能采集对每条用例单独拉起一个pytest进程实现进程间完全隔离避免单条用例崩溃影响其他用例。bash batch_isolated_run.sh ./pt_path 0 # 不采集性能 bash batch_isolated_run.sh ./pt_path 1 # 采集性能挂载msprof bash batch_isolated_run.sh ./pt_path 0 graph # graph模式 不采集性能 bash batch_isolated_run.sh ./pt_path 1 graph # graph模式 性能采集Excel 用例表格式excel/test_cases.xlsx需包含以下列Sheet1列名类型示例Testcase_Namestrtest_case_01batch_sizeint8q_seqint15k_seqint111q_t_sizeint8k_t_sizeint15q_head_numint64k_head_numint1head_dimint128block_sizeint512block_numint8qk_dtypestrFLOAT8_E4M3FN/INT8/HIFLOAT8dequant_dtypestrFP32/FP16actual_seq_dtypestrINT32cu_seqlens_qNone/strNone或[0, 1]cu_seqlens_kNone/strNone或[0, 1]seqused_qNone/strNone或[3,3,3,3,3,3,3,3]seqused_kstr[28,24,80,96,47,76,0,111]cmp_residual_kNone/strNone或[0,0,0,0,0,0,0,0]cmp_ratio1时必填max_seqlen_qint-1quant_modeint1/2/4layout_querystrBSND/TNDlayout_keystrPA_BBNDsparse_countint512sparse_modeint0/3query_datarangestr[-448,448]key_datarangestr[-20,20]weights_datarangestr[-123,123]q_scale_datarangestr[0,255]k_scale_datarangestr[0,65504]cmp_ratioint1/4return_valueint0/1output_idx_offsetNone/strNone或列表字符串注意事项dequant_dtypeAscend950仅支持FP32Ascend910_93支持FP16cmp_ratio 1且sparse_mode ! 0时cmp_residual_k必填长度batch_size的列表return_value1时output_idx_offset需提供有效值Ascend910_93要求quant_mode2输出文件文件说明result.xlsx测试结果精度、参数等result_perf.xlsx测试结果 性能数据仅msprof模式batch_summary.log批量执行详细日志batch_fail_list.log失败用例清单PROF_*/msprof性能原始数据目录【免费下载链接】ops-transformer本项目是CANN提供的transformer类大模型算子库实现网络在NPU上加速计算。项目地址: https://gitcode.com/cann/ops-transformer创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考