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