如何在 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.**
如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。