(Mac/Windows)本地部署ollama,导出/导出ollama模型

##ollama安装

1.首先访问ollama官网下载 https://ollama.com/ 根据系统类型选择下载

2.下载完成后进行安装,mac系统无需关注安装路径,windows系统直接打开OllamaSetup.exe会安装至C盘,需要通过命令指定路径安装

.\OllamaSetup.exe /DIR="D:\Ollama

3.从ollama官网models页面(https://ollama.com/search)选择需要安装的模型 通过下方命令安装(安装需要耐心等待)

ollama pull [模型名称]

#例如安装deepseek-r1:1.5b

ollama pull deepseek-r1:1.5b

4.运行模型,以deepseek-r1:1.5b 为例

ollama run deepseek-r1:1.5b

5.退出对话

/bye

 

## ollama模型导出导入

1.导出ollama中的模型,以deepseek-r1:1.5b为例,使用: ollama show --modelfile deepseek-r1:1.5b 查询模型信息下方内容(modelfile文件)

# Modelfile generated by "ollama show"

# To build a new Modelfile based on this, replace FROM with:

# FROM deepseek-r1:1.5b

FROM /Users/zhangsan/.ollama/models/blobs/sha256-aabd4debf0c8f08881923f2c25fc0fdeed24435271c2b3e92c4af36704040dbc

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|>

  {{- if and $.IsThinkSet (and $last .Thinking) -}}

<think>

{{ .Thinking }}

</think>

{{- end }}{{ .Content }}{{- if not $last }}<|end▁of▁sentence|>{{- end }}

{{- end }}

{{- if and $last (ne .Role "assistant") }}<|Assistant|>

{{- if and $.IsThinkSet (not $.Think) -}}

<think>

 

</think>

 

{{ end }}

{{- end -}}

{{- end }}"""

PARAMETER stop <|begin▁of▁sentence|>

PARAMETER stop <|end▁of▁sentence|>

PARAMETER stop <|User|>

PARAMETER stop <|Assistant|>

LICENSE """MIT License

 

Copyright (c) 2023 DeepSeek

 

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

 

The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.

 

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.

"""

  FROM /Users/zhangsan/.ollama/models/blobs/sha256-aabd4debf0c8f08881923f2c25fc0fdeed24435271c2b3e92c4af36704040dbc  为模型所在位置,在电脑资源管理中找到此模型文件(Mac系统在访达通过command+Shift+G 搜索)

使用下面命令制作guff文件

cp /Users/zhangsan/.ollama/models/blobs/sha256-163553aea1b1de62de7c5eb2ef5afb756b4b3133308d9ae7e42e951d8d696ef5 deepseek-r1.gguf

制作modelfile文件

将刚才返回的内容复制到新建的modelfile中,修改FROM /Users/zhangsan/.ollama/models/blobs/sha256-aabd4debf0c8f08881923f2c25fc0fdeed24435271c2b3e92c4af36704040dbc 为from deepseek-r1.gguf (刚才cp命令拷贝的名称)

2.导入ollama模型

ollama create [模型名称] -f ./modelfile

例如:

ollama create deepseek-r1:1.5b -f ./modelfile

posted @ 2025-08-21 11:35  洋三岁  阅读(623)  评论(0)    收藏  举报
友情链接: 梦想农夫