Skip to content

Store the version inside checkpoints and add tools to upgrade checkpoints - #580

Merged
Luthaf merged 1 commit into
mainfrom
versioning
Jul 11, 2025
Merged

Store the version inside checkpoints and add tools to upgrade checkpoints#580
Luthaf merged 1 commit into
mainfrom
versioning

Conversation

@DavideTisi

@DavideTisi DavideTisi commented May 7, 2025

Copy link
Copy Markdown
Contributor

add checkpoint versioning. Default is 1. each arch have to implement a transfer function to a version to the other, now it just throw an error

Contributor (creator of pull-request) checklist

  • Tests updated (for new features and bugfixes)?
  • Documentation updated (for new features)?
  • Issue referenced (for PRs that solve an issue)?

Reviewer checklist

  • CHANGELOG updated with public API or any other important changes?

📚 Documentation preview 📚: https://metatrain--580.org.readthedocs.build/en/580/

Copilot AI review requested due to automatic review settings May 7, 2025 13:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces checkpoint versioning by adding a version key to default hyperparameters and updating the model loading logic to handle version mismatches.

  • Added tests to verify that loading a checkpoint with a mismatched version raises a NotImplementedError.
  • Updated the model_from_checkpoint logic to convert version 0 to version 1 and to trigger checkpoint upgrade via the model’s upgrade_checkpoint method.
  • Added a new find_architectures_version utility function and updated various model and default-hypers.yaml files to include a default version number.

Reviewed Changes

Copilot reviewed 11 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/utils/test_io.py Added test case verifying error for wrong version checkpoint.
src/metatrain/utils/io.py Updated model loading logic to handle version checking and upgrades.
src/metatrain/utils/architectures.py Introduced find_architectures_version to retrieve current version value.
src/metatrain/soap_bpnn/model.py & default-hypers.yaml Added upgrade_checkpoint stub and version config for SOAP-BPNN model.
src/metatrain/pet/model.py & default-hypers.yaml Added upgrade_checkpoint stub and version config for PET model.
src/metatrain/gap/model.py & default-hypers.yaml Added upgrade_checkpoint stub and version config for GAP model.
src/metatrain/deprecated/pet/model.py & default-hypers.yaml Added upgrade_checkpoint stub and version config for deprecated PET.
Files not reviewed (4)
  • src/metatrain/deprecated/pet/schema-hypers.json: Language not supported
  • src/metatrain/gap/schema-hypers.json: Language not supported
  • src/metatrain/pet/schema-hypers.json: Language not supported
  • src/metatrain/soap_bpnn/schema-hypers.json: Language not supported

Comment thread src/metatrain/utils/io.py Outdated
Comment thread src/metatrain/soap_bpnn/model.py
@DavideTisi
DavideTisi force-pushed the versioning branch 2 times, most recently from 500c12b to 7d41219 Compare May 7, 2025 14:28
@DavideTisi
DavideTisi requested review from Luthaf and PicoCentauri May 7, 2025 15:00
Luthaf
Luthaf previously requested changes May 7, 2025
Comment thread src/metatrain/deprecated/pet/model.py
Comment thread src/metatrain/deprecated/pet/default-hypers.yaml Outdated
Comment thread tests/utils/test_io.py Outdated
Comment thread tests/utils/test_io.py Outdated
@DavideTisi
DavideTisi force-pushed the versioning branch 2 times, most recently from 040cc3c to 56c94f3 Compare May 9, 2025 07:45
@Luthaf
Luthaf force-pushed the versioning branch 5 times, most recently from 77b628e to 2d5f466 Compare June 24, 2025 15:04
@Luthaf Luthaf changed the title Versioning Store the version inside checkpoints and add tools to upgrade checkpoints Jun 24, 2025

@PicoCentauri PicoCentauri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks very good. I have some minor things that we might do. We could also consider putting the Python code for the Model and the trainer from the new-architecture.rst in a Python file and run it in the test suite. Linking these files in the docs should be easy and should also look good.

Comment thread docs/src/dev-docs/new-architecture.rst Outdated
Comment thread src/metatrain/utils/abc.py
Comment thread src/metatrain/utils/abc.py Outdated
@@ -158,19 +189,26 @@ def save_checkpoint(self, model, path: Union[str, Path]):
Save a checkoint of both the ``model`` and trainer state to the given ``path``

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we do some checks that the version is actually injected or do we not care?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will be a follow-up PR!

Comment thread src/metatrain/utils/abc.py
Comment thread docs/src/dev-docs/new-architecture.rst
Comment thread docs/src/dev-docs/new-architecture.rst
@Luthaf
Luthaf force-pushed the versioning branch 3 times, most recently from 3a139d4 to d04e442 Compare July 7, 2025 15:08
@Luthaf

This comment was marked as outdated.

@Luthaf
Luthaf force-pushed the versioning branch 2 times, most recently from 24b0280 to ded41ea Compare July 8, 2025 09:04
@Luthaf
Luthaf requested a review from PicoCentauri July 8, 2025 09:05
@Luthaf
Luthaf dismissed their stale review July 8, 2025 09:05

outdated

@PicoCentauri PicoCentauri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this important work @DavideTisi and @Luthaf!

Comment thread src/metatrain/utils/io.py
Comment on lines +204 to +208
f"Unable to load the model checkpoint from '{path}' for "
f"the '{architecture_name}' architecture: the checkpoint is using "
f"version {model_ckpt_version}, while the current version is "
f"{architecture.__model__.__checkpoint_version__}; and trying to "
"upgrade the checkpoint failed."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a very motivating error message. TLDR: Please go home, I tried everything I can xD

Co-Authored-By: Davide Tisi <davide.tisi93@gmail.com>
@Luthaf
Luthaf added this pull request to the merge queue Jul 11, 2025
@Luthaf
Luthaf removed this pull request from the merge queue due to a manual request Jul 11, 2025
@Luthaf
Luthaf merged commit 8e854e7 into main Jul 11, 2025
13 checks passed
@Luthaf
Luthaf deleted the versioning branch July 11, 2025 14:38
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.

4 participants