huggingface /transformers

🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.

★ 168,729⑂ 35,148👁 1,243⑃ 29,843● 19,811▤ 282◈ 0
PythonApache-2.0Created 2018-10-29huggingface.co/transformers
168,729
stars
+45+278+1,749
35,148
forks
1,243
watchers
29,843
prs
19,811
issues
282
releases
0
discussions

README

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 acts as the model-definition framework for state-of-the-art machine learning with text, computer
vision, audio, video, and multimodal models, for both inference and training.

It centralizes the model definition so that this definition is agreed upon across the ecosystem. transformers is the
pivot across frameworks: if a model definition is supported, it will be compatible with the majority of training
frameworks (Axolotl, Unsloth, DeepSpeed, FSDP, PyTorch-Lightning, ...), inference engines (vLLM, SGLang, TGI, ...),
and adjacent modeling libraries (llama.cpp, mlx, ...) which leverage the model definition from transformers.

We pledge to help support new state-of-the-art models and democratize their usage by having their model definition be
simple, customizable, and efficient.

There are over 1M+ Transformers model checkpoints on the Hugging Face Hub you can use.

Explore the Hub today to find a model and use Transformers to help you get started right away.

 Installation

Transformers works with Python 3.11+, and PyTorch 2.6+.

Create and activate a virtual environment with venv or uv, a fast Rust-based Python package and project manager.

py
 venv
python -m venv .my-env
source .my-env/bin/activate
 uv
uv venv .my-env
source .my-env/bin/activate


Install Transformers in your virtual environment.

py
 pip
pip install "transformers[torch]"

 uv
uv pip install "transformers[torch]"


Install Transformers from source if you want the latest changes in the library or are interested in contributing. However, the latest version may not be stable. Feel free to open an issue if you encounter an error.

shell
git clone https://github.com/huggingface/transformers.git
cd transformers

 pip
pip install '.[torch]'

 uv
uv pip install '.[torch]'


 Quickstart

Get started with Transformers right away with the Pipeline API. The Pipeline is a high-level inference class that supports text, audio, vision, and multimodal tasks. It handles preprocessing the input and returns the appropriate output.

Instantiate a pipeline and specify model to use for text generation. The model is downloaded and cached so you can easily reuse it again. Finally, pass some text to prompt the model.

py
from transformers import pipeline

pipeline = pipeline(task="text-generation", model="Qwen/Qwen2.5-1.5B")
pipeline("the secret to baking a really good cake is ")
[{'generated_text': 'the secret to baking a really good cake is 1) to use the right ingredients and 2) to follow the recipe exactly. the recipe for the cake is as follows: 1 cup of sugar, 1 cu

Top issues

Latest release

Patch release v5.22.2 v5.22.2 2026-11-06
Patch release v5.22.2

Some in between patch for security and distributed fixes. See the included commits :hugs: 

- [Distributed] Set device_id only for NCCL (50281) by @michaelbenayoun  and @3outeille 
- Harden our Jinja sandboxing (50431) by @Rocketknight1

Full Changelog: https://github.com/huggingface/transformers/compare/v5.22.1...v5.22.2

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON