As asked
You are training a model with 7B parameters using DDP across 64 GPUs. Calculate the per-GPU data transmitted during one allreduce of the full gradient, assuming bf16 precision. How does this change if you switch to FSDP FULL_SHARD?
Sample answer outline
DDP allreduce: each GPU sends and receives 2 * (N-1)/N * message_size; for N=64 this is approximately 2 * message_size. 7B params * 2 bytes (bf16) = 14 GB per allreduce. With FSDP FULL_SHARD, the reduce-scatter transmits message_size * (N-1)/N and all-gather transmits the same, totaling 2 * 14 GB / 64 * (N-1) roughly but each rank only holds 1/N of the parameters, so peak in-flight per rank is much smaller. The candidate should derive the formula not just give the number.
Reference implementation (python)
# Estimate allreduce traffic for DDP vs FSDP
num_params = 7e9
bytes_per_param_bf16 = 2 # bf16
world_size = 64
# DDP: ring-allreduce sends 2*(N-1)/N * data per GPU
ddp_bytes_per_gpu = 2 * (world_size - 1) / world_size * num_params * bytes_per_param_bf16
print(f"DDP allreduce per GPU: {ddp_bytes_per_gpu / 1e9:.2f} GB")
# FSDP FULL_SHARD: reduce-scatter + all-gather, each ~data/N per rank per step
# Each rank stores 1/N params, but communicates full gradient volume in sharded fashion
fsdp_reduce_scatter = num_params * bytes_per_param_bf16 * (world_size - 1) / world_size
fsdp_all_gather = num_params * bytes_per_param_bf16 * (world_size - 1) / world_size
print(f"FSDP reduce-scatter per GPU: {fsdp_reduce_scatter / 1e9:.2f} GB")Expect these follow-ups
- How would you measure actual allreduce bandwidth vs. theoretical peak bandwidth in your cluster?