Skip to content

Conversation

@florian-huber
Copy link
Member

@florian-huber florian-huber commented Nov 7, 2025

  • now allows torch>=2.4 (was <=2.6 before) --> closes Different way of saving models #236
  • added new way of saving models
  • new method of loading models (older models can be loaded with potentially unsave allow_legacy=True)
  • Saved models will now also contain a version string besides the ms2deepscore version to keep track of our "model version" which (hopefully) will change much less frequently than the release version --> now in models/__model_format__.py. The first setting here is ms2deepscore.safe.v1 (but any string can in the future be used).
  • there is a convert_legacy_checkpoint() function that allows converting "old" MS2DeepScore 2.0 models to the new style.

@matchms matchms deleted a comment from sonarqubecloud bot Nov 7, 2025
Copy link
Collaborator

@niekdejonge niekdejonge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florian-huber Thanks a lot! That seems like quite some work to get saving to work as well. I assume we will have to upload new MS2DeepScore models, of the new version right? I can do that now.

One question, will the old loading function be able to handle the new model format? If not, I will make a new zenodo link, so people using older versions don't automatically download the new versions.


if settings:
# coerce a copy against current defaults
settings = _coerce_settings_dict(settings, self)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition, to automatically convert incorrect types.


def save(self, filepath):

def save(self, filepath: Union[str, Path]) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice that you fixed this @florian-huber Thanks!

except Exception as safe_err:
if not allow_legacy:
raise RuntimeError(
"Failed to load safely. If this is a trusted legacy file, call with allow_legacy=True."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution!


# ---------- public API ----------

def load_model(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is now like this:
The load by default works for the new way of saving, but if allow_legacy=True it will still be able to load the old versions. If this is correct, that is great!

assert settings_false.use_fixed_set is False


#def test_coerce_invalid_string_to_bool():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these tests be there?

@niekdejonge niekdejonge merged commit 63e9fd8 into main Dec 5, 2025
11 checks passed
@niekdejonge niekdejonge deleted the pytorch_update branch December 5, 2025 09:46
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.

Different way of saving models

3 participants