有的时候,尤其是用一些去除安全审查的模型,模型通常不提供gguf模型,这个时候如果还想用,我们就得自己想一些办法了。本文记录一下hf模型,从下载到转换gguf,转量化,以及安装到ollama中的全过程。主要是怕自己忘了。
首先,用Mistral-Small-3.2-24B-Instruct-2506的破解版做演示。
huihui-ai/Huihui-Mistral-Small-3.2-24B-Instruct-2506-abliterated
所有内容基于llama.cpp仓库的脚本以及文件,我是使用mamba安装了一个虚拟环境。
pip install huggingface-hub
huggingface-cli download huihui-ai/Huihui-Mistral-Small-3.2-24B-Instruct-2506-abliterated
先将模型搞下来。下载完成之后,通常是在
C:\Users\用户名\.cache\huggingface\hub\models--huihui-ai--Huihui-Mistral-Small-3.2-24B-Instruct-2506-abliterated\snapshots\7526a40541895942da4ad7b61611443b94f7c842
然后使用convert_hf_to_gguf.py脚本进行转换。
python convert_hf_to_gguf.py C:\Users\Suenley\.cache\huggingface\hub\models--huihui-ai--Huihui-Mistral-Small-3.2-24B-Instruct-2506-abliterated\snapshots\7526a40541895942da4ad7b61611443b94f7c842 --outfile huihui322506.gguf
完成转换后会得到一个量化16的huihui322506.gguf
调用llama-quantize.exe进行量化转换。
llama-quantize.exe D:\Code\AI\llama.cpp\huihui322506.gguf huihui.gguf Q6_K
完成转换后得到huihui.gguf,接下来是如何让ollama加载这个模型。
新建一个Modelfile
文件,不要后缀,可以就叫Modelfile
,也可以是其他无后缀的文件。然后在里面写入:
FROM D:\models\huihui.gguf
然后执行ollama的命令:格式: ollama create 您想给模型起的名字 -f Modelfile的路径
ollama create test111 -f D:\models\Modelfile
操作完成后ollama中会得到一个test111模型,这是我们想要的,但是我们可以让它看起来更美观一些。
ollama cp test111 Mistral-Small-Abliterated:24B-2506
ollama rm test111
至此,我们已经完成了HF to GGUF的转换,并且加载到了ollama中