Skip to content
C.W.K.
Lesson 01 of 06 · published

Installation and the One-Backend Reality

~25 min · transformers, install

Level 0Scout
0 XP0/50 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

One library, one backend

Since v5, transformers supports PyTorch only; the TensorFlow and JAX/Flax backends were removed. On Apple Silicon, PyTorch with MPS is the default; for serious local inference the MLX backend (separate from transformers) wins on memory.

What you install:

  • transformers — the model classes, tokenizers, pipelines.
  • torch — the backend. Pick the wheel matching your hardware (CUDA, MPS, CPU).
  • accelerate — required for any multi-GPU / mixed-precision / device_map auto.
  • safetensors — safe weight format. Bundled with modern transformers.
  • Optional: bitsandbytes for 8/4-bit quantization, peft for LoRA, datasets for data loading.

Verify the install with transformers env

Before you debug "why is this slow," run transformers env. The output is the answer to 80% of "is my CUDA actually working" tickets — it prints the platform, Python, transformers, and torch versions; whether CUDA / MPS is available; and the GPU name. Paste this into any bug report.

Code

Install transformers correctly per platform·bash
# Linux + CUDA
pip install --upgrade torch  # match the CUDA version of your system
pip install --upgrade transformers accelerate safetensors

# macOS Apple Silicon (MPS)
pip install --upgrade torch torchvision torchaudio
pip install --upgrade transformers accelerate safetensors

# Verify
python -c "import torch; print('cuda:', torch.cuda.is_available(), 'mps:', torch.backends.mps.is_available())"
transformers env
Smallest possible smoke test·python
from transformers import pipeline

# Tiny BERT for fast iteration. Loads in seconds.
pipe = pipeline("text-classification", model="prajjwal1/bert-tiny")
print(pipe("Hugging Face is the GitHub of AI."))
# [{'label': 'LABEL_0', 'score': 0.5...}]

External links

Exercise

Set up a fresh venv. Install transformers + torch matching your platform. Run transformers env and save the output. Run the bert-tiny smoke test. Then load meta-llama/Llama-3.2-1B-Instruct (or any 1B-class model with apache/mit license if Llama is gated) with pipeline('text-generation', ...) and generate one short sentence.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign in — Please sign in to comment.

No comments yet — be the first.