Column parallelism: partition output features without summing them
Track matrix axes, local bias slices, and input-gradient reduction across a partitioned linear layer.
On this page
The question for today
What you’ll understand
- Derive local shapes for an output-feature partition.
- Place bias and elementwise activation correctly on output shards.
- Explain why input gradients may require a sum even when forward outputs do not.
Tensor parallelism distributes one layer’s computation across devices rather than giving every device a complete independent model copy. This module uses row-token notation Y=XW+b, with X shaped [M,H] and W shaped [H,O]. PyTorch Linear stores the transposed weight convention, so axis names must be translated when reading code. Library examples are scoped to Megatron Core 0.15.0 and PyTorch 2.8; the algebra specifies the result while layout and communication choices remain explicit.
Split the feature axis that creates independent outputs
Partition W by its output columns, giving rank i a matrix W_i with shape [H,O/P] for an even P-way split. Every rank needs the input features required by that multiplication. With replicated X, each rank computes its own output-feature slice without summing other ranks’ forward products. Concatenating those slices in the correct global feature order reconstructs Y. Calling an output slice partial can be ambiguous: it is a complete value for selected features, not a pending sum contribution for every feature.
Bias is partitioned along the same output-feature axis. Rank i adds b_i exactly to its own complete output slice. An elementwise activation can remain local because it does not mix different output coordinates. A later operation that needs the entire hidden vector may require gathering or a compatible partitioned algorithm. The useful design often keeps the intermediate sharded until a complementary row-parallel layer consumes it, avoiding a needless full reconstruction between stages.
Backward follows the shared-input dependency
Each local output gradient produces a local weight gradient using the same X and its local dY_i. The input gradient, however, combines contributions from every output-feature partition. Under a replicated-input layout, the complete dX is the sum of local dY_i W_i-transpose products. Omitting that sum can leave the forward output correct while training the earlier layer incorrectly. If the desired backward layout shards tokens, a reduce-scatter may deliver the needed summed pieces instead of a replicated all-reduce.
The communication schedule therefore depends on input and output placements, not just the phrase column parallel. A sequence-sharded input may be gathered before the multiplication, while an output may optionally be gathered afterward. Autograd mappings determine where reductions occur. Inspect the versioned library contract and actual layout transitions. State exactly which tensor is replicated, sharded, or a pending sum before quoting a forward/backward collective count; otherwise two correct implementations can appear to disagree only because their boundaries differ.
Validate the column order before measuring speed
A shard with the right shape can still contain the wrong output columns. Test known matrices that distinguish every feature, then reconstruct in documented rank and feature order. Include nonzero bias so a missing slice or accidental duplicate becomes visible. For training, compare local weight gradients and the assembled input gradient against a dense reference. Numerical tolerance should reflect dtype and reduction order; shape agreement alone is weak evidence of mathematical equivalence.
The matrix lab shows one fixed two-dimensional family rather than arbitrary tensor shards. Reset, set diagonal scale a=1 and shear b=1, predict determinant one, then Step. The selected transform is [[1,1],[0,1]], with readouts describing that final matrix even during interpolation. It does not multiply distributed tensors or reconstruct column shards. Use it only to inspect an explicit linear map while the worked matrix calculation establishes the partitioned layer’s actual values.
Work it through
Two devices own different output columns
Let X=[1,2], W have rows [1,3,5,7] and [2,4,6,8], and b=[1,0,−1,2]. Two devices own the first and last two output columns respectively.
Rank 0 computes XW0=[1×1+2×2,1×3+2×4]=[5,11]. Its bias slice [1,0] gives Y0=[6,11].
Rank 1 computes XW1=[1×5+2×6,1×7+2×8]=[17,23]. Adding bias [−1,2] gives Y1=[16,25].
Concatenate the complete feature slices in order to recover Y=[6,11,16,25]. Each device stores four of the eight weight elements. Summing Y0 and Y1 elementwise would mix different output features and give the wrong layer.
Column partitioning produces different complete output coordinates. It requires concatenation for reconstruction, while the shared-input gradient combines by summation.
The living notebook
Explore the model
Interactive lab · matrix
Inspect a known linear map
Reset, set a=1 and b=1, predict determinant 1, then Step. This fixed triangular 2D transform interpolates geometry while readouts describe the selected matrix. It is not a distributed matrix multiplication, arbitrary weight editor, or shard reconstruction.
- Area scale · det A
- 1.4
- Singular values · σmax, σmin
- 1.597, 0.876
- Condition number · κ₂(A)
- 1.823
The selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA precise map and axis convention come before a correct partitioning argument.
Pause & reason
Check your understanding
Your turn
Try it yourself
X=[2,1], W has rows [1,2] and [3,4], and b=[0,1]. Two ranks own one output column each. Compute both outputs and the reconstructed vector.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use the full two-feature input on each rank and its own one-entry bias slice.
Compare with the solution
Rank 0 computes 2×1+1×3=5. Rank 1 computes 2×2+1×4+1=9. Reconstruction is [5,9], using concatenation. The input-gradient sum depends on the chosen loss and must be checked separately; forward agreement does not establish backward correctness.
Keep the idea
Take it with you
- Output-column shards contain different complete feature values.
- Bias slices and elementwise activation can follow those output shards.
- The shared-input gradient combines contributions from every output partition.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.