Splitting a model
Why split a model
A 70B model at 2 bytes per weight needs 140 GB, but one GPU has 80 GB. So you split it across several GPUs. Remember the KV cache too: weights plus cache must fit. Splitting can also cut latency, because with each layer split, each GPU reads only part of the weights for each token, all at once.
Tensor parallelism
In tensor parallelism, each GPU holds a slice of every layer's weights. After each layer, the GPUs swap their partial results to build the full answer. That happens many times per token, so they need fast links. NVLink joins GPUs inside one machine directly and is much faster than PCIe, the ordinary slot.
Pipeline parallelism
In pipeline parallelism, each GPU holds a range of whole layers, called a stage. A stage passes its token vectors to the next stage, so there is little talk. But a stage can sit idle while it waits for work. These gaps are bubbles. Many requests in flight fill them. Pipelining does not make one request faster.
Data parallelism
Data parallelism runs full copies of the model, called replicas. A load balancer sends each request to one copy. The copies never talk, so more copies serve more users. But each copy needs all the memory, and each answer is no faster.
Picking the split
GPUs in one machine (a node) talk over NVLink. Machines talk over the network, like InfiniBand, which is much slower than NVLink. A common plan:
- Fits on one GPU: add replicas.
- Too big for one GPU: tensor parallelism inside one machine.
- Too big for one machine: add pipeline stages across machines.
Fewer GPUs per copy means less talk; more GPUs per copy means faster tokens.
Remember
- Split when weights plus cache don't fit, or to cut latency.
- Tensor: a slice of every layer, swaps every layer, needs NVLink.
- Pipeline: ranges of layers, little talk, bubbles.
- Data: full copies, no talk, each needs all the memory.
- Tensor inside a machine, pipeline across machines.