Distributed training
Training requires memory for model weights, gradients, and the optimizer’s running estimates. PyTorch FSDP2 partitions this state across GPUs. Each GPU stores its own shard, gathers the weights needed to compute a model block, and receives the corresponding gradient shard after backward. The optimizer then updates the locally owned weights and state. This makes room for models and batches that would otherwise consume too much memory on one GPU.
Hybrid sharding, or HSDP, adds data parallelism to that arrangement. A group of GPUs jointly holds one copy of the model; several such groups process different batches. In the diagram, GPUs 1 and 2 form one replica and GPUs 3 and 4 form another. Matching shards synchronize their gradients before the update, so both replicas learn from the combined data.
Tensor parallelism divides computation within a layer, such as splitting a projection matrix and combining its partial outputs. Pipeline parallelism assigns successive model blocks to different GPUs and passes activations and gradients between their owners. SomaSpeed’s pipeline stages execute synchronously in the model’s original call order. These strategies can be combined, with the choice of layout balancing memory capacity and communication cost.
Return gradients to their owning shards
Return gradients to their owning shards
A, B, C are microbatches. Forward calls execute on their owning stage in sequence. Backward returns gradients through the same stage boundaries.