跳到主要内容Skip to main content
本地推理与部署Local Inference & Serving生产可用Production

Transformers

huggingface / transformers

Hugging Face 的模型库与统一接口:AutoModel / AutoTokenizer 覆盖文本、视觉、音频与多模态,支持 PyTorch、TensorFlow、Flax;能直接加载 Hub 权重,也能接 PEFT、vLLM、TGI 等后端。Hugging Face’s model library and unified interface: AutoModel / AutoTokenizer cover text, vision, audio and multimodal models across PyTorch, TensorFlow and Flax; load Hub weights directly or hand them to PEFT, vLLM or TGI.

169.3k stars 35257 forks Python 语言Language Apache-2.0 许可License 最近推送Last push 2026-11-20

为什么选Why choose it

  • 模型兼容面最广,换 checkpoint 通常不用重写调用层。The broadest model compatibility layer; switching checkpoints rarely requires rewriting the call site.
  • 训练与推理接口统一,文档和社区答案最多。Unified training and inference interfaces with the largest documentation and community base.
  • 和 datasets、accelerate、peft 配套,适合当基线。Pairs with datasets, accelerate and peft, making it a sensible baseline.

不适合Not for

不是推理服务器;高吞吐部署仍要 vLLM、SGLang 或 TGI。Not an inference server; high-throughput serving still needs vLLM, SGLang or TGI.
大模型默认加载会吃显存,需要 device_map、量化或分片。Large models load into VRAM by default; use device_map, quantization or sharding.
版本升级偶尔改 API,生产要锁版本。Occasional API changes between versions — pin versions in production.

最小上手Minimum setup

  1. pip install transformers torch,先加载一个几亿参数的小模型和 tokenizer。pip install transformers torch, then load a small few-hundred-million-parameter model and tokenizer.
  2. 用 pipeline 跑一次文本分类或生成,确认权重、分词与设备都正常。Run one pipeline for classification or generation to confirm weights, tokenizer and device.
  3. 再接 accelerate 或 peft;部署前换 vLLM/TGI 压测。Then add accelerate or peft; benchmark vLLM/TGI before deployment.

依赖与成本Dependencies and cost

Python 3.9+ / PyTorch 或 TensorFlow;从 Hugging Face Hub 拉权重需要网络与磁盘;GPU 可选,大模型需要足够显存或分片。Python 3.9+ with PyTorch or TensorFlow; network and disk for Hub weights; GPU optional, but large models need VRAM or sharding.

许可与使用边界License and usage boundaries

代码 Apache-2.0;每个模型权重有自己的许可,商用前逐一读 model card 与 LICENSE。Code is Apache-2.0; every model weight carries its own licence — read the model card and LICENSE before commercial use.

开源不等于可商用:GPL / AGPL 有传染性;代码许可、模型许可、生成内容许可要分开看。上线前读仓库 LICENSE 与模型卡,必要时让法务确认。Open source is not automatically commercial-use friendly: GPL / AGPL are copyleft; code, model and output licenses are separate. Read the LICENSE and model card before launch, and involve legal when needed.

替代与相邻Alternatives and neighbors

  • vLLM — 规模 / 性能Scale / performance,高吞吐推理与服务引擎,PagedAttention、连续批处理、多卡并行。A high-throughput inference and serving engine with PagedAttention, continuous batching and multi-GPU support.
  • llama.cpp — 本地优先Local-first,C/C++ 推理引擎,CPU、Apple Silicon、消费级 GPU 都能跑,量化格式丰富。A C/C++ inference engine that runs on CPUs, Apple Silicon and consumer GPUs, with a wide range of quantisation formats.
  • Ollama — 先试这个Start here,一条命令拉模型、跑本地推理,自带模型库与 OpenAI 兼容 API。Pull and run local models with one command, with a built-in model library and an OpenAI-compatible API.

下一步Next steps

  • 打开 GitHub,先读 README、LICENSE、最近 release 与 issue。Open GitHub and read the README, LICENSE, latest release and issues first.
  • 按“部署依赖 / 显存 / 数据 / 网络 / 权限”列一张上手清单。Make an onboarding checklist for deployment dependencies, VRAM, data, network and permissions.
  • 用一个小样本跑通,再决定是否进生产;不要直接上生产数据。Run a small sample first, then decide on production; never start with production data.

GitHub 仓库 ↗GitHub repository ↗ 文档 ↗Docs ↗ 加入对比Add to compare

快照口径:stars / forks / language / license / pushed_at 来自 GitHub API 2026-11-20 快照;之后的变化没有回写。标签与“适合 / 不适合”是编辑判断,不是 GitHub 元数据。Snapshot: stars / forks / language / license / pushed_at come from the GitHub API snapshot on 2026-11-20; later changes are not written back. Tags and “fit / not fit” are editorial judgments, not GitHub metadata.
不背书:本站只做索引与风险提示,不审计代码、不保证安全、不替你做许可判断。仓库脚本与模型权重请自行审查。No endorsement: this site only indexes and flags risks; it does not audit code, guarantee security or make license decisions for you. Review repository scripts and model weights yourself.