Skip to main content
LeRobot supports distributed training across multiple GPUs using Hugging Face Accelerate. This can significantly speed up training for large models and datasets.

Quick Start

Train on multiple GPUs with a single command:
This distributes training across 4 GPUs automatically.

Setup

Install Accelerate

Accelerate is included with LeRobot:
Or install separately:

Configure Accelerate

Generate a configuration file:
Answer the prompts:
This creates ~/.cache/huggingface/accelerate/default_config.yaml.

Training with Multiple GPUs

Basic Multi-GPU Training

Use the accelerate launch command:

Inline Configuration

Specify configuration inline without a config file:

YAML Configuration File

Create a custom config file accelerate_config.yaml:
Use it:

Scaling Batch Size

When using multiple GPUs, scale your batch size accordingly:
Each GPU processes batch_size samples, so effective batch size = batch_size × num_gpus.

Adjusting Learning Rate

Scale learning rate with batch size:
Rule of thumb: If you multiply batch size by N, multiply learning rate by √N.

Mixed Precision Training

Use FP16 or BF16 for faster training:

FP16 (Float16)

FP16 is supported on most modern GPUs (NVIDIA Pascal and newer).

BF16 (BFloat16)

BF16 requires Ampere GPUs (A100, RTX 3090, etc.) but is more numerically stable.

Advanced Features

Gradient Accumulation

Simulate larger batch sizes with gradient accumulation:
Effective batch size = 16 × 4 GPUs × 4 accumulation steps = 256.

Selecting Specific GPUs

Use specific GPUs:

DeepSpeed Integration

For very large models, use DeepSpeed:
DeepSpeed config (deepspeed_config.json):

Fully Sharded Data Parallel (FSDP)

For extremely large models:

Implementation Details

LeRobot’s training script uses Accelerate’s Accelerator class:
Key points:
  • accelerator.prepare() wraps objects for distributed training
  • accelerator.backward() handles gradient synchronization
  • Only the main process (rank 0) saves checkpoints

Testing Multi-GPU Setup

Test your setup with a short training run:
Monitor GPU usage:
You should see all GPUs being utilized.

Troubleshooting

Out of Memory (OOM)

Reduce batch size or enable gradient checkpointing:

Slow Data Loading

Increase number of dataloader workers:

GPUs Not All Used

Check that num_processes matches available GPUs:

Different GPU Memory

If GPUs have different memory, use the smallest batch size that fits:

Performance Tips

Benchmark Results

Typical speedup from multi-GPU training: Scaling efficiency depends on:
  • Model size (larger models scale better)
  • Batch size (larger batches scale better)
  • Data loading speed
  • Communication overhead

Multi-Node Training

For training across multiple machines:

Next Steps