HuggingFace stack · LLM / NLP / vision / audio / multimodal · verified against transformers 5.x (2026) · PyTorch-only

transformers cheat sheet

Hugging Face Transformers is the model-definition framework for state-of-the-art models across text, vision, audio and multimodal — for both inference and training. This sheet targets Transformers 5.x, a major release: PyTorch-only (TensorFlow & Flax backends removed), dtype="auto" by default, safetensors-only serialization, and Trainer(processing_class=...). It also folds in the two libraries you always use with it — huggingface_hub (download/upload, Inference) and safetensors (safe weight files). Fast tokenization lives in its own tokenizers sheet.

core objects inference / generate tokenizers / processors training hub & serialization v5 change / gotcha most common

Verified 2026-08-24 against official docs: huggingface.co/docs/transformers (v5), the transformers MIGRATION_GUIDE_V5, huggingface.co/docs/huggingface_hub (v1.x), and huggingface.co/docs/safetensors. Requires Python 3.10+, PyTorch 2.4+. Model-specific APIs vary — always check the model card.

Outline

Grouped by workflow. New to v5? Jump straight to v5 migration & gotchas first — several v4 idioms no longer work.

Get running

  1. 1 · Install & verify
  2. 2 · pipeline() — one-liner inference
  3. 3 · Auto classes & from_pretrained
  4. 4 · dtype, device_map, attention

Inference

  1. 5 · generate() & decoding
  2. 6 · Chat templates & messages
  3. 7 · Vision / audio / multimodal

Tokenizers & data

  1. 8 · Tokenizer & processor
  2. 9 · Padding, truncation, collators

Training

  1. 10 · Trainer & TrainingArguments
  2. 11 · PEFT / LoRA / TRL (cross-ref)

Hub & serialization

  1. 12 · huggingface_hub — download/upload
  2. 13 · InferenceClient (remote)
  3. 14 · safetensors — safe weights

Scale & migrate

  1. 15 · Quantization & performance
  2. 16 · v5 migration & gotchas
  3. Worth memorizing

Get Running

Install, then either the pipeline() shortcut or the explicit Auto-class + from_pretrained path.

1Install & verifytransformers 5.x
2pipeline() — one-liner inferencehigh-level
3Auto classes & from_pretrainedexplicit control
4dtype, device_map & attentionhow it loads

Inference & Generation

Text generation with generate(), the chat-template message format, and the same path for vision/audio.

5generate() & decodingtext generation
6Chat templates & messagesinstruct models
7Vision / audio / multimodalbeyond text

Tokenizers & Data

Turning text into tensors, and batching examples for the model. (Low-level fast tokenizers have their own sheet.)

8Tokenizer & processortext ↔ ids
9Collators for trainingbatch assembly

Training & Fine-tuning

The Trainer loop, and where to go for parameter-efficient (LoRA) and RLHF/SFT training.

10Trainer & TrainingArgumentsthe training loop
11PEFT / LoRA / TRLcross-reference

Hub & Serialization

The two companions folded in here: huggingface_hub (download, upload, remote inference) and safetensors (the safe, fast weight format).

12huggingface_hub — download/uploadhub client · v1.x
13InferenceClient — remote modelsno local weights
14safetensors — safe weightsno pickle

Scale & Migrate

Fit bigger models with quantization, and the v5 changes that break v4 code.

15Quantization & performancefit + speed
16v5 migration & gotchaswhat changed from v4

Worth memorizing

pipeline = fastest startpipeline(task, model) handles tokenize→forward→decode; drop to Auto classes for control
dtype, not torch_dtypev5 renamed the arg and defaults to "auto" (saved precision), not fp32
device_map="auto" needs accelerateshards across GPUs; single device is just .to("cuda")
apply_chat_templatealways render instruct prompts through the model's template, never hand-format
left-pad for batched generateset pad_token and padding_side="left" or decoded text misaligns
Trainer wants processing_classv5 removed tokenizer=; datasets need a labels column for loss
safetensors, never picklesafe + fast + zero-copy; v5 reads/writes nothing else
InferenceClient = no local GPUchat_completion() against hosted providers using your HF token
LoRA via peftget_peft_model + LoraConfig trains MB-sized adapters that plug into Trainer
v5 is PyTorch-onlyTF/Flax removed; read MIGRATION_GUIDE_V5 before upgrading