将其他类型的大模型转化为gguf格式的模型以放在ollama上运行
1.需要用llama.cpp仓库的convert_hf_to_gguf.py脚本来转换
git clone https://github.com/ggerganov/llama.cpp.git pip install -r llama.cpp/requirements.txt
2.执行转换命令:
# 如果不量化,保留模型的效果 python llama.cpp/convert_hf_to_gguf.py ./Meta-Llama-3-8B-Instruct --outtype f16 --verbose --outfile Meta-Llama-3-8B-Instruct-gguf.gguf # 如果需要量化(加速并有损效果),直接执行下面脚本就可以 python llama.cpp/convert_hf_to_gguf.py ./Meta-Llama-3-8B-Instruct --outtype q8_0 --verbose --outfile Meta-Llama-3-8B-Instruct-gguf_q8_0.ggufbb
备注说明:
这里--outtype是输出类型,代表含义:
q2_k:特定张量(Tensor)采用较高的精度设置,而其他的则保持基础级别。
q3_k_l、q3_k_m、q3_k_s:这些变体在不同张量上使用不同级别的精度,从而达到性能和效率的平衡。
q4_0:这是最初的量化方案,使用 4 位精度。
q4_1 和 q4_k_m、q4_k_s:这些提供了不同程度的准确性和推理速度,适合需要平衡资源使用的场景。
q5_0、q5_1、q5_k_m、q5_k_s:这些版本在保证更高准确度的同时,会使用更多的资源并且推理速度较 慢。
q6_k 和 q8_0:这些提供了最高的精度,但是因为高资源消耗和慢速度,可能不适合所有用户。
fp16 和 f32: 不量化,保留原始精度。
3.创建一个文件,名为:Modelfile,内容如下:
#GGUF文件路径 FROM /root/autodl-tmp/Llama3-8B/LLM-Research/Meta-Llama-3-8B-Instruct-gguf8.gguf
4.执行ollama命令,创建ollama可执行的模型
# create 后跟生成后的模型名称 --file 对应上一步的文件 ollama create llama-3-8B-Instruct --file ./ModeFile
5.执行完上述命令后会在ollama里面生成模型,可以用 ollama list 命令查看,然后执行下面命令运行模型:
ollama run llama-3-8B-Instruc