Hugging Face is an open-source platform and community for machine learning that provides libraries, tools, model repositories, and infrastructure for building, training, sharing, and deploying AI models. The ecosystem encompasses the Transformers v5 library for state-of-the-art models (now PyTorch-first with modular architecture), the Hub for hosting 2M+ models and 500k+ datasets, Datasets for data processing, smolagents for AI agents, and dozens of specialized libraries covering NLP, computer vision, diffusion, reinforcement learning, and robotics. What distinguishes Hugging Face is its radically accessible design—complex ML workflows are abstracted into simple APIs while retaining full configurability, making cutting-edge AI practical for practitioners at every level, from prototyping with single-line pipelines to deploying production inference endpoints at scale.
What This Cheat Sheet Covers
This topic spans 16 focused tables and 138 indexed concepts, 131 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Core Libraries
These are the workhorse packages most Hugging Face projects pull in, each owning one slice of the ML lifecycle — Transformers for models, Datasets for data, PEFT and TRL for fine-tuning and alignment, Diffusers for generation, Accelerate for scaling. Skim this first to know which library to reach for before diving into any task.
| Library | Example | Description | |
|---|---|---|---|
from transformers import pipelineclassifier = pipeline("sentiment-analysis")classifier("This is amazing!") | • Flagship library providing 400+ pretrained transformer model architectures for NLP, vision, audio, and multimodal tasks • v5 is PyTorch-first (drops TensorFlow/Flax), introduces modular architecture, transformers serve OpenAI-compatible server, and quantization as a first-class citizen. | ||
from datasets import load_datasetds = load_dataset("glue", "sst2")ds["train"][0] | • Library for efficient loading and processing of datasets with Apache Arrow backend • supports streaming, mapping, filtering, caching, and memory-mapped access for datasets larger than RAM. | ||
from peft import LoraConfig, get_peft_modelconfig = LoraConfig(r=8, lora_alpha=32)model = get_peft_model(model, config) | • Parameter-Efficient Fine-Tuning library implementing LoRA, QLoRA, DoRA, AdaLoRA, IA3, Prefix Tuning, and P-Tuning • trains adapters that modify <1% of parameters while achieving comparable performance to full fine-tuning. | ||
from trl import SFTTrainer, GRPOTrainertrainer = SFTTrainer(model, args, train_dataset)trainer.train() | • v1.0 post-training library with 75+ methods: SFT, DPO, GRPO, ORPO, KTO, PPO, RLOO, reward modeling • stable core (SFT, DPO, GRPO, RLOO) + experimental layer; integrates with vLLM for async generation. | ||
from diffusers import StableDiffusionPipelinepipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")pipe("A cat in space") | • State-of-the-art diffusion models for image, video, and audio generation • provides modular pipelines for Stable Diffusion XL, FLUX, ControlNet, InstructPix2Pix, and text-to-video models. | ||
from accelerate import Acceleratoraccelerator = Accelerator()model, optimizer = accelerator.prepare(model, optimizer) | • Simplifies distributed training across any hardware configuration (multi-GPU, TPU, mixed precision) by adding just 4 lines of code to native PyTorch • handles device placement, gradient sync, and data parallelism automatically. | ||
from transformers import AutoTokenizertokenizer = AutoTokenizer.from_pretrained("gpt2")tokens = tokenizer("Hello world") | • Rust-based fast tokenizers that train new vocabularies and tokenize at extreme speed (1GB in <20 seconds) • supports BPE, WordPiece, Unigram, and SentencePiece algorithms; v5 uses this as the sole tokenization backend. | ||
from smolagents import CodeAgent, InferenceClientModelagent = CodeAgent(tools=[], model=InferenceClientModel())agent.run("Calculate sum 1 to 100") | • Minimal library for AI agents in ~1000 lines of code; CodeAgent writes Python code to invoke tools and orchestrate other agents• model-agnostic (HF Hub, OpenAI, Anthropic), supports MCP tools, secure sandboxed execution. | ||
import evaluateaccuracy = evaluate.load("accuracy")accuracy.compute(predictions=[0,1], references=[0,1]) | • Unified library providing 100+ evaluation metrics for NLP, vision, audio, and multimodal tasks • supports BLEU, ROUGE, BERTScore, perplexity, and task-specific metrics with a consistent API. | ||
from optimum.onnxruntime import ORTModelForSequenceClassificationmodel = ORTModelForSequenceClassification.from_pretrained("distilbert-base-uncased") | • Hardware-specific optimization library for ONNX Runtime, Intel OpenVINO, Nvidia TensorRT, and other accelerators • exports models to optimized formats and applies quantization, pruning, and graph optimization. | ||
from safetensors.torch import save_file, load_filesave_file(tensors, "model.safetensors") | • Secure and fast tensor serialization format replacing pickle • prevents arbitrary code execution, supports lazy loading, and loads faster than .bin with zero-copy deserialization; default format on the Hub. |