Skip to content

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

Merged
mkumar73 merged 2 commits into
mainfrom
fix/saint-attention-norms
Sep 19, 2026
Merged

mkumar73 merged 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>
@mkumar73

Copy link
Copy Markdown
Collaborator
  • Changes looks good.
  • PR will be merged to main, and changes will be shipped with v2.1.0

@mkumar73 mkumar73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@mkumar73
mkumar73 merged commit 1fcdce9 into main Sep 19, 2026
18 checks passed
@mkumar73
mkumar73 deleted the fix/saint-attention-norms branch October 10, 2026 05:06
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

2 participants