huggingface-accelerate

Adds distributed training support to PyTorch scripts with a unified API for DDP, DeepSpeed, FSDP, and Megatron.

13.0k|930|Updated Nov 3, 2025
One-click install
npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill huggingface-accelerate-orchestra-research
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: huggingface-accelerate
Source: https://github.com/Orchestra-Research/AI-research-SKILLs/tree/main/08-distributed-training/accelerate
Command: npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill huggingface-accelerate-orchestra-research

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires accelerate, torch, transformers, and includes references (resource) components.

What problem does it solve? Scaling PyTorch training from a single GPU to multi-GPU or multi-node clusters normally requires rewriting code for each distributed backend. This Skill shows how to add distributed support with four lines of code, handling device placement, mixed precision, and backend configuration automatically. ## Core Features & Use Cases - Unified Distributed API: One code path works across DDP, DeepSpeed ZeRO, FSDP, and Megatron-LM without rewriting training loops. - Mixed Precision Training: Enable FP16, BF16, or FP8 with a single Accelerator flag, including gradient scaling for FP16. - Interactive Configuration and Launch: Use accelerate config and accelerate launch to run the same script on single GPU, multi-GPU, multi-node, or TPU setups. - Use Case: You have a single-GPU training script that now needs to run on an 8-GPU node with BF16 and gradient accumulation. Add the Accelerator, call prepare() on your model, optimizer, and dataloader, then launch with one command. ## Quick Start Convert my PyTorch training script to run on multiple GPUs using HuggingFace Accelerate with BF16 mixed precision.

Frequently Asked Questions about huggingface-accelerate

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add multi-GPU support to a PyTorch training script?▼

Add four lines with HuggingFace Accelerate: create an Accelerator, pass your model, optimizer, and dataloader to accelerator.prepare(), and replace loss.backward() with accelerator.backward(loss). Then run with accelerate launch --multi_gpu --num_processes 8 train.py.

Accelerate vs PyTorch Lightning vs DeepSpeed for distributed training?▼

Accelerate offers the lightest abstraction with a unified API over DDP, DeepSpeed, FSDP, and Megatron. Lightning suits users wanting callbacks and high-level structure, while raw DeepSpeed gives direct control over advanced ZeRO features.

Does Accelerate support DeepSpeed ZeRO-3 and FSDP?▼

Yes. Pass a DeepSpeedPlugin with zero_stage=3 or a FullyShardedDataParallelPlugin to the Accelerator, or select them during accelerate config. The training loop code stays identical across backends.

How do I enable BF16 or FP8 mixed precision in Accelerate?▼

Set mixed_precision='bf16' or 'fp8' when creating the Accelerator. BF16 needs no gradient scaler and is more stable, FP16 uses GradScalerKwargs for loss scaling, and FP8 requires H100 GPUs with TransformerEngine.

Why is gradient accumulation not working with Accelerate?▼

Gradient accumulation requires wrapping the step in the accelerator.accumulate(model) context manager and setting gradient_accumulation_steps on the Accelerator. Without the context manager, gradients synchronize every step instead of accumulating.

How do I save checkpoints correctly in distributed training?▼

Use accelerator.save_state('checkpoint/') after accelerator.wait_for_everyone(), and guard main-process-only logic with accelerator.is_main_process. Load with accelerator.load_state() so every process restores its correct shard.