跳到主要内容

deepseek

在 Neardi PI 3(RK3576 平台)上部署 DeepSeek-R1 推理模型

随着人工智能技术的不断发展,深度学习推理已成为开发智能应用的重要组成部分。本文将一步步指导您如何在 Neardi PI 3(基于 RK3576 芯片平台)上部署 DeepSeek-R1 模型,并使用 RKNPU(Rockchip NPU)进行高效推理。

系统环境

  • Neardi PI 3 (RK3576) 硬件配置:8GB 内存 + 64GB 存储

1. 本地部署 Ollama DeepSeek-R1

1.1 安装 Ollama

  • 方法一:通过终端安装
curl -fsSL https://ollama.com/install.sh | sh
  • 方法二:手动下载并安装软件包 如果您无法通过方法一安装,可以直接访问以下链接下载 arm64 版本并解压安装包: 下载 Ollama 安装包

1.2 运行 Ollama 服务

ollama start

启动 Ollama 推理服务,等待模型加载和初始化。

1.3 安装 DeepSeek-R1:8B 模型

./ollama run deepseek-r1:8b

下载需要一些时间。Ollama 的下载速度可能会自动降低;如果速度降至几百 KB/s,暂停并重新运行可以加快下载速度(已证实有效)。

1.4 安装成功

安装并运行后,当终端显示类似 >>> 的提示符时,您可以开始与模型交互。

1.5 运行 DeepSeek 推理

2. 使用 RKNPU 部署 DeepSeek-R1

2.1 模型下载

建议直接下载 Rockchip 转换好的模型。DeepSeek-R1-Distill-Qwen-1.5B 模型已经转换为 RK3576 可识别的格式。

RKLLM 模型下载,提取码:rkllm

在此处下载 DeepSeek-R1-Distill-Qwen-1.5B_W4A16_RK3576.rkllm 模型。

如果您需要自己转换模型,请参考 DeepSeek-R1-Distill-Qwen-1.5B_Demo 中的模型转换部分。

2.2 编译 llm_demo(可选)

git clone https://github.com/airockchip/rknn-llm

cd rknn-llm/examples/DeepSeek-R1-Distill-Qwen-1.5B_Demo/deploy

# 在 `build-linux.sh` 文件中,将 `GCC_COMPILER_PATH` 值更改为 `aarch64-linux-gnu`,否则编译将失败。
./build-linux.sh

2.3 运行 DeepSeek 推理

使用以下命令在 PI 3 (RK3576) 上运行 DeepSeek 模型推理:

export LD_LIBRARY_PATH=/home/neardi/rknn-llm/rkllm-runtime/Linux/librkllm_api/aarch64:$LD_LIBRARY_PATH
taskset f0 ./rknn-llm/examples/DeepSeek-R1-Distill-Qwen-1.5B_Demo/deploy/install/demo_Linux_aarch64/llm_demo DeepSeek-R1-Distill-Qwen-1.5B_W4A16_RK3576.rkllm 2048 4096

运行后,您将看到类似以下的输出:

rkllm init start
I rkllm: rkllm-runtime version: 1.1.4, rknpu driver version: 0.9.8, platform: RK3576

rkllm init success

********************** You can input the following questions corresponding to the number or custom input ********************

[0] A bag contains 5 red balls and 3 blue balls. What is the probability of drawing a blue ball?
[1] The number sequence: 1, 4, 9, 16, 25, …, what is the next number?
[2] Write a program to determine if a number is odd or even.

*************************************************************************

此时,您可以输入问题并从模型获取推理结果。