当前位置: 首页 > article >正文

如何在 C++ 中运行 DeepSeek R1 LLM

DeepSeek R1 是 DeepSeek 公司开发的一款先进的开源大型语言模型。在这里我将尝试下载该模型(我们将使用一个小型的 DeepSeek-R1-Distill-Qwen-1.5B 模型)、转换该模型并通过 llama.cpp 在本地运行该模型。

1. 这里我使用的是 Linux Ubuntu-24.04

2. 创建我们的工作目录  

$ mkdir -p /workspace/llm/deepseek-r1
$ cd /workspace/llm/deepseek-r1/

3.下载模型

$ sudo apt install -y git-lfs
$ git lfs clone https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
- This downloads the model into "/workspace/llm/deepseek-r1/DeepSeek-R1-Distill-Qwen-1.5B/" directory.
- Alternatively, you can find other models from https://github.com/deepseek-ai/DeepSeek-R1

4.将模型转换为GGUF格式

$ git clone https://github.com/ggerganov/llama.cpp
$ cd llama.cpp/
$ sudo apt install -y python3-pip
$ pip3 install --break-system-packages numpy torch sentencepiece safetensors transformers
$ ./convert_hf_to_gguf.py /workspace/llm/deepseek-r1/DeepSeek-R1-Distill-Qwen-1.5B/
- This generates "/workspace/llm/deepseek-r1/DeepSeek-R1-Distill-Qwen-1.5B/DeepSeek-R1-Distill-Qwen-1.5B-F16.gguf" file.

5.编译llama.cpp

$ cd /workspace/llm/deepseek-r1/llama.cpp/
$ sudo apt install -y cmake
$ cmake -B build
$ cmake --build build

6. 运行

$ /workspace/llm/deepseek-r1/llama.cpp/build/bin/llama-cli -m /workspace/llm/deepseek-r1/DeepSeek-R1-Distill-Qwen-1.5B/DeepSeek-R1-Distill-Qwen-1.5B-F16.gguf -cnv

对话输出(示例)

> John is twice as old as Mark. In five years, the sum of their ages will be 65. How old is each person now?

<think>
I'll start by defining variables for the current ages of John and Mark. Let \( J \) represent John's current age and \( M \) represent Mark's current age.

According to the problem, John is twice as old as Mark. This gives me the equation:
\[ J = 2M \]

Additionally, in five years, the sum of their ages will be 65. This can be expressed as:
\[ (J + 5) + (M + 5) = 65 \]

Substituting the first equation into the second, I get:
\[ (2M + 5) + (M + 5) = 65 \]
Simplifying this:
\[ 3M + 10 = 65 \]
\[ 3M = 55 \]
\[ M = \frac{55}{3} \approx 18.33 \]

Now, substituting \( M \) back into the equation \( J = 2M \):
\[ J = 2 \times \frac{55}{3} = \frac{110}{3} \approx 36.67 \]

So, Mark is currently approximately 18.33 years old, and John is approximately 36.67 years old.
</think>

**Solution:**

Let's define the variables and set up the equations based on the problem statement.

1. **Let \( J \) represent John's current age and \( M \) represent Mark's current age.**

2. **Given that John is twice as old as Mark:**
   \[
   J = 2M
   \]

3. **In five years, the sum of their ages will be 65:**
   \[
   (J + 5) + (M + 5) = 65
   \]

4. **Substitute \( J = 2M \) into the second equation:**
   \[
   (2M + 5) + (M + 5) = 65
   \]

5. **Simplify and solve for \( M \):**
   \[
   3M + 10 = 65
   \]
   \[
   3M = 55
   \]
   \[
   M = \frac{55}{3} \approx 18.33 \text{ years}
   \]

6. **Find John's current age using \( J = 2M \):**
   \[
   J = 2 \times \frac{55}{3} = \frac{110}{3} \approx 36.67 \text{ years}
   \]

**Final Answer:**
- **Mark is currently approximately \(\boxed{18.33}\) years old.**
- **John is currently approximately \(\boxed{36.67}\) years old.**

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。 


http://www.kler.cn/a/594828.html

相关文章:

  • AES 简介 以及 C# 和 js 实现【加密知多少系列_3】
  • 用PaddleNLP为GPT-2模型制作FineWeb二进制预训练数据集
  • 【总结】常用API架构类型
  • R语言绘图:小提琴图
  • redis的lua脚本
  • python+requests实现的接口自动化测试
  • 剖析塔能科技:能源精准节能进阶核心驱动力
  • HarmonyOS Next~HarmonyOS应用开发工具:DevEco Testing
  • 阿里云CEN创建实验
  • 设计模式-单一职责
  • 手撕算法之`vector` 扩容、`string` 分割、链表翻转
  • HTTP和RPC的区别
  • 基于AT89C51单片机的自动贩卖机设计
  • CentOS 7.9 安装 Python 3.10 详细步骤及常见问题解决
  • 服务器部署Kong和Konga过程
  • 大数据在智能交通系统中的实时数据分析
  • Python环境依赖管理之终极指南:从隔离原理到深度维护
  • 30天搭建消防安全培训小程序
  • 从零开发数据可视化
  • 数据库故障排查流程