Accelerate Large Model Training using DeepSpeed
Hugging Face Accelerate can enable DeepSpeed ZeRO data parallelism, which shards optimizer states, gradients and parameters across GPUs and optionally offloads them to CPU, with no or minimal code changes. On two 24GB Titan RTX GPUs, ZeRO Stage-2 allowed 5x larger batches than DDP for DeBERTa-XL (900M) and gave about a 3.5x training speedup with no accuracy loss. BlenderBot-400M fine-tuning saw 2x batch size and a ~1.44x training speedup. ZeRO Stage-3 with CPU offload made GPT-2 XL (1.5B) trainable at batch size 16 where DDP ran out of memory even at batch size 1. The post includes the accelerate config, DeepSpeed JSON configs, and the DummyOptim/DummyScheduler changes needed when the optimizer and scheduler are defined in the DeepSpeed config.
Related posts
- Accelerate Large Model Training using PyTorch Fully Sharded Data Parallel
Hugging Face hardMasterHugging Face Accelerate exposes PyTorch FullyShardedDataParallel (FSDP), which shards parameters, gradients and optimizer states across GPUs (ZeRO stage 2/3) with optional CPU offload, and does so without changes to training code. On 2x24GB Titan RTX GPUs, FSDP gives 2-3x larger batch sizes than DDP for GPT-2 Large. It also trains GPT-2 XL (1.5B), which DDP cannot fit even at batch size 1, and with CPU offload it can do so on a single GPU. DDP with FP16 remained fastest in wall-clock time. Practical caveats: tune the auto-wrap min_num_params, prepare the model before creating the optimizer because parameter flattening loses parameter groups, and note that mixed precision was not yet supported.
- Incredibly Fast BLOOM Inference with DeepSpeed and Accelerate
Hugging Face hardMasterRunning the 176B-parameter BLOOM model (352GB in bf16) for inference is benchmarked across HuggingFace Accelerate, DeepSpeed-Inference and DeepSpeed ZeRO-Inference on an 8x80GB A100 node, with 8-bit quantized variants via BitsAndBytes and DeepSpeed. DeepSpeed-Inference reaches under 1 ms per token at batch size 128, thanks to tensor parallelism and fused CUDA kernels, and its pre-sharded checkpoints load in about a minute. Accelerate's naive pipeline parallelism leaves most GPUs idle but works with almost any model, and it offloads to CPU or disk when GPU memory runs out. ZeRO can run independent streams on each GPU, and int8 halves the memory needed (4 GPUs suffice) at a modest throughput cost. Setup and run commands for each approach are included.
- From DeepSpeed to FSDP and Back Again with Hugging Face Accelerate
Hugging Face hardMasterDeepSpeed ZeRO-3 and PyTorch FSDP gave different training results on Mistral-7B loaded in bfloat16 because DeepSpeed silently upcasts flattened parameters and optimizer state to fp32, while FSDP keeps them in the loaded dtype. That made the same learning rate converge on one backend and stall on the other. Hugging Face Accelerate 0.30.0 adds automatic fp32 upcasting for FSDP when mixed precision is enabled, so FSDP can run either in a DeepSpeed-like mixed-precision mode or in a low-precision mode for memory-constrained setups. In that aligned mode, throughput on four A100s with Granite 7B is roughly equal: about 3159 vs 3095 tokens/sec/GPU and an MFU of 0.41 vs 0.40.
- Accelerate 1.0.0
Hugging Face mediumAdeptHugging Face has published the first release candidates for Accelerate 1.0.0. The library has grown from a thin multi-GPU/TPU training-loop wrapper into the base layer for transformers, diffusers, peft and trl, covering six accelerator types, a launch CLI and big-model inference via device_map="auto". Before 1.0 the team added FP8 support through MS-AMP and TransformerEngine, multi-model DeepSpeed orchestration, torch.compile for big model inference, torch.distributed.pipelining and StatefulDataLoader. Migration notes list the breaking deprecations, such as moving dataloader flags into DataLoaderConfiguration, using AutocastKwargs and renaming is_tpu_available to is_torch_xla_available.
- Fine-tuning Llama 2 70B using PyTorch FSDP
Hugging Face hardMasterFull fine-tuning of Llama 2 70B across two nodes of 8×A100 80GB GPUs with PyTorch FSDP, Hugging Face Accelerate, Transformers and TRL, addressing three obstacles. CPU RAM exhaustion (~2TB if every rank loads the model) is avoided by loading weights only on rank 0 via the meta device and broadcasting with sync_module_states. Slow, NCCL-timeout-prone checkpointing is fixed by saving intermediate checkpoints as SHARDED_STATE_DICT and switching to FULL_STATE_DICT only for the final save. Flash Attention V2 (kernel fusion, tiling, online softmax) plus gradient checkpointing cut VRAM and time; the run finished in ~13.5 hours, with a paged AdamW optimizer needed on a single node.