Transformers documentation

llama.cpp

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.24.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

llama.cpp

llama.cpp 是一个用于在本地部署大型语言模型的 C/C++ 推理引擎。它轻量级,无需 Python、CUDA 或其他重型服务器基础设施。llama.cpp 使用 GGUF 文件格式。GGUF 支持量化模型权重和内存映射,以降低设备上的内存带宽需求。

在 Hub 中浏览已提供 GGUF 格式的模型。

使用 convert_hf_to_gguf.py 脚本将任意 Transformers 模型转换为 GGUF 格式。

python3 convert_hf_to_gguf.py ./models/openai/gpt-oss-20b \
  --outfile gpt-oss-20b.gguf \

使用 llama-cli 从命令行在本地部署模型,或使用 llama-server 启动 Web UI。添加 -hf 标志以表明该模型来自 Hub。

llama-cli
llama-server
llama-cli -hf ggml-org/gpt-oss-20b-GGUF

Transformers 集成

  1. AutoConfig.from_pretrained() 会加载模型的 config.json 文件以提取元数据。
  2. AutoTokenizer.from_pretrained() 会提取词汇表和分词器配置。
  3. 根据配置中的 architectures 字段,该脚本会从内部注册表中选择一个转换器类。该注册表将 Transformers 架构名称(例如 LlamaForCausalLM)映射到对应的转换器类。
  4. 该转换器将 Transformers 张量名称(例如 model.layers.0.self_attn.q_proj.weight)映射为 GGUF 张量名称,对张量进行转换,并打包词表。
  5. 输出是一个单一的 GGUF 文件,其中包含模型权重、分词器和元数据。

资源

Update on GitHub