Skip to content

Fix MoleRec fallback predictor never training - #1214

Open
fbonc wants to merge 1 commit into
sunlabuiuc:masterfrom
fbonc:fix-molerec-lazy-predictor
Open

Fix MoleRec fallback predictor never training#1214
fbonc wants to merge 1 commit into
sunlabuiuc:masterfrom
fbonc:fix-molerec-lazy-predictor

Conversation

@fbonc

@fbonc fbonc commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Issue

On MoleRec's fallback path (no valid SMILES data), the linear fallback predictor simple_predictor was created lazily inside forward() (molerec.py:814-819). The standard PyHealth training pattern builds the optimizer from model.parameters() before the first forward pass, so the predictor's parameters were never registered with the optimizer and never trained.

Fix

Create simple_predictor in init when has_valid_smiles is False, sized nn.Linear(hidden_dim * 2, label_size) to match the concatenated condition/procedure patient embedding. Removed the lazy creation (and its now-unnecessary .to(self.device)) from forward. Parameters are now registered before the optimizer is built.

Notes

Added regression test test_fallback_predictor_registered_and_trains in tests/core/test_molerec.py: it asserts simple_predictor is in named_parameters before any forward and that an optimizer step actually updates its weights.

simple_predictor was created lazily inside forward(), so an optimizer
built from model.parameters() beforehand (the standard pattern) never
saw its parameters. Create it in __init__ on the no-SMILES fallback path.
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.

1 participant