Llama微调以及Ollama部署

1 Llama微调

在基础模型的基础上,通过一些特定的数据集,将具有特定功能加在原有的模型上。

1.1 效果对比

  • 特定数据集
  • 未使用微调的基础模型的回答
  • 使用微调后的回答

1.2 基础模型

基础大模型我选择Mistral-7B-v0.3-Chinese-Chat-uncensored,

模型文件可以在HuggingFace 模型

1.3 选择数据集

微调大模型要想获得比较好的效果,拥有高质量的数据集是关键。可以选择用网上开源的,或者是自己制作。以中文数据集弱智吧为例,约1500条对话数据,数据集可以从HuggingFace 数据集

1.4 训练lora模型并与基础模型进行合并

新建一个merge.py文件,将基础模型和lora模型合并为一个新的模型文件

复制代码
执行merge.py,需要传入的参数(改成自己的):
--base_model
基础模型路径
--lora_model
微调的lora模型路径
--output_dir
合并后模型的输出路径

1.5 量化模型

利用llama.cpp进行量化模型.

  • 1.安装CMAKE下载llama.cpp源码
    git clone https://github.com/ggerganov/llama.cpp.git
    cd llama.cpp
  • 2.安装依赖
    pip install -r requirements/requirements-convert-hf-to-gguf.txt
    cmake -B build
    cmake --build build --config Release
  • 3.执行转换脚本,将safetensors转换为gguf文件,便于量化
    convert-hf-to-gguf.py 合并后模型的位置 --outtype f16 --outfile 转换后模型的位置my_llama3.gguf
  • 4.对转后的文件进行量化操作。
    llama.cpp所在位置\llama.cpp\build\bin\Release quantize.exe 转换后模型的路径 量化后模型的位置quantized_model.gguf q4_0

至此,llama微调后的模型操作完毕,可以直接使用。

2.Ollama部署

Ollama安装地址

2.1 部署现有的模型

打开Ollama,找到目录中现有的模型,使用ollama run llama3.2,来使用现有模型。

2.2 使用微调模型

  • 1.在上述已量化好的模型quantized_model.gguf的目录中新建Modelfile文件

    FROM 量化好的模型路径
    TEMPLATE "[INST] {{ .Prompt }} [/INST]"

  • 2.使用微调模型

    ollama create 模型名字 -f Modelfile文件路径

    ollama create panda -f test.Modelfile

相关推荐
AI大模型2 天前
基于 Docker 的 LLaMA-Factory 全流程部署指南
docker·llm·llama
m0_603888718 天前
LLaMA-Adapter V2 Parameter-Efficient Visual Instruction Model
人工智能·深度学习·ai·llama·论文速览
三千院本院12 天前
LlaMA_Factory实战微调VL大模型
llama
爱分享的飘哥17 天前
第四十六章:AI的“瞬时记忆”与“高效聚焦”:llama.cpp的KV Cache与Attention机制
llama·llama.cpp·kv cache·attention优化·llm cpu推理·量化attention·gguf推理
psyq18 天前
LLaMA Factory 角色扮演模型微调实践记录
人工智能·llama
liliangcsdn1 个月前
mac测试ollama llamaindex
数据仓库·人工智能·prompt·llama
茫茫人海一粒沙1 个月前
使用 LLaMA 3 8B 微调一个 Reward Model:从入门到实践
llama
liliangcsdn1 个月前
mac llama_index agent算术式子计算示例
人工智能·python·macos·llama
许愿与你永世安宁1 个月前
RAG(检索增强生成)里的文档管理
数据库·人工智能·gpt·oracle·llama·rag
许愿与你永世安宁1 个月前
基于Llama的RAG 3种模型配置方法
人工智能·python·自然语言处理·json·github·llama·faiss