transformers
by huggingface
Hugging Face library for defining, running and training machine learning models for text, vision and audio.
- Stars
- 169,293 stars
- Forks
- 35k forks
- Last push
- today
- Activity
- Active
# Install Transformers with PyTorch$ uv pip install "transformers[torch]"# Chat with a model in your terminal$ transformers chatCommands from the project's README. Run them after installing (see below).
Overview
Understand transformers in 60 seconds
- What it does
- Transformers is Hugging Face's Python library that defines hundreds of pretrained AI models for text, images, audio and video. You can load a model from the Hugging Face Hub and use it for inference or training in a few lines.
- The problem it solves
- Every new model architecture would otherwise need its own code. Transformers writes each model once, in PyTorch, in a standard structure, and other tools such as vLLM, Unsloth, SGLang and llama.cpp build on those definitions.
- Why choose it
- Choose it when you want the widest selection of open models with one consistent API. For high-throughput serving in production, the README points to inference engines like vLLM that use Transformers models as a backend.
- Who should use it
- Python developers using pretrained models
- ML engineers fine-tuning language or vision models
- Researchers comparing model architectures
- Builders of inference and training tools
- Setup difficulty
You'll need:
- Python with PyTorch
- uv or pip
- A GPU helps for larger models
How transformers works
Transformers is the model-definition framework for text, vision, audio, video and multimodal models. Each model is one file that reads top to bottom, and new architectures are added as they are released and matched to their original results.
The Pipeline class is the quickest way in: it preprocesses input, runs the model and postprocesses output for a task. You can also generate text with LLMs and vision-language models, chat in the terminal with transformers chat, and serve a model over HTTP with transformers serve for experiments and moderate load.
The library is designed to be easy for people and coding agents to read and change. You can register your own attention function or load optimized kernels from the Hub without editing model code. The README includes a prompt to help coding agents use the current v5 APIs.
Features
Key features
Hundreds of models
Text, vision, audio, video and multimodal architectures.
Pipelines
Run a task end to end with one class.
Training and inference
Use the same model definition for both.
Hugging Face Hub
Load pretrained models by name.
transformers chat and serve
Chat in the terminal or serve a model over HTTP.
Pluggable kernels
Swap attention or load optimized kernels without editing models.
Strengths
- Largest catalog of open models
- Standard, readable model code
- Used as the base by many other tools
- Apache-2.0 license
Limitations
- transformers serve is not meant for large production loads
- Big models need a capable GPU
- Check each model card for its own license and required arguments
Practical use cases
Try an open chat model
Use a text-generation pipeline with a small model like Qwen3-0.6B.
Fine-tune a model
Train a pretrained model on your own data.
Prototype an API
Serve a model with transformers serve for testing.
Installation
Install transformers
Commands come from Transformers's README. AIRepoHub hasn't run them yet. View source
Prerequisites
- Python
- PyTorch
Supported systems
- Windows
- macOS
- Linux
- 1
Install Transformers and PyTorch
Shelluv pip install "transformers[torch]"
- 1
Install with pip
Shellpip install "transformers[torch]" - 2
Check the version
Shellpython -c "import transformers; print(transformers.__version__)"
Configuration and API keys
| Setting | What it's for |
|---|
First run
- 1
Start a chat in your terminal
Shelltransformers chat
transformers's documentation doesn't include sample output, so we don't show any. Expect the results in your terminal.
Your first project
Ask a chat model a question with a pipeline
Load a small chat model from the Hub and get an answer in Python.
Before you start
- Transformers installed with PyTorch
- 1
Create a pipeline and send a message
Textfrom transformers import pipelinepipe = 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"])
What to expect
The model downloads from the Hub and prints a one-sentence answer.
Next steps
- Read the Quickstart on huggingface.co/docs/transformers
- Try another task, like image classification
- Serve a model with transformers serve
Costs and requirements
What it costs to run
- License
- Apache-2.0. Free to use, modify and use commercially.Free
- Software
- Free and open source.Free
- Models
- Most Hub models are free to download; each has its own license.Depends
- Hardware
- Large models may need a paid GPU.Depends
Troubleshooting
Common setup issues
A model needs extra arguments or a newer version
Read the model card on the Hub; many models need a chat template option or a minimum Transformers version.
Code from older tutorials fails
Version 5 changed APIs. Read MIGRATION_GUIDE_V5.md in the repo.
Need production serving
Use an inference engine such as vLLM with the Transformers model as backend.
Alternatives
Similar AI repositories
markitdown
microsoft
Python tool from Microsoft that converts PDFs, Word, Excel, PowerPoint and other files into Markdown for use with AI.
langchain
langchain-ai
Framework for building LLM-powered applications and agents.
pytorch
pytorch
Python framework for building and training neural networks with tensors and GPU acceleration.
Scrapling
D4Vinci
Python web scraping framework for collecting data from websites, from single pages to full crawls.