如何在微调模型
2026年2月17日大约 2 分钟
本人是windows电脑
方案选择
由于 Ollama 0.15.4 版本不支持 fine-tune 命令,推荐使用 llama.cpp 进行微调。
环境准备
提示
如果想自己编译就安装cmake,也可以通过第二步直接下载llama-b7917-bin-win-cpu-x64.zip,跳过camke
1. 安装 camake
如果已经安装可以跳过
我在linux上报错,原因是cmake版本太低,需要升级
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.14 or higher is required. You are running version 2.8.12.
-- Configuring incomplete, errors occurred!- 第一步:卸载系统旧版cmake(如果提示"未安装",直接跳过这步)
yum remove cmake -y- 第二步:下载并安装cmake最新稳定版(自动适配x64架构,所有Linux都能用)
wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-linux-x86_64.sh
chmod +x cmake-3.28.3-linux-x86_64.sh
./cmake-3.28.3-linux-x86_64.sh --prefix=/usr/local --exclude-subdir- 第三步:验证是否升级成功(敲完看版本≥3.14就OK)
find /usr/local -name cmake/usr/local/doc/cmake
/usr/local/share/bash-completion/completions/cmake
/usr/local/bin/cmake
ln -s /usr/local/bin/cmake /usr/bin/cmake
cmake --version2. 安装 llama.cpp
推荐先下载
提示
这一步我是借助自己的轻量云服务器
wget https://github.com/ggml-org/llama.cpp/releases/download/b7917/llama-b7917-bin-win-cpu-x64.zip下载好以后解压可以看到啦
把解压目录添加到环境变量,之后验证
llama-cli.exe --help提示
如果下载不顺利再考虑编译
克隆仓库并编译
推荐使用gitcode镜像
git clone git@gitcode.com:GitHub_Trending/ll/llama.cpp.git会在当前目录下生成一个llama.cpp文件夹
编译(进入lama.cpp)
mkdir build && cd build
cmake ..
make -j 8 # 8是线程数,可以用`nproc`看核数,填对应的数字编译完后,build/bin目录下就有llama-cli了,和预编译包的效果一样~
3. 下载基础模型
从 gitcode 下载 Qwen2-7B 的 GGUF 格式模型:
https://ai.gitcode.com/models?q=Qwen2-7B-Instruct-GGUF
下载文件:qwen2-7b-instruct-q4_k_m.gguf
数据准备
数据格式
data_v1.jsonl 格式正确:
{"instruction": "问题", "response": "回答"}数据清洗
提示
这是自己写的python脚本
每次添加新数据后运行:
python fix_jsonl_clean.py