Hub documentation

在 Hugging Face Hub 上使用 Ollama 运行任意 GGUF 模型

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

在 Hugging Face Hub 上使用 Ollama 运行任意 GGUF 模型

cover

您还可以从 Hugging Face Hub 运行私有的 GGUF 模型。

Ollama 是一个基于 llama.cpp 的应用程序,可让您直接在计算机上与 LLM 进行交互。您可以直接在 Ollama 中使用 Hugging Face 上由社区创建的任意 GGUF 量化模型(例如 bartowski、MaziyarPanahi 以及 更多),而无需创建新的 Modelfile。截至本文撰写时,Hub 上已有 45K 个公开的 GGUF 检查点,您只需一条 ollama run 命令即可运行其中任意一个。我们还提供了诸如选择量化类型、系统提示词等自定义选项,以提升您的整体使用体验。

入门方法非常简单:

  1. 在您的 本地应用设置 中启用 ollama。
  2. 在模型页面上,从 Use this model 下拉菜单中选择 ollama。例如:bartowski/Llama-3.2-1B-Instruct-GGUF。

该代码片段的格式如下:

ollama run hf.co/{username}/{repository}

请注意,您可以使用 hf.co 和 huggingface.co 作为域名。

以下是一些您可以尝试的模型:

ollama run hf.co/bartowski/Llama-3.2-1B-Instruct-GGUF
ollama run hf.co/mlabonne/Meta-Llama-3.1-8B-Instruct-abliterated-GGUF
ollama run hf.co/arcee-ai/SuperNova-Medius-GGUF
ollama run hf.co/bartowski/Humanish-LLama3-8B-Instruct-GGUF

自定义量化

默认情况下,如果模型仓库中存在 Q4_K_M 量化方案,则会使用该方案。如果不存在,则默认选择仓库中一种合理的量化类型。

要选择其他方案,只需:

  1. 在模型页面的 Files and versions 选项卡中,打开特定 GGUF 文件的 GGUF 查看器。
  2. 从 Use this model 下拉菜单中选择 ollama。

该代码片段的格式如下(添加了量化标签):

ollama run hf.co/{username}/{repository}:{quantization}

例如:

ollama run hf.co/bartowski/Llama-3.2-3B-Instruct-GGUF:IQ3_M
ollama run hf.co/bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0

# the quantization name is case-insensitive, this will also work
ollama run hf.co/bartowski/Llama-3.2-3B-Instruct-GGUF:iq3_m

# you can also directly use the full filename as a tag
ollama run hf.co/bartowski/Llama-3.2-3B-Instruct-GGUF:Llama-3.2-3B-Instruct-IQ3_M.gguf

自定义聊天模板和参数

默认情况下,系统会从常用模板列表中自动选择一个模板。该选择基于存储在 GGUF 文件内部的内置 tokenizer.chat_template 元数据。

如果你的 GGUF 文件没有内置模板,或者你想自定义聊天模板,可以在仓库中创建一个名为 template 的新文件。该模板必须是 Go 模板,而不是 Jinja 模板。以下是一个示例:

{{ if .System }}<|system|>
{{ .System }}<|end|>
{{ end }}{{ if .Prompt }}<|user|>
{{ .Prompt }}<|end|>
{{ end }}<|assistant|>
{{ .Response }}<|end|>

如需了解更多关于 Go 模板格式的信息,请参阅此文档

您可以选择通过在新文件中配置系统提示词,并将该文件命名为 system 并放置在仓库中。

若要更改采样参数,请在仓库中创建一个名为 params 的文件。该文件必须采用 JSON 格式。有关所有可用参数的列表,请参阅 此文档。

从 Hugging Face Hub 运行私有 GGUF

您可以通过以下两个简单步骤,从您的个人账户或关联的组织账户运行私有 GGUF:

  1. 复制你的 Ollama SSH 密钥,可以通过以下方式完成:cat ~/.ollama/id_ed25519.pub | pbcopy
  2. 前往您的账户设置并点击Add new SSH key,将对应的密钥添加到您的 Hugging Face 账户中。
  3. 就是这样!现在你可以从 Hugging Face Hub 运行私有的 GGUF 模型了:ollama run hf.co/{username}/{repository}。

参考

Update on GitHub