Parallel layers: does feed-forward have to wait?
Attention runs, then feed-forward runs. Could we let them start together?
One branch has to wait
Our rabbit token reaches another layer. Attention reads its representation, gathers information from other tokens, and adds an update to the residual stream.
Only then does feed-forward read the result and calculate its own update.
That order gives feed-forward something useful: the information attention has just brought back. But it also means waiting. We cannot start that calculation until attention finishes.
Could both branches start with the representation we already have?
Let both branches read the same input
Switch to Parallel. Feed-forward now takes its input from the same point as attention.
Each branch normalises what it reads and calculates an update. We add both updates to the original representation.
This is a parallel layer. Attention still shares information between tokens. Feed-forward still applies its learned transformations. We have changed when they can begin.
The work is still there
We still run attention and feed-forward. But neither branch needs the other’s result, so the hardware can overlap their work.
Their input projections can also be combined into one larger matrix multiplication. That can make better use of the hardware than launching the two separately.
What did we give up?
Switch back to Sequential and follow the feed-forward input. It comes after attention’s addition.
In Parallel, feed-forward cannot use the information attention gathers in this layer. Both updates only meet at the end. The next layer can read their combined result.
So this is a different way to build and train the layer, rather than a shortcut that preserves exactly the same calculation.
We started by moving a norm along the path. Now we have moved an entire branch. The residual stream lets us keep the incoming representation while changing how the layer builds its updates.
Sources
- PaLM, Section 2 describes sequential and parallel residual blocks and fusing their input projections. Its parallel branches read the same normalised input; implementations may share that normalisation. The diagram shows the normalisation on each branch to make the input paths visible.
- GPT-J implementation provides an earlier parallel attention/feed-forward implementation.
The coloured input represents a token vector. The dimension label follows the selected size example. Branch boxes show data dependencies; their drawn lengths do not represent execution times.