Skip to content

Fix multitask_model.pt loading (ModuleNotFoundError on import)#98

Merged
RobbinBouwmeester merged 1 commit into4.0_MTfrom
fix/multitask-model-loading
Apr 24, 2026
Merged

Fix multitask_model.pt loading (ModuleNotFoundError on import)#98
RobbinBouwmeester merged 1 commit into4.0_MTfrom
fix/multitask-model-loading

Conversation

@RobbinBouwmeester
Copy link
Copy Markdown
Member

Problem

multitask_model.pt was serialised when MultitaskDeepLCModel and BatchedHeads lived in a top-level module called multitask_model. That module no longer exists in the package, so any call that loads the default model (including plain deeplc.predict(...)) raised:

ModuleNotFoundError: No module named 'multitask_model'

or, with a partial shim:

AttributeError: Can't get attribute 'BatchedHeads' on <module 'multitask_model'>

Fix

deeplc/_architecture.py — Add the two missing classes:

  • BatchedHeads: parallel output heads (batched linear projection + per-head dot product). Includes a proper __init__ so future checkpoints can be constructed from scratch.
  • MultitaskDeepLCModel: multi-task backbone (same 4 input branches as DeepLCModel, plus a shared trunk feeding into BatchedHeads). Checkpoint-load-only for now; forward is fully implemented.

deeplc/_model_ops.py — Add _patch_legacy_multitask_module(), called inside load_model() before torch.load when the argument is a file path. It registers a sys.modules shim that maps the old multitask_model.* import paths to the new classes in deeplc._architecture. The shim is a no-op if the key is already present.

tests/test_model_ops.py — Add test_load_multitask_model_without_prior_shim to catch regressions: it explicitly removes any pre-existing shim, loads the bundled checkpoint, and asserts the output has the expected multi-head shape.

Verification

All 45 tests pass. End-to-end deeplc.predict(peptides, model=MODEL_MULTITASK) works without any user-side workaround, returning shape (n_peptides, 1020).

Performance on PXD002549 (real LC-MS/MS data, 500-peptide held-out set):

Setup Pearson r MAE
predict multitask (best head) 0.994
predict_and_calibrate multitask 0.994 0.89 min
finetune_and_predict multitask 0.994 0.98 min

🤖 Generated with Claude Code

… to _architecture and register legacy module shim

The bundled multitask_model.pt was serialised when MultitaskDeepLCModel and
BatchedHeads lived in a top-level module called `multitask_model`.  That
module no longer exists, so torch.load raised ModuleNotFoundError for any
user who tried to load the default model.

Fix:
- Add BatchedHeads and MultitaskDeepLCModel to deeplc/_architecture.py,
  where the rest of the model architecture already lives.
- Add _patch_legacy_multitask_module() to deeplc/_model_ops.py, which
  registers a sys.modules shim mapping the old import path to the new
  classes before torch.load is called.  The shim is a no-op if the
  module is already registered.
- Add test_load_multitask_model_without_prior_shim to tests/test_model_ops.py
  to prevent regression.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@RobbinBouwmeester RobbinBouwmeester merged commit 6a58ad2 into 4.0_MT Apr 24, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant