transformers logo

transformers

Free

🤗 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.

Model APIsFreeFree tier
Inputs: text, image, audio, videoOutputs: text, image, audio, video
Type
Open Source
Company
Hugging Face

About transformers

Transformers is Hugging Face's model-definition framework for state-of-the-art machine learning models in text, computer vision, audio, video, and multimodal modalities, supporting both inference and training. It centralizes model definitions so they are compatible across the ecosystem, including training frameworks like Axolotl, Unsloth, DeepSpeed, FSDP, PyTorch-Lightning; inference engines like vLLM, SGLang, TGI; and adjacent libraries like llama.cpp and mlx. Key components include a Pipeline class for optimized inference on tasks such as text generation, image segmentation, automatic speech recognition, and document question answering; a Trainer class supporting mixed precision, torch.compile, FlashAttention, and distributed training; and a generate function for fast text generation with LLMs and VLMs, with streaming and multiple decoding strategies. The project hosts over 1 million pretrained model checkpoints on the Hugging Face Hub, designed for developers, ML engineers, and researchers, with principles of speed, ease of use, and leveraging pretrained models to reduce computational cost and time.

Key Features

Pipeline class for simple and optimized inference across dozens of tasks (text generation, image segmentation, speech recognition, document QA)
Trainer class with support for mixed precision, torch.compile, FlashAttention, and distributed PyTorch training
generate function for fast text generation from LLMs and VLMs, with streaming and multiple decoding strategies
Centralized model definition compatible with major training frameworks (Axolotl, Unsloth, DeepSpeed, FSDP, PyTorch-Lightning), inference engines (vLLM, SGLang, TGI), and adjacent libraries (llama.cpp, mlx)
Over 1 million pretrained model checkpoints available on the Hugging Face Hub

Pros & Cons

Pros
  • Open-source and free to use under the Apache 2.0 license
  • Supports a wide range of modalities including text, vision, audio, video, and multimodal
  • Large ecosystem with over 1 million pretrained checkpoints and compatibility with many third-party tools
  • Designed for both researchers and engineers with high-level APIs (Pipeline, Trainer) and low-level customization
  • Active community and continuous addition of new state-of-the-art models
Cons
  • Requires familiarity with Python and deep learning concepts for effective use
  • Large models can be resource-intensive; optimal performance may need specialized hardware (GPUs/TPUs) and optimization libraries
  • Documentation can be overwhelming due to the breadth of supported models and tasks

Best For

Inference and training of state-of-the-art models in text, computer vision, audio, video, and multimodal domainsRapid prototyping and research with pretrained models to reduce compute costs and development timeIntegration into production pipelines using compatible inference engines like vLLM or TGIBuilding custom models with a simple three-class structure (configuration, model, preprocessor)Exploring and benchmarking the latest model architectures via the Models Timeline on the Hub

Alternatives to transformers

FAQ

What is Transformers?
Transformers is an open-source model-definition framework by Hugging Face that provides state-of-the-art pretrained models for text, vision, audio, video, and multimodal tasks, supporting both inference and training.
What modalities does Transformers support?
It supports text, computer vision, audio, video, and multimodal models.
How do I get started with Transformers?
You can start by installing the library (pip install transformers) and using the Pipeline API for inference or the Trainer for training. Over 1 million pretrained checkpoints are available on the Hugging Face Hub.
Is Transformers free?
Yes, Transformers is completely free and open-source under the Apache 2.0 license.