advanced27 min studyLesson 552 in Engineering

Row parallelism: sum partial products before adding bias

Partition input features, reduce their contributions, and preserve nonlinear and bias semantics.

On this page

What you’ll understand

  • Derive input-feature shards and same-shaped partial outputs.
  • Explain why summation precedes nonlinear operations.
  • Prevent replicated bias from being multiplied by the parallel degree.

A row-parallel layer partitions the input-feature axis of W in our XW convention. Each rank computes a contribution to every output coordinate from only some input features. Those contributions must be combined to obtain the actual output. This is fundamentally different from concatenating output-feature shards. The distinction determines where a reduction, a bias, and an activation belong, and it explains why two similarly shaped local tensors can have very different meanings.

Match the input shard to the corresponding weight rows

Split X into feature blocks X_i with shape [M,H/P], and split W into matching row blocks W_i shaped [H/P,O]. Their local product Z_i has shape [M,O], the same shape on every rank. Each Z_i is missing the other ranks’ feature contributions. It is therefore a pending sum rather than a complete replica. Reconstructing Y requires a sum of Z_i, then the appropriate bias. Concatenating these products would multiply the apparent output width instead of restoring the layer.

A preceding column-parallel expansion can leave its intermediate output features already partitioned in the form this layer needs. That pairing permits local intermediate activation followed by the row-parallel multiplication, without gathering that intermediate solely to repartition it. The exact forward collective can yield a replicated complete output or reduce-scattered token shards, depending on the next layer. Preserve the mathematical sum while choosing the placement that avoids unnecessary traffic for the surrounding computation.

X=[X0  ⋯  XP−1],W=[W0⋮WP−1],Y=∑iXiWi+bX=[X_0\;\cdots\;X_{P-1}],\quad W=\begin{bmatrix}W_0\\\vdots\\W_{P-1}\end{bmatrix},\quad Y=\sum_i X_iW_i+b
X_i is M×(H/P), W_i is (H/P)×O, and each partial product is M×O. Even feature partitioning is assumed. The replicated bias b is added once to the complete result, not once to every summand.↔ Scroll wide equations horizontally.

The location of a nonlinear operation changes the function

In general, applying a nonlinear activation to each Z_i and then adding does not equal activating their sum. A negative partial contribution can cancel a positive one before the activation, while separate activation would remove that cancellation. The same issue appears with normalization across output features: a local incomplete sum is not a valid complete token vector. Make the pending-reduction status explicit so later code cannot accidentally treat a same-shaped local tensor as a fully computed value.

A replicated output bias added before summing would appear P times. The simple safe convention is to add it after reduction. Some fused implementations return bias separately for a later fused operation; others use carefully equivalent distribution rules. Read the actual API instead of adding a second bias because a local output initially appears unbiased. Backward must likewise respect the decomposition: a full upstream output gradient supplies each input shard’s gradient through its local W_i, with further communication determined by how that upstream gradient is placed.

dXi=dYWiT,dWi=XiTdYdX_i=dY W_i^{\mathsf T},\qquad dW_i=X_i^{\mathsf T}dY
dY is the complete M×O upstream gradient for the layer output. dX_i is M×(H/P), and dW_i is (H/P)×O. This assumes the required dY values are available; obtaining them may require a layout transition.↔ Scroll wide equations horizontally.

Test cancellation and a nonzero replicated bias

Use test matrices whose local products have different signs and magnitudes. A test with all zeros can hide missing reductions, and a zero bias cannot reveal duplicate bias addition. Compare a known dense output, then compare backward gradients under one declared loss normalization. An implementation can have the right output shape while silently applying a nonlinear operation too early. Keep dtype, parameter initialization, and the exact output-feature order fixed when comparing layouts.

The function lab gives a direct nonlinear counterexample. Reset, set a=1 and x=1, predict y=1, then Step. Change x to 2 and observe y=4; two copies of f(1) sum to 2, while f(1+1)=4. The input control remains in range and edits retain time, which does not change these selected readouts. This one quadratic is not a row-parallel layer, but it demonstrates why a nonlinear map cannot generally move across a sum without changing the function.

Two feature contributions and one bias

Let X=[1,2], W have rows [1,2] and [3,4], and b=[1,−1]. Rank 0 owns the first input feature and weight row; rank 1 owns the second.

  1. Rank 0 computes [1]×[1,2]=[1,2]. Rank 1 computes [2]×[3,4]=[6,8]. Each local result has both output coordinates but is incomplete.

  2. Summing gives [7,10]. Add the replicated bias once after the sum to obtain Y=[8,9].

  3. If both ranks added the full bias before summation, their results would be [2,1] and [7,7], summing to [9,8]. The error is exactly one extra copy of the bias because P=2.

The result

Row parallelism reduces contributions to the same coordinates. Bias duplication and premature nonlinear operations change the intended layer.

Explore the model

Interactive lab

Interactive lab · function

A nonlinear map cannot freely cross a sum

Reset, set a=1 and x=1, predict y=1, then Step. Set x=2 to observe y=4, and compare with 2f(1)=2. This fixed quadratic is a nonlinear counterexample, not distributed linear algebra or a reduction implementation.

A nonlinear map cannot freely cross a sumThis lab uses only y = ax². Playback traces the curve within the fixed integration interval from 0 to x; it does not estimate numerical error or change the chosen point. Current readings: y at chosen x: 0.608; Tangent slope · 2ax: 1.35; Signed area · ax³/3: 0.182. All parameters are adjustable with the labeled controls below.−2.4−1.201.22.4−9−4.504.59xy(x, ax²)
y = ax²TangentSigned integral
y at chosen x
0.608
Tangent slope · 2ax
1.35
Signed area · ax³/3
0.182
t = 0 s

This lab uses only y = ax². Playback traces the curve within the fixed integration interval from 0 to x; it does not estimate numerical error or change the chosen point. 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 forThe sum must be complete before an operation whose semantics depend on that complete value.

Check your understanding

Two row-parallel ranks produce Z0=−2 and Z1=3 for one output, with zero bias. What is ReLU of the intended complete output?

Try it yourself

Two ranks contribute [2,−1] and [3,4], with replicated bias [1,2]. Compute the correct output and the result if each partial receives the full bias before summation.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

First sum contributions, then compare one bias copy with two.

Compare with the solution

The complete product is [5,3], so the correct output is [6,5]. Adding bias to both partials produces [3,1]+[4,6]=[7,7], containing one extra bias [1,2]. This test needs nonzero bias to expose that placement error.

Take it with you

  • Input-feature shards contribute to the same output coordinates.
  • Reduce the complete sum before dependent nonlinear operations.
  • Replicated bias belongs once in the complete result under the stated convention.

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.