C.W.K.
Stream
Lesson 01 of 06 · published

Installation and the Three-Backend Reality

~25 min · transformers, install

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

Three backends, one library

The transformers library targets PyTorch (default), TensorFlow, and JAX/Flax. In 2026 the only backend you should reach for is PyTorch unless you have a specific reason — TF support is in maintenance mode upstream, JAX/Flax is alive but a niche choice for research. 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-cli env

Before you debug "why is this slow," run transformers-cli 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-cli 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-cli 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 inPlease sign in to comment.

No comments yet — be the first.