The central model-definition framework for state-of-the-art ML models across text, vision, audio, video, and multimodal tasks. Provides pretrained model weights, tokenizers, pipelines, and training APIs. Interfaces with PyTorch (primary), with 400+ model architectures and 750k+ checkpoints on the Hub. MAJOR VERSION NOTE: v5 released late 2025 — first major release in 5 years. v5 is PyTorch-only (TensorFlow/Flax/JAX removed). pip install transformers installs v5 as of Feb 2026. v4 was the last stable version before this; v4.57.x is the last v4 release. Requires Python 3.10+ in v5.
pip install transformers[torch]Verified import paths — ran on the pinned version, not inferred.
pipeline() handles everything automatically. For quantization in v5, use BitsAndBytesConfig — passing load_in_4bit=True directly to from_pretrained() is removed.
Migrate to PyTorch. If TF/Flax is required, pin: pip install 'transformers<5'. Last v4 release: 4.57.3.
from transformers import BitsAndBytesConfig; model = AutoModel.from_pretrained(id, quantization_config=BitsAndBytesConfig(load_in_4bit=True))
Replace AutoFeatureExtractor with AutoImageProcessor. Install torchvision if missing.
Replace encode_plus() with direct tokenizer() call: tokenizer(text, truncation=True, padding='max_length', max_length=128, return_tensors='pt')
Replace: export TRANSFORMERS_CACHE=/path with: export HF_HOME=/path
Upgrade to Python 3.10+. Or pin transformers<5 for Python 3.9.
Always install with extras: pip install transformers[torch]. Or install torch separately first.
Set HF_HOME to a volume with sufficient space. Pre-download models using snapshot_download() or huggingface-cli download.
pip install accelerate alongside transformers.
Ensure your Alpine environment has `build-base` and `rust` packages installed (e.g., `apk add build-base rust`). For newer Python versions or if issues persist, consider using official Python images based on glibc (e.g., `python:3.x-slim-bullseye` instead of `python:3.x-alpine`) or explicitly pinning `tokenizers` to a version with a compatible musl wheel if available.
Migrate your code to use PyTorch-compatible classes and functions, or downgrade `transformers` to a v4 version (e.g., `pip install transformers==4.x.x`) if TensorFlow support is essential.
Upgrade your Python installation to version 3.10 or higher, or install `transformers` v4 (e.g., `pip install transformers==4.x.x`) if you need to use an older Python version.
Add `trust_remote_code=True` to your `from_pretrained()` call (e.g., `AutoModel.from_pretrained('org/model', trust_remote_code=True)`), but only if you understand and trust the source of the custom code.Double-check the model name for typos, ensure you have an an active internet connection, and if it's a private model, ensure you are logged in (`huggingface-cli login`) or provide a valid authentication token.