fix(nn): apply pre-norm and dropout around RowColTransformer attention - #436
Open
ChrisW09 wants to merge 2 commits into
Open
fix(nn): apply pre-norm and dropout around RowColTransformer attention#436ChrisW09 wants to merge 2 commits into
ChrisW09 wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #416
Problem
RowColTransformer(the backbone SAINT uses) builds each attention slot asnn.Sequential(LayerNorm, MultiheadAttention, Dropout), butforwardcalls only the attention module: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 Noneafter 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.pyfits aSAINTRegressor, runs one manual forward/backward, and asserts the attention LayerNorm parameters receive gradients.tests/test_nn_blocks.pypasses unchanged.🤖 Generated with Claude Code