Skip to content

fix(core): apply rnn and conv pooling in pool_sequence - #482

Open
ChrisW09 wants to merge 3 commits into
mainfrom
fix/rnn-conv-pooling
Open

ChrisW09 wants to merge 3 commits into
mainfrom
fix/rnn-conv-pooling

Conversation

@ChrisW09

@ChrisW09 ChrisW09 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #481

Problem

pooling_method="rnn" and pooling_method="conv" were accepted by every pooling architecture (FTTransformer, TabTransformer, SAINT, Mambular, MambAttention, TabulaRNN). Each one then crashed on its first forward pass with ValueError: Invalid pooling method.

Root cause

BaseModel.initialize_pooling_layers builds pooling_rnn (an nn.LSTM) and conv1d_pooling (an nn.Conv1d) for these two methods. BaseModel.pool_sequence never used them and fell through to its else: raise ValueError(...).

Fix

pool_sequence now applies the layers that are already built:

  • "rnn" returns the LSTM output at the last sequence step, i.e. (batch, seq, hidden) → (batch, hidden).
  • "conv" applies the 1-D convolution over the sequence, then global max pooling. This matches the existing comment on conv1d_pooling.

No other pooling method changes. Model construction and parameter counts stay the same, because the layers were already being created.

Tests

New TestRecurrentAndConvolutionalPooling in tests/core/test_base_model.py:

  • Unit checks that "rnn" returns the last LSTM step and "conv" returns the global max of the convolution.
  • A forward/backward check for all six affected architectures (FTTransformer, MambAttention, Mambular, SAINT, TabTransformer and TabulaRNN) with both methods. It asserts the output shape and that every parameter of the pooling layer receives a gradient, so neither layer is dead.

All 14 new cases fail on main and pass with this change.

Docs

  • pool_sequence now has a NumPy-style docstring that lists every supported method.
  • The pooling_method docstrings of the six affected model configs list the valid values instead of ('cls', 'avg', etc.).

Checks

  • just test: 3250 passed, 46 skipped, 28 xfailed; coverage 91.32%
  • just docs: build succeeded (warnings treated as errors)
  • just check: all hooks passed (ruff, prettier, pyright)

ChrisW09 and others added 3 commits October 21, 2026 14:56
initialize_pooling_layers builds an LSTM for pooling_method="rnn" and a
Conv1d for pooling_method="conv", but pool_sequence had no branch for
either value and raised "Invalid pooling method" on the first forward
pass of every pooling architecture. Use the LSTM output at the last
step for "rnn" and the convolution followed by global max pooling for
"conv", and list the supported values in the model config docstrings.

Fixes #481

@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.

@ChrisW09, thank you for your contribution.

  • Both pooling options now work
  • PR can be merged once CI is passed.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
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] pooling_method="rnn" and "conv" crash at the first forward pass on every pooling architecture

3 participants