8/11
Part 6 of 7 · The worked exampleLearn and do

A worked example: the sharding sheet

The prompt, from a candidate's Anthropic session: work out what different ways of sharding a model cost in compute, memory and network (1 source). Build it one column at a time:

  1. Memory: what each GPU holds, and what fits.
  2. Compute: 6 operations per parameter per token, at a realistic share of the peak.
  3. Traffic: data-parallel traffic on InfiniBand, tensor-parallel traffic on NVLink.
  4. The bubble, if there's a pipeline.

Here's the sheet for the shop's fine-tune on 64 GPUs, two ways, and the same plan at Llama 3 405B's scale, with its 126 layers and model dimension of 16,384.

def plan(tp, pp, dp, zero, params, tokens, layers, hidden, seq=8_192):
    """One training step's memory, traffic and compute, with tensor parallel inside a node."""
    shard = params / (tp * pp)
    weights, grads, states = 2.0, 2.0, 12.0
    if zero >= 1:
        states /= dp
    if zero >= 2:
        grads /= dp
    if zero >= 3:
        weights /= dp
    memory = shard * (weights + grads + states) / 1e9
    infiniband = (1.5 if zero >= 3 else 1.0) * 2 * (dp - 1) / dp * 2 * shard / 50e9
    # sequences each tensor-parallel group runs
    sequences = tokens / seq / dp
    nvlink = sequences * layers / pp * 4 * 2 * (tp - 1) / tp * seq * hidden * 2 / 450e9
    compute = 6 * params * tokens / (tp * pp * dp * 989e12 * 0.40)
    print(f"TP {tp} DP {dp:6,} ZeRO {zero}: {memory:5.1f} GB, {infiniband:4.1f} s InfiniBand, {nvlink:4.1f} s NVLink, {compute:4.1f} s compute")


# the shop's fine-tune, sharded data parallel only
plan(1, 1, 64, 3, 70e9, 4e6, 80, 8_192)
# the shop's fine-tune, 8-way tensor parallel
plan(8, 1, 8, 1, 70e9, 4e6, 80, 8_192)
# 405B on 16,384 GPUs, sharded data parallel only
plan(1, 1, 16_384, 3, 405e9, 16e6, 126, 16_384)
Predict

The same sharded data parallel plan works for the shop's 70B model on 64 GPUs. What happens to it for 405B on 16,384 GPUs?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

Llama 3 used tensor parallel 8. Why exactly 8?

Pick an answer above to see the rest