transformers 5.12.1
pip install transformers
Released:
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.
Navigation
Verified details
These details have been verified by PyPIProject links
GitHub Statistics
Maintainers
👁 Avatar for ArthurZucker from gravatar.comArthurZucker 👁 Avatar for Cyril123456789 from gravatar.com
Cyril123456789 👁 Avatar for lysandre from gravatar.com
lysandre 👁 Avatar for Thomwolf from gravatar.com
Thomwolf 👁 Avatar for vasqu from gravatar.com
vasqu 👁 Avatar for xcid from gravatar.com
xcid
Unverified details
These details have not been verified by PyPIMeta
- License: Apache 2.0 License
- Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)
- Tags machine-learning , nlp , python , pytorch , transformer , llm , vlm , deep-learning , inference , training , model-hub , pretrained-models , llama , gemma , qwen
- Requires: Python >=3.10.0
-
Provides-Extra:
torch,vision,audio,video,timm,quality,docs,kernels,sentencepiece,tiktoken,mistral-common,chat-template,sklearn,accelerate,retrieval,sagemaker,deepspeed,optuna,integrations,ray,codecarbon,serving,num2words,benchmark,ja,testing,deepspeed-testing,all,dev
Classifiers
- Development Status
- Intended Audience
- Operating System
- Programming Language
- Topic
Project description
👁 Checkpoints on Hub
👁 Build
👁 GitHub
👁 Documentation
👁 GitHub release
👁 Contributor Covenant
👁 DOI
English | 简体中文 | 繁體中文 | 한국어 | Español | 日本語 | हिन्दी | Русский | Português | తెలుగు | Français | Deutsch | Italiano | Tiếng Việt | العربية | اردو | বাংলা | فارسی | Türkçe |
State-of-the-art pretrained models for inference and training
👁 Image
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.10+, and PyTorch 2.4+.
Create and activate a virtual environment with venv or uv, a fast Rust-based Python package and project manager.
# 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.
# 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.
gitclonehttps://github.com/huggingface/transformers.git cdtransformers # pip pipinstall'.[torch]' # uv uvpipinstall'.[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.
fromtransformersimport 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 cup of flour, 1 cup of milk, 1 cup of butter, 1 cup of eggs, 1 cup of chocolate chips. if you want to make 2 cakes, how much sugar do you need? To make 2 cakes, you will need 2 cups of sugar.'}]
To chat with a model, the usage pattern is the same. The only difference is you need to construct a chat history (the input to Pipeline) between you and the system.
[!TIP] You can also chat with a model directly from the command line, as long as
transformers serveis running.transformerschatQwen/Qwen2.5-0.5B-Instruct
importtorch fromtransformersimport pipeline chat = [ {"role": "system", "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."}, {"role": "user", "content": "Hey, can you tell me any fun things to do in New York?"} ] pipeline = pipeline(task="text-generation", model="meta-llama/Meta-Llama-3-8B-Instruct", dtype=torch.bfloat16, device_map="auto") response = pipeline(chat, max_new_tokens=512) print(response[0]["generated_text"][-1]["content"])
Expand the examples below to see how Pipeline works for different modalities and tasks.
Why should I use Transformers?
-
Easy-to-use state-of-the-art models:
- High performance on natural language understanding & generation, computer vision, audio, video, and multimodal tasks.
- Low barrier to entry for researchers, engineers, and developers.
- Few user-facing abstractions with just three classes to learn.
- A unified API for using all our pretrained models.
-
Lower compute costs, smaller carbon footprint:
- Share trained models instead of training from scratch.
- Reduce compute time and production costs.
- Hundreds of model architectures with 1M+ pretrained checkpoints across all modalities.
-
Choose the right framework for every part of a model's lifetime:
- Train state-of-the-art models in 3 lines of code.
- Move a single model between PyTorch/JAX/TF2.0 frameworks at will.
- Pick the right framework for training, evaluation, and production.
-
Easily customize a model or an example to your needs:
- We provide examples for each architecture to reproduce the results published by its original authors.
- Model internals are exposed as consistently as possible.
- Model files can be used independently of the library for quick experiments.
When shouldn't I use Transformers?
- This library is not a modular toolbox of building blocks for neural nets. The code in the model files is not refactored with additional abstractions on purpose, so that researchers can quickly iterate on each of the models without diving into additional abstractions/files.
- The training API is optimized to work with PyTorch models provided by Transformers. For generic machine learning loops, you should use another library like Accelerate.
- The example scripts are only examples. They may not necessarily work out-of-the-box on your specific use case and you'll need to adapt the code for it to work.
100 projects using Transformers
Transformers is more than a toolkit to use pretrained models, it's a community of projects built around it and the Hugging Face Hub. We want Transformers to enable developers, researchers, students, professors, engineers, and anyone else to build their dream projects.
In order to celebrate Transformers 100,000 stars, we wanted to put the spotlight on the community with the awesome-transformers page which lists 100 incredible projects built with Transformers.
If you own or use a project that you believe should be part of the list, please open a PR to add it!
Example models
You can test most of our models directly on their Hub model pages.
Expand each modality below to see a few example models for various use cases.
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" }
Project details
Verified details
These details have been verified by PyPIProject links
GitHub Statistics
Maintainers
👁 Avatar for ArthurZucker from gravatar.comArthurZucker 👁 Avatar for Cyril123456789 from gravatar.com
Cyril123456789 👁 Avatar for lysandre from gravatar.com
lysandre 👁 Avatar for Thomwolf from gravatar.com
Thomwolf 👁 Avatar for vasqu from gravatar.com
vasqu 👁 Avatar for xcid from gravatar.com
xcid
Unverified details
These details have not been verified by PyPIMeta
- License: Apache 2.0 License
- Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)
- Tags machine-learning , nlp , python , pytorch , transformer , llm , vlm , deep-learning , inference , training , model-hub , pretrained-models , llama , gemma , qwen
- Requires: Python >=3.10.0
-
Provides-Extra:
torch,vision,audio,video,timm,quality,docs,kernels,sentencepiece,tiktoken,mistral-common,chat-template,sklearn,accelerate,retrieval,sagemaker,deepspeed,optuna,integrations,ray,codecarbon,serving,num2words,benchmark,ja,testing,deepspeed-testing,all,dev
Classifiers
- Development Status
- Intended Audience
- Operating System
- Programming Language
- Topic
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file transformers-5.12.1.tar.gz.
File metadata
- Download URL: transformers-5.12.1.tar.gz
- Upload date:
- Size: 8.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
679ee731c8225347889ad4fb3b2c926a62e9da3b7d284e9d12c791da7272466b
|
|
| MD5 |
453ff953148c078375efceb59b0d5d7f
|
|
| BLAKE2b-256 |
aa7c8240f612819718100a9346dc28dea6a11370c3ca9c8c6eabadd3dea4ef29
|
Provenance
The following attestation bundles were made for transformers-5.12.1.tar.gz:
Publisher:
release.yml on huggingface/transformers
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
transformers-5.12.1.tar.gz -
Subject digest:
679ee731c8225347889ad4fb3b2c926a62e9da3b7d284e9d12c791da7272466b - Sigstore transparency entry: 1826723297
- Sigstore integration time:
-
Permalink:
huggingface/transformers@ddb849abe009d1089e6c691bfc897f27211c663c -
Branch / Tag:
refs/tags/v5.12.1 - Owner: https://github.com/huggingface
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ddb849abe009d1089e6c691bfc897f27211c663c -
Trigger Event:
push
-
Statement type:
File details
Details for the file transformers-5.12.1-py3-none-any.whl.
File metadata
- Download URL: transformers-5.12.1-py3-none-any.whl
- Upload date:
- Size: 11.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a5e109d2021265df7098ffbb738295acaf5ad256f12cbc586db2ea4dcbb1a8a
|
|
| MD5 |
400103692fc839fd1d48e3ab872b4e70
|
|
| BLAKE2b-256 |
df56bbd60dd8668055803bf8ba55a81f9b8a8b31497f620109a9671d26a2076d
|
Provenance
The following attestation bundles were made for transformers-5.12.1-py3-none-any.whl:
Publisher:
release.yml on huggingface/transformers
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
transformers-5.12.1-py3-none-any.whl -
Subject digest:
2a5e109d2021265df7098ffbb738295acaf5ad256f12cbc586db2ea4dcbb1a8a - Sigstore transparency entry: 1826723982
- Sigstore integration time:
-
Permalink:
huggingface/transformers@ddb849abe009d1089e6c691bfc897f27211c663c -
Branch / Tag:
refs/tags/v5.12.1 - Owner: https://github.com/huggingface
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ddb849abe009d1089e6c691bfc897f27211c663c -
Trigger Event:
push
-
Statement type:
