Transformers is a Python library that defines pretrained text, vision, audio, and multimodal models once in PyTorch for shared inference and training across the ecosystem.
Overview
Transformers standardizes how hundreds of architectures are expressed so training tools, inference engines, and local runtimes can reuse the same model files. Each implementation follows configuration, model, and preprocessor patterns intended to stay readable while matching original paper results.
Users load checkpoints from the Hugging Face Hub or local paths, then run tasks through Pipeline helpers, chat interfaces, or custom training loops. Generation APIs cover decoding strategies and streaming for large language and vision-language models.
Serving options include a built-in HTTP server for experiments, continuous batching for throughput, and backends that plug into vLLM or SGLang. Training support spans Trainer workflows, parameter-efficient fine-tuning, fully sharded data parallel training, tensor and expert parallelism, quantization, and swappable attention kernels.
Contributors can add architectures via modular inheritance, register custom attention or expert functions, and rely on automated tests that expand from small model-specific suites. Documentation and courses guide installation, task selection, and agent-oriented setup prompts.
Key features
- Unified PyTorch model definitions
- Hugging Face Hub checkpoint loading
- Pipeline task inference helpers
- Text and multimodal generation APIs
- Trainer and distributed training options
- PEFT and quantization workflows
- Local serve and chat CLI tools
- Modular model contribution flow
Use cases
- Running pretrained NLP and vision models
- Fine-tuning models on custom datasets
- Serving models to apps via HTTP or engines