分享

在笔记本电脑快速运行 DeepSeek R1

 若悟369 2025-01-25

DeepSeek R1[1]是一个功能强大且用途广泛的 AI 模型,它凭借先进的推理能力、成本效益和开源可用性向 OpenAI 等老牌企业发起了挑战。虽然它有一些局限性,但其创新的方法和强大的性能使其成为开发人员、研究人员和企业的宝贵工具。对于那些有兴趣探索其功能的人来说,该模型及其精简版本可以在 Hugging Face 和 GitHub 等平台上获得。

在笔记本电脑快速运行 DeepSeek R1

由受 GPU 限制的中国团队训练,它在数学、编码甚至一些相当复杂的推理方面表现出色。最有趣的是,它是一个“精简”模型,这意味着它比它所基于的巨型模型更小、更高效。这很重要,因为它使人们在实际使用和构建它时更加实用。

本文我们将介绍

  • 如何在自己的设备上运行开源 DeepSeek 模型
  • 如何使用最新的 DeepSeek 模型创建与 OpenAI 兼容的 API 服务

我们将使用 LlamaEdge[2](Rust + Wasm 技术栈)来开发和部署这个模型的应用程序。无需安装复杂的 Python 包或 C++ 工具链[3]!了解我们选择这项技术的原因[4]

在自己的设备上运行 DeepSeek-R1-Distill-Llama-8B 模型

第一步: 通过以下命令行安装WasmEge[5]

curl -sSf https://raw./WasmEdge/WasmEdge/master/utils/install_v2.sh | bash -s -- -v 0.14.1

第二步:下载量化过的DeepSeek-R1-Distill-Llama-8B-GGUF[6]模型文件。 这可能需要一定时间,因为模型的大小为 5.73 GB。

curl -LO https:///second-state/DeepSeek-R1-Distill-Llama-8B-GGUF/resolve/main/DeepSeek-R1-Distill-Llama-8B-Q5_K_M.gguf`

第三步:下载 LlamaEdge API 服务器应用程序。它也是一个跨平台的便可移植的 Wasm 应用程序,可以在许多 CPU 和 GPU 设备上运行。

curl -LO https://github.com/LlamaEdge/LlamaEdge/releases/latest/download/llama-api-server.wasm

第四步: 下载chatbot UI,以便在浏览器中与 DeepSeek-R1-Distill-Llama-8B 模型进行交互。

curl -LO https://github.com/LlamaEdge/chatbot-ui/releases/latest/download/chatbot-ui.tar.gztar xzf chatbot-ui.tar.gzrm chatbot-ui.tar.gz

接下来,使用以下命令行为模型启动 LlamaEdge API 服务器。

wasmedge --dir .:. --nn-preload default:GGML:AUTO:DeepSeek-R1-Distill-Llama-8B-Q5_K_M.gguf \ llama-api-server.wasm \ --prompt-template llama-3-chat \ --ctx-size 8096

然后,打开浏览器访问 http://localhost:8080[7] 开始聊天!

或者可以向模型发送 API 请求。

curl -X POST http://localhost:8080/v1/chat/completions \  -H 'accept:application/json' \  -H 'Content-Type: application/json' \  -d '{'messages':[{'role':'system', 'content': 'You are a helpful assistant.'}, {'role':'user', 'content': 'What is the capital of France?'}], 'model': 'DeepSeek-R1-Distill-Llama-8B'}'  {'id':'chatcmpl-68158f69-8577-4da2-a24b-ae8614f88fea','object':'chat.completion','created':1737533170,'model':'default','choices':[{'index':0,'message':{'content':'The capital of France is Paris.\n</think>\n\nThe capital of France is Paris.<|end▁of▁sentence|>','role':'assistant'},'finish_reason':'stop','logprobs':null}],'usage':{'prompt_tokens':34,'completion_tokens':18,'total_tokens':52}}

为 DeepSeek-R1-Distill-Llama-8B 创建与 OpenAI 兼容的 API 服务

LlamaEdge 是轻量级的,不需要守护进程或 sudo 进程即可运行。它可以轻松嵌入到您自己的应用程序中!通过支持聊天和 embedding 模型,LlamaEdge 可以成为本地计算机上应用程序内部的 OpenAI API 替代品!

接下来,我们将展示如何为 DeepSeek-R1 模型以及 embedding 模型启动完整的 API 服务器。API 服务器将具有 chat/completions embeddings 端点。除了上一节中的步骤之外,我们还需要:

第五步:下载 embedding 模型。

curl -LO https:///second-state/Nomic-embed-text-v1.5-Embedding-GGUF/resolve/main/nomic-embed-text-v1.5.f16.gguf

然后,我们可以使用以下命令行启动具有聊天和 embedding 模型的 LlamaEdge API 服务器。更详细的说明,请查看文档——启动 LlamaEdge API 服务[8]

wasmedge --dir .:. \   --nn-preload default:GGML:AUTO:DeepSeek-R1-Distill-Llama-8B-Q5_K_M.gguf \   --nn-preload embedding:GGML:AUTO:nomic-embed-text-v1.5.f16.gguf \   llama-api-server.wasm -p llama-3-chat,embedding \     --model-name DeepSeek-R1-Distill-Llama-8B,nomic-embed-text-v1.5.f16 \     --ctx-size 8192,8192 \     --batch-size 128,8192 \     --log-prompts --log-stat

最后,可以按照这些教程将 LlamaEdge API 服务器作为 OpenAI 的替代与其他 Agent 框架集成。具体来说,在你的应用或 Agent 配置中使用以下值来替换 OpenAI API。

Config option Base API URL http://localhost:8080/v1 --- --- 模型名称 (大模型) DeepSeek-R1-Distill-Llama-8B 模型名称(文本 embedding) nomic-embed

就是这样啦!立即访问 LlamaEdge 仓库并构建你的第一个 AI Agent!如果觉得有意思,请在此处为我们的repo[9]加注星标。在运行此模型时有任何问题,也可以请前往该 repo 提出问题或与我们预约演示,以跨设备运行自己的 LLM!

参考资料

[1]

DeepSeek R1: https:///deepseek-ai/DeepSeek-R1-Distill-Llama-8B

[2]

LlamaEdge: https://link.zhihu.com/?target=https%3A//github.com/second-state/LlamaEdge/

[3]

工具链: https://zhida.zhihu.com/search?content_id=249066187&content_type=Article&match_order=1&q=%E5%B7%A5%E5%85%B7%E9%93%BE&zhida_source=entity

[4]

选择这项技术的原因: https://www./articles/wasm-runtime-agi/

[5]

WasmEge: https://github.com/WasmEdge/WasmEdge

[6]

DeepSeek-R1-Distill-Llama-8B-GGUF: https:///second-state/DeepSeek-R1-Distill-Llama-8B-GGUF/

[7]

http://localhost:8080: http://localhost:8080/

[8]

启动 LlamaEdge API 服务: https:///docs/user-guide/openai-api/intro/

[9]

repo: https://github.com/LlamaEdge/LlamaEdge

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多