1. 模型下载

2. 开始转换hf模型为gguf,需要用|lama.cpp仓库的convert_hf_to_gguf.py脚本来转换

git clone https://github.com/ggerganov/llama.cpp.git
pip install -r llama.cpp/requirements.txt

3.执行转换

#不量化,保留模型的效果

python llama.cpp/convert_hf_to_gguf.py /mnt/workspace/.cache/modelscope/models/LLM-Research/Meta-Llama-3-8B-Instruct --outtype f16 --verbose --outfile Meta-Llama-3-8B-Instruct_f16.gguf

#需要量化(加速并有损失效果)

python llama.cpp/convert_hf_to_gguf.py /mnt/workspace/.cache/modelscope/models/LLM-Research/Meta-Llama-3-8B-Instruct --outtype q8_0 --verbose --outfile Meta-Llama-3-8B-Instruct_f16.gguf

4.启动ollama

nohup ollama serve &

5.创建Modelfile

# 基础模型:指定本地Llama 3 8B Instruct模型路径
FROM ./Meta-Llama-3-8B-Instruct_f16.gguf

# 模型参数配置(根据需求调整)
# 温度值:0~1,越低回答越严谨,越高越灵活
PARAMETER temperature 0.7
# 采样范围:0~1,控制回答多样性(0.8适合大多数场景)
PARAMETER top_p 0.8
# 重复惩罚:>1 防止重复生成,1.05为轻微惩罚
PARAMETER repeat_penalty 1.05
# 停止符:遇到这些字符时停止生成(适配Llama 3格式)
PARAMETER stop <|im_end|>

# 对话模板(严格遵循Llama 3的<|im_start|>格式)
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 """
你是一个由Llama 3驱动的智能助手,擅长清晰、准确地回答各类问题。
- 回答需符合中文表达习惯,简洁易懂;
- 遇到不确定的内容,会明确说明“不确定”,不编造信息;
- 支持多轮对话,会结合上下文理解用户需求。
"""

6.创建自定义模型

ollama create Meta-Llama-3-8B-Instruct_f16  --file ./Modelfile

7.运行模型

 ollama run Meta-Llama-3-8B-Instruct_f16

8.open-webui界面集成使用

pip install open-webui
open-webui serve

访问端口 8080

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐