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
二.部署模型
资源来源
模型仓库 | 地址 |
---|---|
ModelScope | https://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-14B-GGUF/files |
Huggingface | https://huggingface.co |
安装
1. 下载资源
说明:将下载好的GGUF格式的大模型文件上传到服务器中,如果是多个分片需要合并。注意:ollama需要使用GGUF格式文件,如果模型仓库没有,需要自己转换。
模型 | 下载链接 |
---|---|
DeepSeek-R1-Distill-Qwen-7B | https://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-14B | https://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-32B | https://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-32B-GGUF/resolve/master/DeepSeek-R1-Distill-Qwen-32B-Q4_K_M.gguf |
DeepSeek-R1 | https://modelscope.cn/models/lmstudio-community/DeepSeek-R1-GGUF/resolve/master/DeepSeek-R1-Q4_K_M-00001-of-00011.gguf |
QwQ-32B | https://modelscope.cn/models/Qwen/QwQ-32B-GGUF/resolve/master/qwq-32b-q4_0-00001-of-00005.gguf |
Qwen2.5-14B-Instruct | https://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