问小白 wenxiaobai
资讯
历史
科技
环境与自然
成长
游戏
财经
文学与艺术
美食
健康
家居
文化
情感
汽车
三农
军事
旅行
运动
教育
生活
星座命理

Ollama部署DeepSeek-R1 70B模型完整指南

创作时间:
作者:
@小白创作中心

Ollama部署DeepSeek-R1 70B模型完整指南

引用
CSDN
1.
https://m.blog.csdn.net/Code1994/article/details/145494672

Ollama是一个开源的LLM部署框架,支持多种大模型的快速部署和推理。DeepSeek-R1 70B是一个基于Llama架构的700亿参数量的开源大语言模型,通过Q5_K_M量化处理后体积压缩至49GB,非常适合在各种设备上运行。本文将详细介绍如何在Ollama平台上部署DeepSeek-R1 70B模型。

一、模型下载与准备

1. 获取GGUF格式模型文件

通过ModelScope平台下载量化后的模型文件(推荐Q5_K_M中等量化级别):

pip install modelscope
modelscope download --model unsloth/DeepSeek-R1-Distill-Llama-70B-GGUF DeepSeek-R1-Distill-Llama-70B-Q5_K_M.gguf --local_dir /DeepSeek-R1-Distill-Llama-70B-GGUF

技术说明:GGUF(GPT-Generated Unified Format)是专为LLM设计的跨平台格式,支持CPU/GPU混合推理,特别适合在苹果芯片设备或纯CPU环境运行。Q5_K_M量化在保持94%精度的同时,将模型体积压缩至49GB。

二、Ollama环境配置

1. 安装Ollama推理框架

参考官网ollama/ollama

curl -fsSL https://ollama.com/install.sh | sudo sh

2. 配置远程访问(可选)

参考ollama/docs/faq.md

如需通过其他设备访问,需修改服务配置:

sudo nano /etc/systemd/system/ollama.service

[Service]部分添加:

Environment="OLLAMA_HOST=0.0.0.0"
Environment="OLLAMA_ORIGINS=*"

刷新服务配置:

sudo systemctl daemon-reload
sudo systemctl restart ollama

三、模型配置文件编写

创建Modelfile配置文件:

# 这里填入gguf文件路径
FROM /home/DeepSeek-R1-Distill-Llama-70B-GGUF/DeepSeek-R1-Distill-Llama-70B-Q5_K_M.gguf
# 以下为模型模板配置
TEMPLATE """{{- if .System }}{{ .System }}{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1}}
{{- if eq .Role "user" }}<|User|>{{ .Content }}
{{- else if eq .Role "assistant" }}<|Assistant|>{{ .Content }}{{- if not $last }}<|end▁of▁sentence|>{{- end }}
{{- end }}
{{- if and $last (ne .Role "assistant") }}<|Assistant|>{{- end }}
{{- end }}"""
PARAMETER stop "<|begin▁of▁sentence|>"
PARAMETER stop "<|end▁of▁sentence|>"
PARAMETER stop "<|User|>"
PARAMETER stop "<|Assistant|>"
PARAMETER num_ctx 12800

参数解析

  • stop:设置对话终止符
  • num_ctx:扩展上下文窗口至12800 tokens

四、模型加载与运行

1. 创建Ollama模型实例

ollama create DeepSeek-R1-Distill-Llama-70B-Q5_K_M -f /home/DeepSeek-R1-Distill-Llama-70B-GGUF/Modelfile

2. 验证模型列表

ollama list
# 预期输出
NAME                                           ID              SIZE     MODIFIED
DeepSeek-R1-Distill-Llama-70B-Q5_K_M:latest    dd7ae729f6fc    49 GB    46 minutes ago

3. 启动模型服务

ollama run DeepSeek-R1-Distill-Llama-70B-Q5_K_M:latest

成功运行后将进入交互式命令行界面。

五、远程访问验证

访问http://{服务器IP}:11434/,出现以下界面即表示服务正常运行:

Ollama服务状态

六、高级应用场景

现在可通过以下方式接入模型:

  1. Open WebUI:搭建可视化聊天界面
  2. API集成:通过RESTful API对接应用程序
  3. LangChain:构建自动化AI工作流
© 2023 北京元石科技有限公司 ◎ 京公网安备 11010802042949号