02-pipeline-parallelism-bubble-fraction split a model between layers, putting different layers on different GPUs. Tensor parallelism goes a level deeper: it splits a SINGLE layer's matmul itself across GPUs, so even one Linear layer too big to fit on one GPU can still run — but naively splitting a matmul can silently produce the wrong answer unless you split it along the right axis, and know when the pieces can be combined by simple concatenation versus when they need to be summed.
Implement column_parallel_linear and row_parallel_linear — the two standard ways (from Megatron-LM) to split a Linear layer's weight matrix across GPUs — plus the split_weight_by_output_features/split_by_input_features helpers that set each scheme up correctly.
column_parallel_linear: each GPU holds a row-slice of the weight matrix (a slice of the OUTPUT features) and sees the SAME full input; the GPUs' outputs are concatenated along the last axis to reconstruct the full output — no communication needed mid-computation.row_parallel_linear: each GPU holds a column-slice of the weight matrix (a slice of the INPUT features) and only its matching slice of the input; each GPU computes a partial output, and the partials are summed (an all-reduce, 04-collective-communication-primitives) before the (un-split) bias is added once.linear(input, weight, bias) (01-hypothesis-function's function) exactly, for any number of GPUs, including uneven splits.Open one at a time. Each gives away a little more than the last.
Column-parallel splits the weight the same way 05-zero-optimizer-state-sharding splits data — cleanly, with no cross-GPU math needed until the very last concatenation step, because each GPU's output columns don't depend on any other GPU's slice.
Row-parallel is different: each GPU's partial output is only PART of the correct answer (it's missing the contribution from every other GPU's input features), so a plain sum across GPUs — not a concatenation — is what reconstructs the true result.
No results yet
Run your code to check it against the examples, or submit to run every test.