DeepSeek-R1-Distill-Llama-70B
Usage
Using the reasoning data generated by DeepSeek-R1, DeepSeek AI fine-tuned several dense models that are widely used in the research community, slightly changing their configs and tokenizers. DeepSeek-R1-Distill-Llama-70B is one of them.
权重
权重下载
加载镜像
前往昇腾社区/开发资源下载适配DeepSeek-R1-Distill-Llama-70B的镜像包:1.0.0-800I-A2-py311-openeuler24.03-lts
完成之后,请使用docker images
命令确认查找具体镜像名称与标签。
镜像中各组件版本配套如下:
组件 | 版本 |
---|---|
MindIE | 1.0.0 |
CANN | 8.0.0 |
PTA | 6.0.0 |
MindStudio | 7.0.0 |
HDK | 24.1.0 |
约束条件
- 部署DeepSeek-R1-Distill-Llama-70B模型至少需要
1台Atlas 800I A2服务器
- 支持TP=8推理
新建容器
目前提供的MindIE镜像预置了DeepSeek-R1-Distill-Llama-70B模型推理脚本,无需再额外下载模型适配代码,直接新建容器即可。
如果您使用的是root用户镜像(例如从Ascend Hub上取得),并且可以使用特权容器,请使用以下命令启动容器:
docker run -it -d --net=host --shm-size=1g \
--privileged \
--name <container-name> \
--device=/dev/davinci_manager \
--device=/dev/hisi_hdc \
--device=/dev/devmm_svm \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver:ro \
-v /usr/local/sbin:/usr/local/sbin:ro \
-v /path-to-weights:/path-to-weights:ro \
mindie:1.0.0-800I-A2-py311-openeuler24.03-lts bash
如果您希望使用自行构建的普通用户镜像,并且规避容器相关权限风险,可以使用以下命令指定用户与设备:
docker run -it -d --net=host --shm-size=1g \
--name <container-name> \
--device=/dev/davinci_manager \
--device=/dev/hisi_hdc \
--device=/dev/devmm_svm \
--device=/dev/davinci0 \
--device=/dev/davinci1 \
--device=/dev/davinci2 \
--device=/dev/davinci3 \
--device=/dev/davinci4 \
--device=/dev/davinci5 \
--device=/dev/davinci6 \
--device=/dev/davinci7 \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver:ro \
-v /usr/local/sbin:/usr/local/sbin:ro \
-v /path-to-weights:/path-to-weights:ro \
mindie:1.0.0-800I-A2-py311-openeuler24.03-lts bash
更多镜像使用信息请参考官方镜像仓库文档。
进入容器
docker exec -it ${容器名称} bash
量化权重生成
Atlas 800I A2 w8a8量化
生成量化权重依赖msModelSlim工具,安装方式见此README
进入到msit/msmodelslim/example/Llama的目录
cd msit/msmodelslim/example/Llama
;W8A8量化权重请使用以下指令生成
- 注意该量化方式仅支持在Atlas 800I A2服务器上运行
# 设置CANN包的环境变量
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 关闭虚拟内存
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:False
# 运行量化转换脚本
python3 quant_llama.py --model_path {浮点权重路径} --save_directory {W8A8量化权重路径} --calib_file ../common/boolq.jsonl --device_type npu --disable_level L5 --anti_method m4 --act_method 3
纯模型推理
对话测试
进入llm_model路径
cd $ATB_SPEED_HOME_PATH
执行对话测试
torchrun --nproc_per_node 8 \
--master_port 20037 \
-m examples.run_pa \
--model_path ${权重路径} \
--input_texts 'What is deep learning?' \
--max_output_length 20
性能测试
进入ModelTest路径
cd $ATB_SPEED_HOME_PATH/tests/modeltest/
运行测试脚本
bash run.sh pa_[data_type] performance [case_pair] [batch_size] ([prefill_batch_size]) [model_name] ([is_chat_model]) (lora [lora_data_path]) [weight_dir] ([trust_remote_code]) [chip_num] ([parallel_params]) ([max_position_embedding/max_sequence_length])
具体执行batch=1, 输入长度256, 输出长度256用例的8卡并行性能测试命令如下,
Atlas 800I A2:
bash run.sh pa_bf16 performance [[256,256]] 1 llama ${weight_path} 8
注:ModelTest为大模型的性能和精度提供测试功能。使用文档请参考
${ATB_SPEED_HOME_PATH}/tests/modeltest/README.md
服务化推理
- 打开配置文件
vim /usr/local/Ascend/mindie/latest/mindie-service/conf/config.json
- 更改配置文件
{
...
"ServerConfig" :
{
...
"port" : 1025, #自定义
"managementPort" : 1026, #自定义
"metricsPort" : 1027, #自定义
...
"httpsEnabled" : false,
...
},
"BackendConfig": {
...
"npuDeviceIds" : [[0,1,2,3,4,5,6,7]],
...
"ModelDeployConfig":
{
"ModelConfig" : [
{
...
"modelName" : "llama",
"modelWeightPath" : "/data/datasets/DeepSeek-R1-Distill-Llama-70B",
"worldSize" : 8,
...
}
]
},
...
}
}
- 拉起服务化
cd /usr/local/Ascend/mindie/latest/mindie-service/bin
./mindieservice_daemon
- 新建窗口测试(VLLM接口)
curl 127.0.0.1:1025/generate -d '{
"prompt": "What is deep learning?",
"max_tokens": 32,
"stream": false,
"do_sample":true,
"temperature": 0.6,
"top_p": 0.95,
"model": "llama"
}'
注: 服务化推理的更多信息请参考MindIE Service用户指南
常见问题
- ImportError: cannot import name 'shard_checkpoint' from 'transformers.modeling_utils'. 降低transformers版本可解决。
pip install transformers==4.46.3
pip install numpy==1.26.4
声明
- 本代码仓提到的数据集和模型仅作为示例,这些数据集和模型仅供您用于非商业目的,如您使用这些数据集和模型来完成示例,请您特别注意应遵守对应数据集和模型的License,如您因使用数据集或模型而产生侵权纠纷,华为不承担任何责任。
- 如您在使用本代码仓的过程中,发现任何问题(包括但不限于功能问题、合规问题),请在本代码仓提交issue,我们将及时审视并解答。