跳到主内容
@wquguru
精选85r/LocalLLaMA(Reddit)产品发布/更新

Hugging Face transformers 库原生支持 GGUF 格式

GGUFs in transformers natively!

原文
发到 X
推荐理由

本地部署玩家福音,transformers 终于原生支持 GGUF,PyTorch 生态调试和评估更方便了,赶紧升级试试。

Hey there folks!

大家好!

Aritra here from Hugging Face. I wanted to update you all about the latest changes in `transformers`. We now natively support GGUFs (llama cpp quants).

我是来自 Hugging Face 的 Aritra。我想向大家更新 `transformers` 的最新变化。我们现在原生支持 GGUF(llama cpp 量化模型)。

You can use it like so:

你可以这样使用它:

代码 · 1
from transformers import AutoModelForCausalLM, AutoTokenizer model_id = "unsloth/Qwen3.5-4B-GGUF" filename = "Qwen3.5-4B-Q4_K_M.gguf" model = AutoModelForCausalLM.from_pretrained( model_id, gguf_file=filename, )
代码 · 1
from transformers import AutoModelForCausalLM, AutoTokenizer model_id = "unsloth/Qwen3.5-4B-GGUF" filename = "Qwen3.5-4B-Q4_K_M.gguf" model = AutoModelForCausalLM.from_pretrained( model_id, gguf_file=filename, )

After loading, you're using the normal Transformers APIs.

加载后,你使用的是标准的 Transformers API。

Why did we want to do this?

我们为什么要这么做?

  • Quantized models are smaller (so fits in a laptop)
  • PyTorch tooling at hand (useful for debugging)
  • Debugging, evaluation, custom generation becomes much easier
  • 量化后的模型体积更小(因此可以放入笔记本电脑)
  • 拥有现成的 PyTorch 工具链(对调试很有用)
  • 调试、评估和自定义生成变得更加容易

On supported Apple Silicon setups, we're also reusing ggml kernels so the model can run directly from its packed quantized weights. On the Qwen checkpoints we tested on an M2 Max, Transformers reached:

在支持的 Apple Silicon 设备上,我们还复用了 ggml 内核,因此模型可以直接从其打包的量化权重中运行。我们在 M2 Max 上测试 Qwen 检查点时,Transformers 达到了以下性能:

  • Qwen3.5-4B Q4_K_M: 70.4 tok/s vs 71.8 tok/s with llama.cpp
  • Qwen3.8-27B UD-Q4_K_M: 15.9 tok/s vs 13.4 tok/s
  • Qwen3.5-35B-A3B UD-IQ4_XS: 60.2 tok/s vs 61.3 tok/s
  • Qwen3.5-4B Q4_K_M:70.4 tok/s,而 llama.cpp 为 71.8 tok/s
  • Qwen3.8-27B UD-Q4_K_M:15.9 tok/s,而 llama.cpp 为 13.4 tok/s
  • Qwen3.5-35B-A3B UD-IQ4_XS:60.2 tok/s,而 llama.cpp 为 61.3 tok/s

This isn't meant to replace llama.cpp. If you only care about maximum local inference performance, llama.cpp is still probably the better choice.

这并非旨在取代 llama.cpp。如果你只关心最大的本地推理性能,llama.cpp 可能仍然是更好的选择。

The point is more that you can now use the same GGUF models in a more flexible environment.

更重要的是,你现在可以在更灵活的环境中使用相同的 GGUF 模型。

Read more: https://huggingface.co/blog/transformers-llama-cpp-quants

阅读更多:https://huggingface.co/blog/transformers-llama-cpp-quants

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件