Ollama

注意

仍需为Qwen3更新。

Ollama helps you run LLMs locally with only a few commands. It is available at macOS, Linux, and Windows. Now, Qwen2.5 is officially on Ollama, and you can run it with one command:

ollama run qwen2.5

接着,我们介绍在Ollama使用Qwen2.5模型的更多用法

快速开始

访问官方网站Ollama,点击Download以在您的设备上安装Ollama。您还可以在网站上搜索模型,在这里您可以找到Qwen2.5系列模型。除了默认模型之外,您可以通过以下方式选择运行不同大小的Qwen2.5-Instruct模型:

  • ollama run qwen2.5:0.5b

  • ollama run qwen2.5:1.5b

  • ollama run qwen2.5:3b

  • ollama run qwen2.5:7b

  • ollama run qwen2.5:14b

  • ollama run qwen2.5:32b

  • ollama run qwen2.5:72b

备注

ollama并不托管基模型。即便模型标签不带instruct后缀,实际也是instruct模型。

用Ollama运行你自己的GGUF文件

有时您可能不想拉取模型,而是希望直接使用自己的GGUF文件来配合Ollama。假设您有一个名为qwen2.5-7b-instruct-q5_0.gguf的Qwen2.5的GGUF文件。在第一步中,您需要创建一个名为Modelfile的文件。该文件的内容如下所示:

FROM qwen2.5-7b-instruct-q5_0.gguf

# set the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 0.7
PARAMETER top_p 0.8
PARAMETER repeat_penalty 1.05
PARAMETER top_k 20

TEMPLATE """{{ if .Messages }}
{{- if or .System .Tools }}<|im_start|>system
{{ .System }}
{{- if .Tools }}

# Tools

You are provided with function signatures within <tools></tools> XML tags:
<tools>{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}{{- end }}
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end }}<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ end }}
{{- end }}
{{- else }}
{{- if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}"""

# set the system message
SYSTEM """You are Qwen, created by Alibaba Cloud. You are a helpful assistant."""

Then create the Ollama model by running:

ollama create qwen2.5_7b -f Modelfile

Once it is finished, you can run your Ollama model by:

ollama run qwen2.5_7b

工具调用

Tool use is now supported Ollama and you should be able to run Qwen2.5 models with it. For more details, see our function calling guide.