Skip to content

fix(models): make encode() deterministic and repair the LSS override - #458

Open
ChrisW09 wants to merge 2 commits into
mainfrom
fix/encode-eval-mode
Open

fix(models): make encode() deterministic and repair the LSS override#458
ChrisW09 wants to merge 2 commits into
mainfrom
fix/encode-eval-mode

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #451

Problems

  1. encode() never leaves training mode. After fit() the model is still in train mode, so dropout stays active and embeddings are corrupted and non-reproducible. Verified with attn_dropout=0.5: two encode(X) calls on the same rows differed by up to 4.45, with estimator.training == True. It also ran with autograd enabled, needlessly building a graph.
  2. SklearnBaseLSS.encode() always raises. It unpacks two values from the three-element (num_features, cat_features, embeddings) batches that preprocess_new_data yields: ValueError: too many values to unpack (expected 2) for every LSS model, on every architecture.

Fix

Put the task model in eval() under torch.no_grad() for the duration of the encode, restoring the previous mode afterwards; and have the LSS override pass the whole batch to estimator.encode(), matching the base _PredictMixin implementation.

Tests

New tests/test_encode.py: two encode() calls agree, the prior training mode is restored, and LSS encode() returns embeddings. Verified 2 of the 3 fail on main. tests/test_base_mixins.py, test_inspection.py and test_lss_base.py pass unchanged.

Note: the stray self.encoder(x) line in BaseModel.encode() (which makes encode() raise on Mamba backbones) is a separate defect, already filed as #426 item 1 and fixed in #439.

🤖 Generated with Claude Code

ChrisW09 and others added 2 commits July 27, 2026 22:34
encode() never switched the model out of training mode, so embeddings
taken after fit() ran with dropout active: two calls on the same rows
differed by up to 4.45 and no result was reproducible. It also ran with
autograd enabled. The model is now put in eval() under torch.no_grad()
and its previous mode restored afterwards.

SklearnBaseLSS.encode() additionally unpacked two values from the
three-element (num_features, cat_features, embeddings) batches that
preprocess_new_data yields, so it raised
'ValueError: too many values to unpack (expected 2)' for every LSS model.
It now passes the whole batch to estimator.encode(), matching the base
_PredictMixin implementation.

Fixes #451

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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] encode() returns dropout-corrupted embeddings and is completely broken for LSS models

1 participant