Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Simplest distributed training API. 4 lines to add distributed support to any PyTorch script. Unified API for DeepSpeed/FSDP/Megatron/DDP. Automatic device placement, mixed precision (FP16/BF16/FP8). Interactive config, single launch command. HuggingFace ecosystem standard.
.claude/skills/openlair-huggingface-accelerate/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-09 | ✗→✓ | ▲ Improved | 382% | 0% |
| case-19 | ✗→✓ | ▲ Improved | 28% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 91% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 131% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 65% | 0% |
Accelerate simplifies distributed training to 4 lines of code.
Installation:
bashpip install accelerate
Convert PyTorch script (4 lines):
pythonimport torch + from accelerate import Accelerator + accelerator = Accelerator() model = torch.nn.Transformer() optimizer = torch.optim.Adam(model.parameters()) dataloader = torch.utils.data.DataLoader(dataset) + model, optimizer, dataloader = accelerator.prepare(model, optimizer, dataloader) for batch in dataloader: optimizer.zero_grad() loss = model(batch) - loss.backward() + accelerator.backward(loss) optimizer.step()
Run (single command):
bashaccelerate launch train.py
Original script:
python# train.py import torch model = torch.nn.Linear(10, 2).to('cuda') optimizer = torch.optim.Adam(model.parameters()) dataloader = torch.utils.data.DataLoader(dataset, batch_size=32) for epoch in range(10): for batch in dataloader: batch = batch.to('cuda') optimizer.zero_grad() loss = model(batch).mean() loss.backward() optimizer.step()
With Accelerate (4 lines added):
python# train.py import torch from accelerate import Accelerator # +1 accelerator = Accelerator() # +2 model = torch.nn.Linear(10, 2) optimizer = torch.optim.Adam(model.parameters()) dataloader = torch.utils.data.DataLoader(dataset, batch_size=32) model, optimizer, dataloader = accelerator.prepare(model, optimizer, dataloader) # +3 for epoch in range(10): for batch in dataloader: # No .to('cuda') needed - automatic! optimizer.zero_grad() loss = model(batch).mean() accelerator.backward(loss) # +4 optimizer.step()
Configure (interactive):
bashaccelerate config
Questions:
Launch (works on any setup):
bash# Single GPU accelerate launch train.py # Multi-GPU (8 GPUs) accelerate launch --multi_gpu --num_processes 8 train.py # Multi-node accelerate launch --multi_gpu --num_processes 16 \ --num_machines 2 --machine_rank 0 \ --main_process_ip $MASTER_ADDR \ train.py
Enable FP16/BF16:
pythonfrom accelerate import Accelerator # FP16 (with gradient scaling) accelerator = Accelerator(mixed_precision='fp16') # BF16 (no scaling, more stable) accelerator = Accelerator(mixed_precision='bf16') # FP8 (H100+) accelerator = Accelerator(mixed_precision='fp8') model, optimizer, dataloader = accelerator.prepare(model, optimizer, dataloader) # Everything else is automatic! for batch in dataloader: with accelerator.autocast(): # Optional, done automatically loss = model(batch) accelerator.backward(loss)
Enable DeepSpeed ZeRO-2:
pythonfrom accelerate import Accelerator accelerator = Accelerator( mixed_precision='bf16', deepspeed_plugin={ "zero_stage": 2, # ZeRO-2 "offload_optimizer": False, "gradient_accumulation_steps": 4 } ) # Same code as before! model, optimizer, dataloader = accelerator.prepare(model, optimizer, dataloader)
Or via config:
bashaccelerate config # Select: DeepSpeed → ZeRO-2
deepspeed_config.json:
json{ "fp16": {"enabled": false}, "bf16": {"enabled": true}, "zero_optimization": { "stage": 2, "offload_optimizer": {"device": "cpu"}, "allgather_bucket_size": 5e8, "reduce_bucket_size": 5e8 } }
Launch:
bashaccelerate launch --config_file deepspeed_config.json train.py
Enable FSDP:
pythonfrom accelerate import Accelerator, FullyShardedDataParallelPlugin fsdp_plugin = FullyShardedDataParallelPlugin( sharding_strategy="FULL_SHARD", # ZeRO-3 equivalent auto_wrap_policy="TRANSFORMER_AUTO_WRAP", cpu_offload=False ) accelerator = Accelerator( mixed_precision='bf16', fsdp_plugin=fsdp_plugin ) model, optimizer, dataloader = accelerator.prepare(model, optimizer, dataloader)
Or via config:
bashaccelerate config # Select: FSDP → Full Shard → No CPU Offload
Accumulate gradients:
pythonfrom accelerate import Accelerator accelerator = Accelerator(gradient_accumulation_steps=4) model, optimizer, dataloader = accelerator.prepare(model, optimizer, dataloader) for batch in dataloader: with accelerator.accumulate(model): # Handles accumulation optimizer.zero_grad() loss = model(batch) accelerator.backward(loss) optimizer.step()
Effective batch size: batch_size * num_gpus * gradient_accumulation_steps
Use Accelerate when:
Key advantages:
Use alternatives instead:
Issue: Wrong device placement
Don't manually move to device:
python# WRONG batch = batch.to('cuda') # CORRECT # Accelerate handles it automatically after prepare()
Issue: Gradient accumulation not working
Use context manager:
python# CORRECT with accelerator.accumulate(model): optimizer.zero_grad() accelerator.backward(loss) optimizer.step()
Issue: Checkpointing in distributed
Use accelerator methods:
python# Save only on main process if accelerator.is_main_process: accelerator.save_state('checkpoint/') # Load on all processes accelerator.load_state('checkpoint/')
Issue: Different results with FSDP
Ensure same random seed:
pythonfrom accelerate.utils import set_seed set_seed(42)
Megatron integration: See references/megatron-integration.md for tensor parallelism, pipeline parallelism, and sequence parallelism setup.
Custom plugins: See references/custom-plugins.md for creating custom distributed plugins and advanced configuration.
Performance tuning: See references/performance.md for profiling, memory optimization, and best practices.
Launcher requirements:
torch.distributed.run (built-in)deepspeed (pip install deepspeed)| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 21,004 | 10,311 | -51% | 1 | 1 | 0% | 2,148 | 4,259 | +98% | 0 | 0 | — |
case-02 | pass→pass | 8,756 | 7,419 | -15% | 1 | 1 | 0% | 2,030 | 3,885 | +91% | 0 | 0 | — |
case-03 | pass→pass | 8,477 | 9,228 | +9% | 1 | 1 | 0% | 1,770 | 4,084 | +131% | 0 | 0 | — |
case-04 | pass→pass | 13,105 | 9,559 | -27% | 1 | 1 | 0% | 2,673 | 4,418 | +65% | 0 | 0 | — |
case-05 | pass→pass | 10,339 | 7,963 | -23% | 1 | 1 | 0% | 2,220 | 4,047 | +82% | 0 | 0 | — |
case-06 | pass→pass | 10,384 | 7,201 | -31% | 1 | 1 | 0% | 2,265 | 3,760 | +66% | 0 | 0 | — |
case-07 | pass→pass | 11,357 | 7,797 | -31% | 1 | 1 | 0% | 2,462 | 4,002 | +63% | 0 | 0 | — |
case-08 | pass→pass | 5,007 | 4,021 | -20% | 1 | 1 | 0% | 897 | 2,821 | +214% | 0 | 0 | — |
case-09 | fail→pass | 3,923 | 1,941 | -51% | 1 | 1 | 0% | 503 | 2,426 | +382% | 0 | 0 | — |
case-10 | pass→pass | 5,177 | 3,286 | -37% | 1 | 1 | 0% | 978 | 2,781 | +184% | 0 | 0 | — |
case-11 | pass→pass | 3,902 | 3,064 | -21% | 1 | 1 | 0% | 571 | 2,689 | +371% | 0 | 0 | — |
case-12 | fail→fail | 9,961 | 5,314 | -47% | 1 | 1 | 0% | 1,551 | 3,190 | +106% | 0 | 0 | — |
case-13 | pass→pass | 9,821 | 8,770 | -11% | 1 | 1 | 0% | 1,710 | 3,728 | +118% | 0 | 0 | — |
case-14 | pass→pass | 4,878 | 4,258 | -13% | 1 | 1 | 0% | 899 | 2,880 | +220% | 0 | 0 | — |
case-15 | pass→pass | 5,327 | 6,573 | +23% | 1 | 1 | 0% | 1,036 | 3,320 | +220% | 0 | 0 | — |
case-16 | pass→pass | 14,459 | 14,394 | -0% | 1 | 1 | 0% | 2,078 | 4,126 | +99% | 0 | 0 | — |
case-17 | pass→pass | 4,495 | 2,989 | -34% | 1 | 1 | 0% | 668 | 2,655 | +297% | 0 | 0 | — |
case-18 | pass→pass | 6,910 | 5,045 | -27% | 1 | 1 | 0% | 1,107 | 3,084 | +179% | 0 | 0 | — |
case-19 | fail→pass | 10,571 | 2,675 | -75% | 1 | 1 | 0% | 2,012 | 2,582 | +28% | 0 | 0 | — |
case-20 | fail→fail | 10,352 | 7,119 | -31% | 1 | 1 | 0% | 2,098 | 3,566 | +70% | 0 | 0 | — |
case-21 | pass→pass | 9,288 | 7,570 | -18% | 1 | 1 | 0% | 1,518 | 3,831 | +152% | 0 | 0 | — |
case-22 | pass→pass | 10,972 | 6,007 | -45% | 1 | 1 | 0% | 1,825 | 3,415 | +87% | 0 | 0 | — |
case-23 | pass→pass | 9,276 | 5,051 | -46% | 1 | 1 | 0% | 2,021 | 3,203 | +58% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.