在Llama Factory导出hf格式的模型
- 设置第一块的
模型路径(基底模型路径,不是Lora检查点,例如./model/Qwen2.5-1.5B-Instruct) - 设置第二块的
检查点路径(例如./saves/Qwen2.5-1.5B-Instruct/lora/train_2025-10-20-19-55-19) - 点击
Export页面 - 设置
导出路径 开始导出
编译 llama.cpp
下面三步都依赖于编译好的 llama.cpp
bash
git clone https://github.com/ggerganov/llama.cpp --depth 1
cd llama.cpp
mkdir build && cd build
cmake .. -DLLAMA_BUILD_EXAMPLES=ON -DLLAMA_NATIVE=ON -DLLAMA_CURL=OFF
cmake --build . --config Release -j
cd ..
python3 -m venv venv
source venv/bin/activate
pip install -r "./requirements/requirements-convert_hf_to_gguf.txt"HuggingFace 权重转 GGUF
命令格式:
bash
python3 ./convert_hf_to_gguf.py <HF模型路径> --outfile <输出GGUF路径> --outtype <精度类型><HF模型路径>:HuggingFace 格式模型目录(通常为微调或下载后的路径)<输出GGUF路径>:转换后生成的.gguf模型保存路径<精度类型>:精度类型,'f32', 'f16', 'bf16', 'q8_0', 'tq1_0', 'tq2_0', 'auto'
示例:
bash
python3 convert_hf_to_gguf.py /root/autodl-tmp/finetune/models/qwen3-8b-qlora/merged --outfile /root/autodl-fs/qwen3-8b-fp16-agent.gguf --outtype f16量化模型
命令格式:
bash
./build/bin/llama-quantize <输入GGUF路径> <输出GGUF路径> <量化等级><输入GGUF路径>:未量化的.gguf文件路径<输出GGUF路径>:量化后的.gguf文件保存路径<量化等级>:如Q4_0、Q4_K_M、Q8_0等,根据需求和硬件选择
示例:
bash
./build/bin/llama-quantize \
/root/autodl-fs/qwen3-8b-fp16-agent.gguf \
/root/autodl-fs/qwen3-8b-q8_0-agent.gguf \
Q8_0(可选)运行模型测试
命令格式:
bash
./build/bin/llama-run <GGUF模型路径><GGUF模型路径>:你想测试的 GGUF 模型路径(可以是原始或量化后的)
示例:
bash
./build/bin/llama-run /root/autodl-fs/qwen3-8b-fp16-agent.gguf从服务器上高速下载文件
可以直接从服务器提供商的数据存储中下载,就不用开机付费了
或者使用lftp
bash
lftp -u {用户名},{密码} -p {端口} sftp://{服务器地址}-e "set xfer:clobber true; pget -n {线程数} {服务器文件路径} -o {本地文件名/路径}: bye"pget: 使用多线程并行下载-n:指定线程数(建议64+)(甚至256线程会有更好的表现)
范例
bash
lftp -u root,askdjiwhakjd -p 27391 sftp://yourserver.com -e "set xfer:clobber true; pget -n 256 /root/autodl-fs/qwen3-8b-fp16-agent.gguf -o qwen3-8b-fp16-agent.gguf; bye"