保存为 GGUF
将模型保存为 16 位 GGUF,以便用于 Ollama、Jan AI、Open WebUI 等!
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "q4_k_m")
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "q8_0")
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "f16")model.push_to_hub_gguf("hf_username/directory", tokenizer, quantization_method = "q4_k_m")
model.push_to_hub_gguf("hf_username/directory", tokenizer, quantization_method = "q8_0")# https://github.com/ggerganov/llama.cpp/blob/master/examples/quantize/quantize.cpp#L19
# 来自 https://mlabonne.github.io/blog/posts/Quantize_Llama_2_models_using_ggml.html
ALLOWED_QUANTS = \
{
"not_quantized" : "推荐。转换快速。推理慢,文件大。",
"fast_quantized" : "推荐。转换快速。推理和文件大小均可。",
"quantized" : "推荐。转换慢。推理快,文件小。",
"f32" : "不推荐。保留100%精度,但非常慢且占用大量内存。",
"f16" : "转换最快且保留100%精度。推理慢且占用大量内存。",
"q8_0" : "转换快速。资源使用高,但通常可接受。",
"q4_k_m" : "推荐。对 attention.wv 和 feed_forward.w2 张量的一半使用 Q6_K,其余使用 Q4_K",
"q5_k_m" : "推荐。对 attention.wv 和 feed_forward.w2 张量的一半使用 Q6_K,其余使用 Q5_K",
"q2_k" : "对 attention.vw 和 feed_forward.w2 张量使用 Q4_K,对其他张量使用 Q2_K。",
"q3_k_l" : "对 attention.wv、attention.wo 和 feed_forward.w2 张量使用 Q5_K,其余使用 Q3_K",
"q3_k_m" : "对 attention.wv、attention.wo 和 feed_forward.w2 张量使用 Q4_K,其余使用 Q3_K",
"q3_k_s" : "对所有张量使用 Q3_K",
"q4_0" : "原始量化方法,4 位。",
"q4_1" : "比 q4_0 精度更高但不及 q5_0。然而推理比 q5 模型更快。",
"q4_k_s" : "对所有张量使用 Q4_K",
"q4_k" : "q4_k_m 的别名",
"q5_k" : "q5_k_m 的别名",
"q5_0" : "更高的精度、更高的资源使用且推理更慢。",
"q5_1" : "精度更高、资源使用更高且推理更慢。",
"q5_k_s" : "对所有张量使用 Q5_K",
"q6_k" : "对所有张量使用 Q8_K",
"iq2_xxs" : "2.06 bpw 量化",
"iq2_xs" : "2.31 bpw 量化",
"iq3_xxs" : "3.06 bpw 量化",
"q3_k_xs" : "3 位极小量化",
}在 Unsloth 上运行效果良好,但导出并在其他平台运行后结果很差
保存为 GGUF / vLLM 16bit 崩溃
如何手动保存为 GGUF?
最后更新于
这有帮助吗?

