CANN/cann-recipes-infer在线推理Benchmark测评 一、基于 EvalScope 的 Online 推理 Benchmark 测评【免费下载链接】cann-recipes-infer本项目针对LLM与多模态模型推理业务中的典型模型、加速算法提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-infer1. 概述本文档用于验证cann-recipes-infer仓库 OnlinePD 分离模式的在线推理能力及端到端可用性。Benchmark 测评目标基于EvalScope框架对在线推理服务进行 Benchmark 基准测试验证其推理精度达到预期标准。2. 测评准备本次测评采用EvalScope针对部署完成的 Online 推理服务进行精度验证。测试模型支持 Online 模式的模型Benchmark 数据集本次测评包含以下公开 BenchmarkBenchmark能力类型HumanEvalPython 代码生成MATH-500数学推理MMLU综合知识理解LongBench长上下文理解测评框架EvalScope支持的产品型号Atlas A3系列产品环境准备安装CANN软件包。本样例的编译执行依赖CANN开发套件包与CANN二进制算子包支持的CANN软件版本为CANN 9.0.0。请从软件包下载地址下载Ascend-cann-toolkit_${version}_linux-${arch}.run与Ascend-cann-A3-ops_${version}_linux-${arch}.run软件包并参考CANN安装文档进行安装。${version}表示CANN包版本号如9.0.0。${arch}表示CPU架构如aarch64、x86_64。安装Ascend Extension for PyTorchtorch_npu。Ascend Extension for PyTorchtorch_npu为支撑PyTorch框架运行在NPU上的适配插件本样例支持的Ascend Extension for PyTorch版本为v26.0.0PyTorch版本为2.8.0。请从软件包下载地址下载torch_npu-2.8.0.post4-cp311-cp311-manylinux_2_28_${arch}.whl安装包并参考torch_npu安装文档进行安装。${arch}表示CPU架构如aarch64、x86_64。下载项目源码并安装依赖的 Python 库。# 下载项目源码以master分支为例 git clone https://gitcode.com/cann/cann-recipes-infer.git # 安装依赖的python库仅支持python 3.11 cd cann-recipes-infer pip3 install -r ./models/qwen3_moe/requirements.txt配置样例运行所需环境信息。修改executor/scripts/set_env.sh中的如下字段IPs配置所有节点的IP按照rank id排序多个节点的 IP 通过空格分开例如(xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx)。cann_path: CANN软件包安装路径例如/usr/local/Ascend/ascend-toolkit/latest。说明HCCL相关配置如HCCL_SOCKET_IFNAME、HCCL_OP_EXPANSION_MODE可以参考集合通信文档并在executor/scripts/function.sh中自定义配置。安装 EvalScope。安装pip install evalscope1.8.0验证evalscope --version可选组件功能安装命令说明Visualizationpip install evalscope[service]1.8.0Benchmark 结果可视化Sandboxpip install evalscope[sandbox]1.8.0HumanEval 必需说明本样例中默认使用evalscope1.8.0其中evalscope[service]为可选组件。HumanEval 涉及代码执行必须安装 Sandbox 环境。二、Online 推理服务部署本样例对 Qwen3-235B-A22B 和 Qwen3-8B 进行benchmark测评。两个模型的推理部署和测评流程基本一致本文后续关于推理部署和测评流程的介绍均以Qwen3-235B-A22B为例。1. 配置模型 YAMLOnline 推理所需的配置文件位于models/qwen3_moe/config/qwen3_moe_pd/首次使用时请将 YAML 文件中的model_path修改为模型权重所在路径例如model_path: /data/models/Qwen3-235B-A22B更多 YAML 参数说明请参考YAML 参数说明。默认配置对于以下 Benchmark可直接使用models/qwen3_moe/config/qwen3_moe_pd目录下提供的默认配置HumanEvalMATH-500MMLU无需额外修改其他参数。LongBench 配置LongBench 包含大量长上下文任务输入长度可达到数万甚至超过百万 Token。为了支持长上下文推理需要调整 Prefill 与 Decode 的调度参数。Prefill 配置修改prefill.yaml中的相关配置model_config: model_name: qwen3_moe model_path: /data/models/Qwen3-235B-A22B exe_mode: eager enable_profiler: False with_ckpt: True enable_cache_compile: False parallel_config: world_size: 16 attn_tp_size: 16 moe_tp_size: 16 embed_tp_size: 16 lmhead_tp_size: 16 scheduler_config: batch_size: 4 max_prefill_tokens: 102400 max_new_tokens: 16 mem_fraction_static: 0.57Decode 配置修改decode.yaml中的相关配置model_config: model_name: qwen3_moe model_path: /data/models/Qwen3-235B-A22B exe_mode: ge_graph enable_profiler: False with_ckpt: True enable_cache_compile: False parallel_config: world_size: 16 attn_tp_size: 16 moe_tp_size: 16 embed_tp_size: 16 lmhead_tp_size: 16 scheduler_config: batch_size: 8 max_prefill_tokens: 102400 max_new_tokens: 8192 mem_fraction_static: 0.85说明Qwen3-235B-A22B 默认支持的最大上下文长度max_position_embeddings为40960。为支持 LongBench 的长上下文评测需要将模型目录下config.json中的max_position_embeddings修改为131072否则超长输入会因超过模型上下文长度限制而无法完成推理。2. 启动 Online 服务Prefill 节点bash executor/scripts/infer.sh \ --model qwen3_moe \ --mode online \ --pd-role prefillDecode 节点bash executor/scripts/infer.sh \ --model qwen3_moe \ --mode online \ --pd-role decode3. 服务验证Online 服务启动后Router 默认部署在Prefill 节点。支持 OpenAI Compatible API/v1/completions/v1/chat/completions示例curl -X POST http://localhost:8000/v1/chat/completions \ -H Content-Type: application/json \ -d { model:default, messages:[ { role:user, content:hello } ], max_tokens:10 }若接口能够正常返回推理结果则说明 Online 服务已部署成功可继续进行 Benchmark 测评。三、EvalScope Benchmark 测评1. Benchmark 测试说明本样例未额外设置采样参数生成时均使用 infer 仓的默认采样参数配置。1.1 HumanEval / MATH-500 / MMLU 评测EvalScope使用 EvalScope 对 HumanEval、MATH-500 和 MMLU 数据集进行评测# 参数说明 # datasets选择测试的数据集本样例可选值humaneval、math_500、mmlu # sandbox是否启用 Sandbox仅 HumanEval 测试时需要设置为 true evalscope eval \ --model Qwen/Qwen3-235B-A22B \ --api-url http://localhost:8000/v1 \ --datasets humaneval \ --sandbox {enabled: true} \ --eval-batch-size 32 \ --generation-config {max_tokens:65535} \ --limit 10 # 正式评测时请删除该参数1.2 LongBench 评测EvalScopeLongBench 为长上下文测评任务根据 LongBench 论文及其代码仓中的 LongBench/pred.py 实现需要对输入进行中间截断处理。因此本示例参考 EvalScope 自定义模型评测 方式对 LongBench 输入进行中间截断预处理后再调用模型完成评测。相关脚本位于benchmark/evalscope_scripts/eval_longbench.py执行方式如下python eval_longbench.py \ --model-name Qwen/Qwen3-235B-A22B \ --base-url http://localhost:8000/v1/chat/completions \ --model-path /data/models/Qwen3-235B-A22B \ --max-prefill-tokens 102400 \ --max-tokens 8192 \ --limit 10 # 正式评测时请删除该参数2. Benchmark 结果Benchmark能力类型Qwen3-235B-A22B 得分Qwen3-8B 得分HumanEvalPython 代码生成92.2485.37MATH-500数学推理88.6782.40MMLU综合知识理解87.3777.56LongBench长上下文理解44.2635.98【免费下载链接】cann-recipes-infer本项目针对LLM与多模态模型推理业务中的典型模型、加速算法提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-infer创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考