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

ollama离线部署+大语言模型

环境要求

  • Ubuntu >= 22.04
  • NVIDIA GPU

一.安装ollama客户端

资源来源

所有版本安装包安装脚本
https://github.com/ollama/ollama/releases/https://ollama.com/install.sh

安装

1. 下载资源

mkdir -p /root/ollama/
cd  /root/ollama
wget 'https://github.com/ollama/ollama/releases/download/v0.5.13/ollama-linux-amd64.tgz'
wget 'https://ollama.com/install.sh'

2. 修改安装脚本内容 : install.sh

#注释下面三行代码,并添加一行代码
#curl --fail --show-error --location --progress-bar \
#"https://ollama.com/download/ollama-linux-${ARCH}.tgz${VER_PARAM}" | \
#$SUDO tar -xzf - -C "$OLLAMA_INSTALL_DIR"  
$SUDO tar -xzf /root/ollama/ollama-linux-${ARCH}.tgz -C "$OLLAMA_INSTALL_DIR" 

3. 执行安装命令

bash install.sh

4. 检测安装

ollama --version

5. 修改环境变量

vim /etc/systemd/system/ollama.service

# 在原有的Environment下,添加一下内容
Environment="OLLAMA_HOST=0.0.0.0:11434" #允许其他ip地址请求访问
Environment="OLLAMA_NUM_PARALLEL=4" #并行处理请求的数量
Environment="OLLAMA_MAX_LOADED_MODELS=4" #同时加载的模型数量

sudo systemctl daemon-reload
systemctl stop ollama

6. 启动服务

ollama serve
// 或
sudo systemctl start ollama
// 或
nohup ollama serve &

7.关闭服务

service ollama stop

二.部署模型

资源来源

模型仓库地址
ModelScopehttps://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-14B-GGUF/files
Huggingfacehttps://huggingface.co

安装

1. 下载资源

  说明:将下载好的GGUF格式的大模型文件上传到服务器中,如果是多个分片需要合并。注意:ollama需要使用GGUF格式文件,如果模型仓库没有,需要自己转换。
模型下载链接
DeepSeek-R1-Distill-Qwen-7Bhttps://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-7B-GGUF/resolve/master/DeepSeek-R1-Distill-Qwen-7B-Q4_K_M.gguf
DeepSeek-R1-Distill-Qwen-14Bhttps://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-14B-GGUF/resolve/master/DeepSeek-R1-Distill-Qwen-14B-Q4_K_M.gguf
DeepSeek-R1-Distill-Qwen-32Bhttps://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-32B-GGUF/resolve/master/DeepSeek-R1-Distill-Qwen-32B-Q4_K_M.gguf
DeepSeek-R1https://modelscope.cn/models/lmstudio-community/DeepSeek-R1-GGUF/resolve/master/DeepSeek-R1-Q4_K_M-00001-of-00011.gguf
QwQ-32Bhttps://modelscope.cn/models/Qwen/QwQ-32B-GGUF/resolve/master/qwq-32b-q4_0-00001-of-00005.gguf
Qwen2.5-14B-Instructhttps://modelscope.cn/models/Qwen/Qwen2.5-14B-Instruct-GGUF/resolve/master/qwen2.5-14b-instruct-q4_0-00001-of-00003.gguf

2. 合并GGUF(可选)*

安装llama.cpp预编译工具

# 示例版本 b5162,请替换为最新版本号
wget https://github.com/ggerganov/llama.cpp/releases/download/b5162/llama-b5162-bin-ubuntu-vulkan-x64.zipmkdir -p ~/llama_tools   # 自定义工具存放目录
unzip -j llama-b5162-bin-ubuntu-vulkan-x64.zip 'build/bin/*' -d ~/llama_tools
chmod +x ~/llama_tools/*

合并GGUF分片

cd ~/llama_tools./llama-gguf-split --merge \~/models/DeepSeek-V3-Q3/DeepSeek-V3-0324-Q3_K_M-00001-of-00007.gguf \~/models/DeepSeek-V3-Q3/DeepSeek-V3-Q3_Merged.gguf// 参数说明:
// --merge:合并模式;
// 第一个参数:任意一个分片文件路径;
// 第二个参数:合并后完整 GGUF 文件的输出路径。

3. 创建Modelfile文件

参考:https://github.com/ollama/ollama/blob/main/docs/modelfile.md#format
例如:Qwen2.5-14B.Modelfile
# 文件内容为模型的路径
FROM /root/Qwen2.5-14B-Instruct.gguf
PARAMETER temperature 0.7
PARAMETER top_p 0.7
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ .Response }}<|im_end|>
"""
SYSTEM """You are a helpful assistant."""

4. 创建模型

使用ollama创建模型,model_name可自定义
ollama create <model_name> -f <path_to_Modelfile>

5. 查看模型

ollama list

三.GGUF格式转换(可选)*

1. 安装

执行以下命令安装llama.cpp环境
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
pip install -r requirements.txt

2. 生成GGUF

例如:qwen2_0.5b_instruct
// 如果不量化,保留模型的效果
python llama.cpp/convert_hf_to_gguf.py ./qwen2_0.5b_instruct --outtype f16 --verbose --outfile qwen2_0.5b_instruct_f16.gguf

// 量化
python llama.cpp/convert_hf_to_gguf.py ./qwen2_0.5b_instruct --outtype q8_0 --verbose --outfile qwen2_0.5b_instruct_q8_0.gguf

http://www.xdnf.cn/news/18832.html

相关文章:

  • AI-调查研究-62-机器人 机械臂五大应用场景详解:从焊接到手术,从农田到太空
  • 4步用代码拆解数学建模中的TOPSIS评价决策! ! !
  • Apache Commons Lang 3
  • 野火STM32Modbus主机读取寄存器/线圈失败(二)-解决CRC校验错误
  • uC/OS-III 队列相关接口
  • 数据分析与数据挖掘
  • 企业如何构建全面的高防IP防护体系?
  • Teams Workflows 业务流程搭建与Linux自动化运维拓展应用全解析
  • 状态设计模式
  • 构建面向人工智能决策的世界模型引擎所需的基本知识体系
  • 如何在GitHub找到10k+个stars的仓库
  • podman启动mongdb的container因为权限问题导致changing ownership和读取storage.bson失败的解决方法
  • CMake构建学习笔记20-iconv库的构建
  • 算法概述篇
  • 游戏空间划分技术
  • 日语学习-日语知识点小记-构建基础-JLPT-N3阶段(20):文法+单词第7回2
  • 广告推荐模型1:逻辑回归(Logistic Regression,LR)
  • 如何拯救一家濒临破产的科技公司?
  • 技术总结:AArch64架构下Jenkins Agent(RPM容器编译节点)掉线问题分析与排查
  • KubeBlocks for Oracle 容器化之路
  • 【RAGFlow代码详解-30】构建系统和 CI/CD
  • 微服务-28.配置管理-共享配置
  • poi生成word固定表格列宽
  • TensorFlow 面试题及详细答案 120道(61-70)-- 高级特性与工具
  • css3背景线性渐变:linear-gradient
  • 【密集目标检测】停车场车辆(车位)识别数据集:12k+图像,yolo标注
  • 04 网络信息内容安全--入侵检测技术
  • 依托边缘计算方案,移动云全面化解算力、效率、安全平衡难题
  • from中烟科技翼支付 面试题2
  • 高频面试题:说一下线程池吧?(线程池原理,核心参数,创建方式,应用场景都要说到才能让面试官心服口服)