Skip to main content

Hugging Face Transformers Library

Checkpoints on Hub Build GitHub Documentation GitHub release Contributor Covenant DOI

English | 简体中文 | 繁體中文 | 한국어 | Español | 日本語 | हिन्दी | मराठी | Русский | Português | తెలుగు | Français | Deutsch | Italiano | Tiếng Việt | العربية | اردو | বাংলা | فارسی | Română | Türkçe

State-of-the-art pretrained models for inference and training

Transformers is the model-definition framework for machine learning models in text, computer vision, audio, video, and multimodal tasks. It defines each model once, in PyTorch, and you use that definition for both inference and training.

Training frameworks, inference engines, and local runtimes build on that definition instead of writing their own. Transformers adds new architectures as they're released and matches each one to its original results, so those tools get each new model as soon as it's added.

Unsloth
Fine-tune with less memory. Unsloth trains LLMs in 4-bit, 8-bit, and 16-bit precision with custom kernels.
vLLM
Serve LLMs at scale. vLLM batches requests continuously and keeps KV cache memory compact with PagedAttention.
SGLang
Serve LLMs with low latency. SGLang is a high-throughput inference engine with a frontend language for agentic workflows.
llama.cpp
Run LLMs locally without Python. llama.cpp is a C/C++ inference engine that runs quantized models in the GGUF format.

Transformers standardizes how every model is written, so hundreds of architectures share one structure. Each model is one file that reads from top to bottom and stays simple without giving up performance. An improvement made once reaches every architecture, so if you find one, contribute it.

Transformers is designed to be read and modified by humans and coding agents alike. To swap how a model computes, register your own attention or experts function, or load an optimized kernel from the Hub, and the model uses it without edits to its code.

Try a model

Install Transformers with PyTorch. See the Installation guide for other setups.

uv pip install "transformers[torch]"

Create a Pipeline with a chat model from the Hugging Face Hub and pass it a message.

from transformers import pipeline

pipe = pipeline(task="text-generation", model="Qwen/Qwen3-0.6B")
messages = [
    {"role": "user", "content": "What's the secret to baking a really good cake? Answer in one sentence."},
]
output = pipe(messages, tokenizer_encode_kwargs={"enable_thinking": False})
print(output[0]["generated_text"][-1]["content"])
# The secret to baking a really good cake is combining the perfect balance of ingredients, technique, and a warm, loving atmosphere.

The Quickstart covers loading models, running inference on other tasks, and training.

Set up your coding agent

Copy the prompt below into your coding agent. It has the agent check your installed version, read the docs for that version, and use the current Transformers v5 APIs.

I'm building with Hugging Face Transformers. Before you write any Transformers code:

1. Check the installed version with `python -c "import transformers; print(transformers.__version__)"`. If Transformers isn't installed, install it with `pip install "transformers[torch]"`.
2. Read the docs index for that version at https://huggingface.co/docs/transformers/v<version>/llms.txt, for example v5.22.2. For a .dev version, use https://huggingface.co/docs/transformers/main/llms.txt. Add .md to any docs page URL to read it as Markdown. Look up each class and argument there instead of relying on memory.
3. If the version is 5.0 or later, read https://github.com/huggingface/transformers/blob/main/MIGRATION_GUIDE_V5.md. Don't use APIs from older versions.
4. Read the model card of each model you use on the Hugging Face Hub. Many models need specific arguments, like a chat template option or a minimum Transformers version.

Run inference

Load a pretrained model and run it on text, images, audio, video, or any combination of modalities.

  • Pipeline: Preprocess the input, run the model, and postprocess the output for a task with one class.
  • Text generation: Generate text with LLMs and VLMs, and control the decoding strategy and streaming.
  • Chat with models: Start a chat in your terminal with transformers chat, or pass a chat history to a pipeline.

Serve models

Serve a model to other applications over HTTP. transformers serve is for evaluation, experimentation, and moderate load. For large production deployments, use an inference engine with a Transformers model as the backend.

  • Serve CLI: Start a local server compatible with the OpenAI SDK with transformers serve.
  • Continuous batching: Raise throughput by adding new requests to the batch as other requests finish.
  • Inference engines: Use a Transformers model as the backend for vLLM or SGLang.

Train models

Fine-tune a pretrained model on your data, on one GPU or many.

  • Trainer: Run the training loop with support for mixed precision and torch.compile.
  • PEFT: Train a small adapter instead of all of a model's weights.
  • FSDP: Shard a model's parameters across GPUs to train models that don't fit on one.
  • Tensor parallelism: Split each weight matrix across GPUs so every GPU computes part of each layer.
  • Expert parallelism: Place the experts of a mixture-of-experts model on different GPUs and route tokens to them.

Use less memory and run faster

Fit a model on your hardware and speed it up.

  • Quantization: Store weights in fewer bits so a model needs less memory.
  • Kernels: Load precompiled operations for your hardware from the Hub.
  • Attention backends: Switch between attention implementations without changing the model.

Add or change a model

Add a model to Transformers or edit an existing one.

  • Modular Transformers: Add a model by inheriting from existing models. A converter generates the standalone file.
  • Model structure rules: Follow the conventions a checker enforces on every modeling, modular, and configuration file.
  • Writing model tests: Write a small amount of model-specific test code, and the test mixins generate more than 100 tests from it.

Citation

We now have a paper you can cite for the 🤗 Transformers library:

@inproceedings{wolf-etal-2020-transformers,
    title = "Transformers: State-of-the-Art Natural Language Processing",
    author = "Thomas Wolf and Lysandre Debut and Victor Sanh and Julien Chaumond and Clement Delangue and Anthony Moi and Pierric Cistac and Tim Rault and Rémi Louf and Morgan Funtowicz and Joe Davison and Sam Shleifer and Patrick von Platen and Clara Ma and Yacine Jernite and Julien Plu and Canwen Xu and Teven Le Scao and Sylvain Gugger and Mariama Drame and Quentin Lhoest and Alexander M. Rush",
    booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
    month = oct,
    year = "2020",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2020.emnlp-demos.6/",
    pages = "38--45"
}

Metadata

Release files for transformers 5.25.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for transformers 5.25.1
File Size Uploaded Provenance Actions
transformers-5.25.1.tar.gz 10.9 MB With provenance Details for transformers-5.25.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for transformers 5.25.1
File Interpreter ABI Platform Actions
transformers-5.25.1-py3-none-any.whl Python 3 none any Details for transformers-5.25.1-py3-none-any.whl

Total release size: 24.7 MB

Release files / transformers-5.25.1.tar.gz

Download URL transformers-5.25.1.tar.gz
Size 10.9 MB
Tags Source
SHA-256 checksum
How to use checksums
2663b9160b61c67dc4d2f37b72686bf1a9266d678632451314ff810b513f0e7c
BLAKE2b-256 checksum
How to use checksums
c2319f5c05537045f2ec2f1fc06de6850a8c18164c73f9e6a0a32fabd2e406e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / transformers-5.25.1-py3-none-any.whl

Download URL transformers-5.25.1-py3-none-any.whl
Size 13.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
9fa2d4745d7adc0162afcd0a9b520dd8eed3b1e354c44e820c637abc1c0d821c
BLAKE2b-256 checksum
How to use checksums
08ba0d36a4c552415561d8e3eb6bb33152e05919a199e14514bcadbca06167fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for transformers 5.25.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for transformers-5.25.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

5.25.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page