HuggingFace · run PyTorch on any device / distributed config · verified against Accelerate 1.x (2026)

accelerate cheat sheet

Accelerate lets one PyTorch training script run unchanged on CPU, a single GPU, multi-GPU, multi-node, or TPU — with mixed precision (incl. fp8), FSDP and DeepSpeed a config away. You add ~4 lines (Accelerator(), prepare(), accelerator.backward(), drop manual .to(device)) and launch with accelerate launch. It's the distributed engine under 🌐 Transformers' Trainer, usable standalone. This sheet targets Accelerate 1.x.

the 4 code changes launch precision & accumulation distributed helpers scale & big models gotcha most common

Verified 2026-08-24 against the official docs at huggingface.co/docs/accelerate (Accelerate 1.x) and the huggingface/accelerate repo. Wraps native PyTorch DDP/FSDP/DeepSpeed; your model/optimizer/loop stay ordinary PyTorch.

Outline

Learn the 4 edits to a training loop, then how to launch it. Everything else (precision, accumulation, FSDP) is config on top.

Code

  1. 1 · Install & Accelerator
  2. 2 · The training-loop edits

Run

  1. 3 · config & launch
  2. 4 · notebook_launcher

Features

  1. 5 · Mixed precision
  2. 6 · Gradient accumulation & clipping

Multi-process

  1. 7 · Process control & logging
  2. 8 · Save / load / gather

Scale

  1. 9 · FSDP / DeepSpeed
  2. 10 · Big-model inference
  3. 11 · Gotchas
  4. Worth memorizing

The Code Changes

Four edits turn a single-GPU loop into a device-agnostic one.

1Install & Accelerator1.x
2The training-loop editsprepare + backward

Run It

Launch across processes — from CLI or a notebook.

3config & launchCLI
4notebook_launcherJupyter / Colab

Precision & Accumulation

Speed and effective batch size, without manual scaler code.

5Mixed precisionfp16 / bf16 / fp8
6Gradient accumulation & clippingbigger effective batch

Multi-process Control

Do things once, or gather results from every rank.

7Process control & loggingonce vs everywhere
8Save / load / gathercheckpoints & metrics

Scale & Big Models

Shard huge models for training and inference.

9FSDP / DeepSpeedconfig, not code
10Big-model inferenceload huge weights
!Common gotchasread before shipping

Worth memorizing

4 editsAccelerator(), prepare(), accelerator.backward(), drop .to(device)
prepare the dataloaderor every GPU trains on the same batches
accelerate launch, not pythonthe launcher spawns the processes; notebook_launcher in Jupyter
mixed_precision handles the scalerset "bf16"/"fp16"/"fp8"; no manual GradScaler
with accelerator.accumulate(model)clean gradient accumulation, skips sync between boundaries
is_main_process / accelerator.printdo one-time work once; avoid N duplicate logs
unwrap_model before savestrip the DDP/FSDP wrapper; save_state for full resume
gather_for_metrics for evaldrops the distributed sampler's padding
FSDP/DeepSpeed = configenable sharding via accelerate config, not code changes