Favicon of Transformers

Transformers

An Apache 2.0 Python library for local AI inference and training across text, vision and audio, with PyTorch support and pretrained models.

Screenshot of Transformers website

Transformers is a Python library for developers and researchers running pretrained AI models or training models on their own hardware. It covers text, images, audio, video and multimodal tasks through shared model definitions.

  • Task-based inference: The Pipeline API handles input preparation and output for tasks such as text generation, image segmentation, speech recognition and document question answering.
  • Language and vision generation: Generate text with language and vision language models, including streaming output and different decoding strategies.
  • Model training: Trainer supports PyTorch model training with distributed execution, mixed precision and FlashAttention.
  • Model customization: Inspect and adapt model implementations, or use individual model files for experiments.
  • Ecosystem compatibility: Supported model definitions are used by training tools such as Axolotl and Unsloth and inference engines such as vLLM and SGLang, as well as llama.cpp and mlx.

The library runs in a local Python environment with PyTorch. The separate Hugging Face Hub provides pretrained checkpoints. Transformers is open source under Apache 2.0.

Its training API is designed around the PyTorch models supplied by Transformers. It isn't a general-purpose collection of neural network building blocks, and example training scripts may need adaptation for your task.

Similar to Transformers