昇腾NPU上基于MindIE服务的AIME和MATH500测评方案

简介: 本文介绍了基于MindIE服务和lighteval工具对DeepSeek-R1类模型进行能力测评的方法。针对AIME 2024、AIME 2025、MATH-500和GPQA等数据集,通过在Atlas 800I A2硬件上部署MindIE服务,结合开源项目Open R1的评测方法完成测评。主要内容包括模型权重下载、MindIE服务化部署、lighteval安装与配置,以及使用openai模式进行测评的具体步骤。最终展示了AIME 2024和MATH-500的测评结果,并对比了DeepSeek官方数据。该方案适合需要准确评估带推理思维链模型性能的场景。

背景

当前对DeepSeek-R1此类带推理think思维链的模型进行模型能力测评缺乏一个较准确的方,MindIE当前不能对DeepSeek报告中提到的几个数据集(AIME 2024、AIME 2025、MATH-500、GPQA等)进行模型效果评测。
Open R1由huggingface出品,是当前最火的DeepSeek-R1全开源复现。我们可以参考Open R1项目的评测方法,基于lighteval进行评测。

约束条件

  • 硬件约束:本案例硬件信息为Atlas 800I A2 ,约束条件为模型在MindIE服务可成功部署即可。
  • MindIE版本:同上,模型可成功部署即可。
  • lighteval版本:本案例验证lighteval版本为commit-id:ed084813e0bd12d82a06d9f913291fdbee774905,新版本代码可能需自行验证。

    模型权重下载

# 安装modelscope
pip install modelscope -i https://pypi.tuna.tsinghua.edu.cn/simple/

# 使用modelscope下载权重
modelscope download --model deepseek-ai/DeepSeek-R1-Distill-Qwen-7B --local_dir ./DeepSeek-R1-Distill-Qwen-7B
AI 代码解读

MindIE服务化部署

镜像下载

下载链接:
https://www.hiascend.com/developer/ascendhub/detail/af85b724a7e5469ebd7ea13c3439d48f
AI 代码解读

启动容器

# 查看镜像
docker images

# 创建并启动容器
sudo docker run -it --name lighteval_test \
    --network=host --shm-size=128G \
    --privileged=true \
    --device=/dev/davinci_manager \
    --device=/dev/hisi_hdc \
    --device=/dev/devmm_svm \
    -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
    -v /usr/local/dcmi:/usr/local/dcmi \
    -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
    -v /usr/local/sbin:/usr/local/sbin \
    -v /etc/ascend_install.info:/etc/ascend_install.info \
    -v /home:/home \
    -v /tmp:/tmp \
    -v /data:/data \
    -v `pwd`:/workspace \
    -w /workspace \
    swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:2.0.RC1-800I-A2-py311-openeuler24.03-lts /bin/bash
AI 代码解读

环境变量

# 在容器中设置如下环境变量:
source /usr/local/Ascend/ascend-toolkit/set_env.sh
source /usr/local/Ascend/nnal/atb/set_env.sh
source /usr/local/Ascend/mindie/set_env.sh
source /usr/local/Ascend/atb-models/set_env.sh
AI 代码解读

启动MindIE服务

修改MindIE配置文件

cd /usr/local/Ascend/mindie/latest/mindie-service/conf
vim config.json

修改config.json的配置项:
修改"httpsEnabled"false,
修改"npuDeviceIds"[[0,1,2,3,4,5,6,7]],
修改"modelName""qwen_distill_7b"
修改"modelWeightPath"为/home/test/DeepSeek-R1-Distill-Qwen-7B
修改"worldSize"8

其它config.json的参考配置:
maxSeqlen为最大输入加输出长度,此处建议修改为40960
maxInputTokenLen:根据实际输入长度配置,此处建议8192
maxPrefillTokens:建议和maxSeqlen保持一致即可
maxIterTimes:由于带think思维链模型输出较长,建议设为32786
AI 代码解读

修改模型配置文件

vim /home/test/DeepSeek-R1-Distill-Qwen-7B/config.json
修改"torch_dtype": "float16",
AI 代码解读

修改模型路径权限

chmod -R 750 /home/test/DeepSeek-R1-Distill-Qwen-7B
AI 代码解读

启动MindIE服务

cd /usr/local/Ascend/mindie/latest/mindie-service/bin
./mindieservice_daemon
AI 代码解读

启动成功显示:

Daemon starts success!
AI 代码解读

MindIE服务测试

curl 127.0.0.1:1025/generate -d '{
"prompt": "What is deep learning?",
"max_tokens": 32,
"stream": false,
"do_sample":true,
"repetition_penalty": 1.00,
"temperature": 0.01,
"top_p": 0.001,
"top_k": 1,
"model": "qwen_distill_7b"
}'
AI 代码解读

注意:
上面curl语句中的1025端口与qwen_distill_7b 分别与/usr/local/Ascend/mindie/latest/mindie-service/conf/config.json 配置文件里的port和modelName对应

安装lighteval

python包安装(不推荐)

pip install lighteval
AI 代码解读

python包安装可能由于版本问题会和open-r1提供的评测脚本有代码冲突,建议选择通过源码安装

源码安装(推荐)

git clone https://github.com/huggingface/lighteval.git
cd lighteval
# 本次验证参考版本commit-id:ed084813e0bd12d82a06d9f913291fdbee774905
git checkout ed084813e0bd12d82a06d9f913291fdbee774905
pip install .
pip install .[math]
AI 代码解读

编写evaluate.py

参考Open R1项目的的src/open_r1/evaluate.py 准备好evaluate.py文件,用于自定义评测任务:

# Copyright 2025 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Custom evaluation tasks for LightEval."""

import random

from lighteval.metrics.dynamic_metrics import (
    ExprExtractionConfig,
    IndicesExtractionConfig,
    LatexExtractionConfig,
    multilingual_extractive_match_metric,
)
from lighteval.tasks.lighteval_task import LightevalTaskConfig
from lighteval.tasks.requests import Doc
from lighteval.utils.language import Language

latex_gold_metric = multilingual_extractive_match_metric(
    language=Language.ENGLISH,
    fallback_mode="first_match",
    precision=5,
    gold_extraction_target=(LatexExtractionConfig(),),
    # Match boxed first before trying other regexes
    pred_extraction_target=(ExprExtractionConfig(), LatexExtractionConfig(boxed_match_priority=0)),
    aggregation_function=max,
)

expr_gold_metric = multilingual_extractive_match_metric(
    language=Language.ENGLISH,
    fallback_mode="first_match",
    precision=5,
    gold_extraction_target=(ExprExtractionConfig(),),
    # Match boxed first before trying other regexes
    pred_extraction_target=(ExprExtractionConfig(), LatexExtractionConfig(boxed_match_priority=0)),
    aggregation_function=max,
)

gpqa_metric = multilingual_extractive_match_metric(
    language=Language.ENGLISH,
    gold_extraction_target=[IndicesExtractionConfig(prefix_for_extraction="NativeLetters")],
    pred_extraction_target=[IndicesExtractionConfig(prefix_for_extraction="NativeLetters")],
    precision=5,
)

def prompt_fn(line, task_name: str = None):
    """Assumes the model is either prompted to emit \\boxed{answer} or does so automatically"""
    return Doc(
        task_name=task_name,
        query=line["problem"],
        choices=[line["solution"]],
        gold_index=0,
    )

def aime_prompt_fn(line, task_name: str = None):
    return Doc(
        task_name=task_name,
        query=line["problem"],
        choices=[line["answer"]],
        gold_index=0,
    )

def gpqa_prompt_fn(line, task_name: str = None):
    """Prompt template adapted from simple-evals: https://github.com/openai/simple-evals/blob/83ed7640a7d9cd26849bcb3340125002ef14abbe/common.py#L14"""
    gold_index = random.randint(0, 3)
    choices = [line["Incorrect Answer 1"], line["Incorrect Answer 2"], line["Incorrect Answer 3"]]
    choices.insert(gold_index, line["Correct Answer"])
    query_template = "Answer the following multiple choice question. The last line of your response should be of the following format: 'Answer: $LETTER' (without quotes) where LETTER is one of ABCD. Think step by step before answering.\n\n{Question}\n\nA) {A}\nB) {B}\nC) {C}\nD) {D}"
    query = query_template.format(A=choices[0], B=choices[1], C=choices[2], D=choices[3], Question=line["Question"])

    return Doc(
        task_name=task_name,
        query=query,
        choices=["A", "B", "C", "D"],
        gold_index=gold_index,
        instruction=query,
    )

# Define tasks
aime24 = LightevalTaskConfig(
    name="aime24",
    suite=["custom"],
    prompt_function=aime_prompt_fn,
    hf_repo="HuggingFaceH4/aime_2024",
    hf_subset="default",
    hf_avail_splits=["train"],
    evaluation_splits=["train"],
    few_shots_split=None,
    few_shots_select=None,
    generation_size=32768,
    metric=[expr_gold_metric],
    version=1,
)
aime25 = LightevalTaskConfig(
    name="aime25",
    suite=["custom"],
    prompt_function=aime_prompt_fn,
    hf_repo="yentinglin/aime_2025",
    hf_subset="default",
    hf_avail_splits=["train"],
    evaluation_splits=["train"],
    few_shots_split=None,
    few_shots_select=None,
    generation_size=32768,
    metric=[expr_gold_metric],
    version=1,
)
math_500 = LightevalTaskConfig(
    name="math_500",
    suite=["custom"],
    prompt_function=prompt_fn,
    hf_repo="HuggingFaceH4/MATH-500",
    hf_subset="default",
    hf_avail_splits=["test"],
    evaluation_splits=["test"],
    few_shots_split=None,
    few_shots_select=None,
    generation_size=32768,
    metric=[latex_gold_metric],
    version=1,
)
gpqa_diamond = LightevalTaskConfig(
    name="gpqa:diamond",
    suite=["custom"],
    prompt_function=gpqa_prompt_fn,
    hf_repo="Idavidrein/gpqa",
    hf_subset="gpqa_diamond",
    hf_avail_splits=["train"],
    evaluation_splits=["train"],
    few_shots_split=None,
    few_shots_select=None,
    generation_size=32768,  # needed for reasoning models like R1
    metric=[gpqa_metric],
    stop_sequence=[],  # no stop sequence, will use eos token
    trust_dataset=True,
    version=1,
)

# Add tasks to the table
TASKS_TABLE = []
TASKS_TABLE.append(aime24)
TASKS_TABLE.append(aime25)
TASKS_TABLE.append(math_500)
TASKS_TABLE.append(gpqa_diamond)

# MODULE LOGIC
if __name__ == "__main__":
    print([t["name"] for t in TASKS_TABLE])
    print(len(TASKS_TABLE))
AI 代码解读

测评方式说明

lighteval 提供了几个主要的入口点来进行模型评估,但是在NPU设备上使用vllm和tgi模式可能还需要对代码进行适配,因此我们可以使用的就是accelerate 和endpoint openai两个模式。但是accelerate模型存在输出较短和推理速度较慢的问题,==因此推荐基于openai模式,并通过MindIE部署模型推理服务实现评测==。

使用openai模式测评(基于lighteval+MindIE服务)

lighteval也支持通过openai第三方库对模型推理服务进行评分,但当前评测框架没有对本地模型服务的情况进行适配,通过分析代码发现适配量不大,因此采用此模式对MindIE服务进行模型评测。

lighteval适配本地推理服务

查找lighteval安装路径

通过pip show lighteval找到lighteval安装路径
01_查找lighteval安装路径.png

修改openai_model.py

修改lighteval python安装包路径下“lighteval/models/endpoints/openai_model.py”代码:

评测命令

==说明:==

  • 下面OPENAI_BASE_URL需配置为服务地址,注意需保证服务可访问,可通过curl命令验证;OPENAI_API_KEY未使用,但是仍需配置,要求非空。
  • --custom-tasks 后填写前面自定义的evaluate.py文件路径

    配置环境变量

MODEL="/home/test/DeepSeek-R1-Distill-Qwen-7B"
MODEL_ARGS="$MODEL"
OUTPUT_DIR=./data/evals/$MODEL
export OPENAI_BASE_URL="http://127.0.0.1:1025/v1"
export OPENAI_API_KEY="test"
AI 代码解读

AIME 2024测评

TASK=aime24

lighteval endpoint openai $MODEL_ARGS "custom|$TASK|0|0" \
    --custom-tasks evaluate.py \
--output-dir $OUTPUT_DIR
AI 代码解读

MATH-500测评

TASK=math_500

lighteval endpoint openai $MODEL_ARGS "custom|$TASK|0|0" \
    --custom-tasks evaluate.py \
    --output-dir $OUTPUT_DIR
AI 代码解读

测评结果

AIME2024测评结果

04_AIME2024测评结果.png

MATH-500测评结果

05_MATH500测评结果.png

DeepSeek官方测评结果

06_DeepSeek官方测评结果.png

目录
打赏
0
0
0
0
2
分享
相关文章
飞桨x昇腾生态适配方案:00_整体方案介绍
本文详细介绍PaddlePaddle与NPU的适配工作,涵盖训练与推理支持、性能优化及离线推理方案。PaddleCustomDevice作为适配层,支持主流模型(详见飞桨-昇腾模型列表),多数性能媲美V100,部分调优模型接近0.8*A800。硬件适配主要针对A2芯片,A1兼容但310系列建议离线推理。提供常用模型仓链接及整体方案导览,包括环境准备、算子适配、性能调优和Paddle转ONNX/OM等内容。
122 0
【Shell 命令集合 文本编辑器 】Linux pico 编辑器使用指南
【Shell 命令集合 文本编辑器 】Linux pico 编辑器使用指南
229 1
vllm+vllm-ascend本地部署QwQ-32B
本指南介绍如何下载、安装和启动基于Ascend的vLLM模型。首先,可通过华为镜像或Hugging Face下载预训练模型;其次,安装vllm-ascend,支持通过基础镜像(如`quay.io/ascend/vllm-ascend:v0.7.3-dev`)或源码编译方式完成;最后,使用OpenAI兼容接口启动模型,例如运行`vllm serve`命令,设置模型路径、并行规模等参数。适用于大模型推理场景,需注意显存需求(如QwQ-32B需70G以上)。
1236 17
银河麒麟v10离线安装docker二进制包
银河麒麟v10离线安装docker二进制包
1653 0
|
4月前
|
在Docker上部署Ollama+AnythingLLM完成本地LLM Agent部署
通过以上步骤,您可以成功在Docker上部署Ollama和AnythingLLM,实现本地LLM Agent的功能。在部署过程中,确保环境和配置正确,以避免不必要的问题。希望本文能够帮助您顺利完成部署,并在本地环境中高效地使用LLM模型。
1457 8
Qwen3技术报告首次全公开!“混合推理模型”是这样炼成的
近日,通义千问Qwen3系列模型已开源,其技术报告也正式发布。Qwen3系列包含密集模型和混合专家(MoE)模型,参数规模从0.6B到235B不等。该模型引入了“思考模式”与“非思考模式”的动态切换机制,并采用思考预算机制优化推理性能。Qwen3支持119种语言及方言,较前代显著提升多语言能力,在多个基准测试中表现领先。此外,通过强到弱蒸馏技术,轻量级模型性能优异,且计算资源需求更低。所有Qwen3模型均采用Apache 2.0协议开源,便于社区开发与应用。
649 28
从零开始200行python代码实现LLM
本文从零开始用Python实现了一个极简但完整的大语言模型,帮助读者理解LLM的工作原理。首先通过传统方法构建了一个诗词生成器,利用字符间的概率关系递归生成文本。接着引入PyTorch框架,逐步重构代码,实现了一个真正的Bigram模型。文中详细解释了词汇表(tokenizer)、张量(Tensor)、反向传播、梯度下降等关键概念,并展示了如何用Embedding层和线性层搭建模型。最终实现了babyGPT_v1.py,一个能生成类似诗词的简单语言模型。下一篇文章将在此基础上实现自注意力机制和完整的GPT模型。
147 14
从零开始200行python代码实现LLM
一文讲透程序编排的核心方式:从表达式语言到并行化实践
高德的poi数据来源多种多样,处理流程也多种多样,但因流程相对固定,因此使用了流程化配置简化开发,使用表达式语言保证灵活性。为了加深对平台的理解,并帮助大家对编排有一定的了解,本文会以影响范围的视角去总结当前编排的方案。
104 13
一文讲透程序编排的核心方式:从表达式语言到并行化实践
解决安装flash-attn时的错误报告
记住,程序包安装问题就像个顽皮的谜题,得一步步解开,耐心是解决问题的钥匙,没有什么问题是一顿猛敲键盘解决不了的,如果有,那就两顿。
103 8
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问