Ollama 直接导入 safetensors 模型

Ollama 默认 pull 到的模型都是量化过的

image


量化过的有时候会有点傻

想要用非量化的模型

我们还是需要自己导入


还是用上一篇的模型:https://hf-mirror.com/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B

image



我们可以看到模型是 safetensors 的

新版的 Ollama 已经可以直接导入 safetensors  模型

不用自己再转换为 GGUF 再导入了

文档见:https://github.com/ollama/ollama/blob/main/docs/import.md#Importing-a-model-from-Safetensors-weights


同样我们还是需要自己建立一个 Modelfile 文件

Modelfile 文件说明:https://github.com/ollama/ollama/blob/main/docs/modelfile.md


根据文档的说明很简单

只要写:

FROM ./DeepSeek-R1-Distill-Qwen-7B/

但是如果这么写的话,你问的时候会胡言乱语….

下面这些字段也是需要写的…

image



当然简单的话我们可以看看 Ollama 当前模型咋写的

ollama show --modelfile deepseek-r1:7b

image


然后复制下,Modelfile 这么写:

FROM ./DeepSeek-R1-Distill-Qwen-7B/
TEMPLATE """{{- if .System }}{{ .System }}{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1}}
{{- if eq .Role "user" }}<|User|>{{ .Content }}
{{- else if eq .Role "assistant" }}<|Assistant|>{{ .Content }}{{- if not $last }}<|end▁of▁sentence|>{{- end }}
{{- end }}
{{- if and $last (ne .Role "assistant") }}<|Assistant|>{{- end }}
{{- end }}"""
PARAMETER stop <|begin▁of▁sentence|>
PARAMETER stop <|end▁of▁sentence|>
PARAMETER stop <|User|>
PARAMETER stop <|Assistant|>


最后导入模型:

ollama create deepseek-r1-qwen:7b -f Modelfile

image


等待一段时间后

导入成功


看下模型:

ollama show deepseek-r1-qwen:7b

image



启动模型,试试效果:

ollama run deepseek-r1-qwen:7b

image



加上 –verbose 参数可以看下推理速度(考验显卡的时候到了,…显然我的不给力…)

ollama run --verbose deepseek-r1-qwen:7b

image

posted @ 2025-03-12 11:13  sun8134  阅读(8325)  评论(2)    收藏  举报
分享按钮