📘
Complete Mixer Block with Residuals
A complete MLP-Mixer block combines token mixing and channel mixing with residual connections:
X1=X+TokenMix(X) X2=X1+ChannelMix(X1)
Where:
- TokenMix: Wtoken⋅X (mix across N tokens)
- ChannelMix: MLP with GELU applied per-token
The residual connections ensure stable training and allow the network to learn identity mappings when beneficial.
Task: Implement a complete Mixer block with both mixing stages and residual connections.
Example:
Input:
X (2×2), W_token=zeros, W1=I, W2=I
Output:
X + 0 + GELU(X) = X + GELU(X)
Reasoning:
Zero token weights mean no token mixing. Identity channel weights apply GELU directly. Final output includes both residuals.
Constraints:
- Input X: Shape (N,D)
- Wtoken: Shape (N,N)
- W1: Shape (D,H) for channel MLP
- W2: Shape (H,D) for channel MLP
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.