跳到正文
原文
Hugging Face Blog·· 2026-09-22精选AI 评分62

Transformers 新增 llama.cpp GGUF 量化模型支持

Transformers now runs llama.cpp quants

AI 导读

Hugging Face 在 transformers 中加入 GGUF 支持,用户可从 Hub 选取量化 checkpoint,通过 from_pretrained 传入 gguf_file 参数即可在本地生成,无需额外配置。

推荐理由

Hugging Face 官方说明 transformers 如何直接加载 GGUF 量化权重,并给出与 llama.cpp 的对比数据与当前限制。

深读指南

适合谁读:希望在 Apple Silicon Mac 上通过 transformers API 本地运行 GGUF 量化模型、并关注 PyTorch 与 llama.cpp 性能对比的开发者与研究者。

  • GGUF 把权重、元数据、分词器信息和可选聊天模板打包在单个文件中,并支持不同量化级别以权衡精度与内存占用。

    GGUF packages model weights and metadata, including tokenizer information and an optional chat template, in one file.
  • 加载 GGUF 只需在 from_pretrained 中传入 gguf_file,其余流程沿用标准 transformers API。

    pass its Hub model_id and filename as gguf_file to from_pretrained . No extra configuration is needed
  • 作者建议从 Q4_K_M 起步,再根据可用内存尝试 Q5_K_M 或 Q6_K,并强调量化质量取舍需在实际任务上评估。

    We suggest starting with Q4_K_M , then trying Q5_K_M or Q6_K if you have more memory available.

局限与前提:当前打包推理路径仅支持 MPS(Apple Silicon),架构覆盖限于 Qwen3.5 稠密与 MoE(含兼容的 Qwen3.8),填充批处理性能仍待改进;文中基准对比也自述条件不完全相同(Transformers 测量包含 prefill,而 llama-bench 仅报告 decode 吞吐),因此性能结论不宜直接外推。

对照原文阅读

来源:Hugging Face Blog · huggingface.co