---
title: DeepSeek-R1-Distill-Llama-8B-模型库-ModelZoo-昇腾社区
description: DeepSeek-R1-Distill-Llama-8B是DeepSeek AI从DeepSeek-R1模型中蒸馏出来的Llama模型，比经过强化学习训练出来的小型稠密模型拥有更好的推理能力。
keywords: DeepSeek,Distill,Llama,模型库,ModelZoo,昇腾社区,Usage,权重
url: https://www.hiascend.com/software/modelzoo/models/detail/8625241d99c64b528f1ff4dba7defb26
section: (其他)
---

# DeepSeek-R1-Distill-Llama-8B-模型库-ModelZoo-昇腾社区

URL: https://www.hiascend.com/software/modelzoo/models/detail/8625241d99c64b528f1ff4dba7defb26
描述: DeepSeek-R1-Distill-Llama-8B是DeepSeek AI从DeepSeek-R1模型中蒸馏出来的Llama模型，比经过强化学习训练出来的小型稠密模型拥有更好的推理能力。
关键词: DeepSeek,Distill,Llama,模型库,ModelZoo,昇腾社区,Usage,权重

ModelZoo主页

主页 [了解详情](https://www.hiascend.com/software/modelzoo)大模型 [了解详情](https://www.hiascend.com/software/modelzoo/big-models)模型库 [了解详情](https://www.hiascend.com/software/modelzoo/models)工具库 [了解详情](https://www.hiascend.com/software/modelzoo/tools)权重库 [了解详情](https://www.hiascend.com/software/modelzoo/datasets)ModelShow [了解详情](https://www.hiascend.com/software/modelzoo/modelshow)DeepSeek专区HOT [了解详情](https://www.hiascend.com/developer/deepseek)文档中心 [了解详情](https://www.hiascend.com/document/detail/zh/ModelZoo/Documentation/overview/overview_0001.html)论坛交流 [了解详情](https://www.hiascend.com/forum/forum-0140120119986591009-1.html)

主页 [了解详情](https://www.hiascend.com/software/modelzoo)大模型 [了解详情](https://www.hiascend.com/software/modelzoo/big-models)模型库 [了解详情](https://www.hiascend.com/software/modelzoo/models)工具库 [了解详情](https://www.hiascend.com/software/modelzoo/tools)权重库 [了解详情](https://www.hiascend.com/software/modelzoo/datasets)ModelShow [了解详情](https://www.hiascend.com/software/modelzoo/modelshow)DeepSeek专区HOT [了解详情](https://www.hiascend.com/developer/deepseek)文档中心 [了解详情](https://www.hiascend.com/document/detail/zh/ModelZoo/Documentation/overview/overview_0001.html)论坛交流 [了解详情](https://www.hiascend.com/forum/forum-0140120119986591009-1.html)

模型库 [了解详情](https://www.hiascend.com/software/modelzoo/models)

DeepSeek-R1-Distill-Llama-8B

## DeepSeek-R1-Distill-Llama-8B

LLMPyTorch推理6870次浏览2025/12/29更新

5.0

获取源码

点击DeepSeek专区 [了解详情](https://www.hiascend.com/developer/deepseek)获取更多资源

DeepSeek-R1-Distill-Llama-8B

点击DeepSeek专区 [了解详情](https://www.hiascend.com/developer/deepseek)获取更多资源

查看模型源码

模型使用

版本信息

模型使用

版本信息

...

# DeepSeek-R1-Distill-Llama-8B

## 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-8B is one of them.

## 权重

权重下载

- DeepSeek-R1-Distill-Llama-8B [了解详情](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-8B/tree/main)

## 加载镜像

前往昇腾社区/开发资源 [了解详情](https://www.hiascend.com/developer/ascendhub/detail/af85b724a7e5469ebd7ea13c3439d48f)下载适配DeepSeek-R1-Distill-Llama-8B的镜像包：1.0.0-800I-A2-py311-openeuler24.03-lts或1.0.0-300I-Duo-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-8B模型至少需要`1台Atlas 800I A2服务器`或者`1台插1张Atlas 300I DUO卡的服务器`
- 在使用Atlas 300I DUO推理卡部署模型时，需要修改权重目录下的config.json文件，"torch_dtype"字段改为"float16"
- 支持TP=1/2/4/8推理

## 新建容器

目前提供的MindIE镜像预置了DeepSeek-R1-Distill-Llama-8B模型推理脚本，无需再额外下载模型适配代码，直接新建容器即可。

如果您使用的是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
```

更多镜像使用信息请参考官方镜像仓库文档 [了解详情](https://gitee.com/ascend/ascend-docker-image/tree/dev/mindie#%E5%90%AF%E5%8A%A8%E5%AE%B9%E5%99%A8)。

## 进入容器

```
docker exec -it ${容器名称} bash
```

## 量化权重生成

### Atlas 800I A2 w8a8量化

- 生成量化权重依赖msModelSlim工具，安装方式见此README [了解详情](https://gitee.com/ascend/msit/tree/master/msmodelslim)
- 量化权重统一使用${ATB_SPEED_HOME_PATH}/examples/convert/model_slim/quantifier.py脚本生成，以下提供Llama模型量化权重生成快速启动命令
- W8A8量化权重请使用以下指令生成

- 注意该量化方式仅支持在Atlas 800I A2服务器上运行

```
# 设置CANN包的环境变量
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 虚拟内存
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:False
# 进入atb-models目录
cd ${ATB_SPEED_HOME_PATH}
# DeepSeek-R1-Distill-Llama-8B量化，有回退层，antioutlier使用m1算法配置，使用min-max量化方式，校准数据集使用50条BoolQ数据，在NPU上进行运算
bash examples/models/llama3/generate_quant_weight.sh -src {浮点权重路径} -dst {W8A8量化权重路径} -type llama3.1_8b_w8a8
```

### Atlas 300I DUO稀疏量化

Step 1 生成W8A8S量化权重

- 注意该量化方式仅支持在Atlas 300I DUO卡上运行
- 修改模型权重config.json中`torch_dtype`字段为`float16`
- 生成量化权重依赖msModelSlim工具，安装方式见此README [了解详情](https://gitee.com/ascend/msit/tree/master/msmodelslim)
- 进入到{msModelSlim工具路径}/msit/msmodelslim/example/Llama的目录`cd msit/msmodelslim/example/Llama`；

```
# 运行量化转换脚本
python3 quant_llama.py --model_path {浮点权重路径} --save_directory {W8A8S量化权重路径} --calib_file ../common/boolq.jsonl --w_bit 4 --a_bit 8 --fraction 0.011 --co_sparse True
```

Step 2 量化权重切分及压缩

- 该步骤需要在Atlas 300I DUO卡上运行

```
# 执行"jq --version"查看是否安装jq，若返回"bash：jq：command not found"，则依次执行"apt-get update"和"apt install jq"
jq --version
```

```
export IGNORE_INFER_ERROR=1
# 进入atb-models目录
cd ${ATB_SPEED_HOME_PATH}
# 运行切分及压缩脚本
torchrun --nproc_per_node {TP数} -m examples.convert.model_slim.sparse_compressor --model_path {W8A8S量化权重路径} --save_directory {W8A8SC量化权重路径}
```

- TP数为tensor parallel并行个数
- 注意：若权重生成时以TP=2进行切分，则运行时也需以TP=2运行
- 示例

```
torchrun --nproc_per_node 2 -m examples.convert.model_slim.sparse_compressor --model_path /data1/weights/model_slim/Llama-8b_w8a8s --save_directory /data1/weights/model_slim/Llama-8b_w8a8sc
```

## 纯模型推理

### 对话测试

进入llm_model路径

```
cd $ATB_SPEED_HOME_PATH
```

执行对话测试

```
torchrun --nproc_per_node 2 \
         --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用例的4卡并行性能测试命令如下，

Atlas 800I A2:

```
bash run.sh pa_bf16 performance [[256,256]] 1 llama ${weight_path} 4
```

Atlas 300I Duo:

```
bash run.sh pa_fp16 performance [[256,256]] 1 llama ${weight_path} 4
```

注：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]],
...
"ModelDeployConfig":
{
"ModelConfig" : [
{
...
"modelName" : "llama",
"modelWeightPath" : "/data/datasets/DeepSeek-R1-Distill-Llama-8B",
"worldSize" : 4,
...
}

},
...
}
}
```

- 拉起服务化

```
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用户指南 [了解详情](https://www.hiascend.com/document/detail/zh/mindie/100/mindieservice/servicedev/mindie_service0001.html)

## 常见问题

1. 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，我们将及时审视并解答。

| 版本 | 更新时间 | 精度 | 处理器 | CANN版本 | 操作 |
| --- | --- | --- | --- | --- | ---|
| 1.0 | 2025/04/10 | BF16; FP16 | Ascend 910; Ascend 310 | CANN 8.0.0 | MindIE |

使用模型资源和服务前，请您仔细阅读并理解透彻《昇腾深度学习模型许可协议 3.0》 [了解详情](https://www.hiascend.com/legal/modelzoo_models_license)
