Skip to content

fix(nn): apply pre-norm and dropout around RowColTransformer attention - #436

Open
ChrisW09 wants to merge 2 commits into
mainfrom
fix/saint-attention-norms
Open

fix(nn): apply pre-norm and dropout around RowColTransformer attention#436
ChrisW09 wants to merge 2 commits into
mainfrom
fix/saint-attention-norms

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #416

Problem

RowColTransformer (the backbone SAINT uses) builds each attention slot as nn.Sequential(LayerNorm, MultiheadAttention, Dropout), but forward calls only the attention module:

x = attn1[1](x, x, x)[0] + x   # skips attn1[0] (LayerNorm) and attn1[2] (Dropout)
...
x = attn2[1](x, x, x)[0] + x

SAINT therefore trains with no normalization before either attention block and no attention-path dropout, diverging from the published architecture and risking instability. Verified: the LayerNorm weights inside those Sequentials have grad is None after a backward pass — they are dead parameters carried in the optimizer.

Fix

Apply the full pre-norm → attention → dropout → residual chain for both the column-wise and row-wise attention.

Tests

New tests/test_saint_attention.py fits a SAINTRegressor, runs one manual forward/backward, and asserts the attention LayerNorm parameters receive gradients. tests/test_nn_blocks.py passes unchanged.

🤖 Generated with Claude Code

ChrisW09 and others added 2 commits July 27, 2026 21:30
The attention slots are nn.Sequential(LayerNorm, MultiheadAttention,
Dropout), but forward indexed only attn[1], skipping the pre-norm at
index 0 and the dropout at index 2. SAINT therefore trained with no
normalization before either the column-wise or row-wise attention and no
attention-path dropout, and the LayerNorm parameters received no
gradients at all.

Fixes #416

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
model._task_model and model._data_module are Optional-typed internals.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SAINT's RowColTransformer skips its LayerNorms and dropouts

1 participant