Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

457 geovex model saving loading #460

Merged
merged 17 commits into from
Aug 26, 2024

Conversation

sabman
Copy link
Contributor

@sabman sabman commented Aug 21, 2024

work for #457

This PR adds:

GeoVexEmbedder:
  save
  cls.load

It also adds a test to save and load GeoVexEmbedder. We have been running it via: but hopefully CI runs the full suite.

PYTHONPATH=. pytest tests/embedders/geovex/test_embedder.py::test_embedder_save_load

Our first PR to this awesome project, apologies in advance for any oversights but happy to learn best practices from feedback and contribute more.

Co-authored with @mhassanch

sabman and others added 12 commits August 17, 2024 20:03
Co-Authored-By: Muhammad Hassan <[email protected]>
Co-Authored-By: Muhammad Hassan <[email protected]>
…d loading of model

clean up embedder load/save
clean up tests

Co-Authored-By: Muhammad Hassan <[email protected]>
…ving-loading' into 457-geovex-model-saving-loading
Co-Authored-By: Muhammad Hassan <[email protected]>
Co-Authored-By: Muhammad Hassan <[email protected]>
Co-Authored-By: Muhammad Hassan <[email protected]>
@piotrgramacki
Copy link
Collaborator

Hi @sabman,

Thank you for this contribution. This feature is vital for us, so having this PR to work with is excellent! We'll review it and lat you know if anything needs to be added before merging it into srai.

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.21%. Comparing base (23ee20e) to head (af3b541).
Report is 1 commits behind head on main.

Files Patch % Lines
srai/embedders/geovex/embedder.py 93.75% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #460      +/-   ##
==========================================
+ Coverage   89.74%   90.21%   +0.46%     
==========================================
  Files          62       62              
  Lines        2439     2474      +35     
==========================================
+ Hits         2189     2232      +43     
+ Misses        250      242       -8     
Flag Coverage Δ
macos-13-python3.12 90.21% <94.59%> (+0.55%) ⬆️
ubuntu-latest-python3.10 90.09% <94.59%> (+0.42%) ⬆️
ubuntu-latest-python3.11 90.01% <94.59%> (+0.34%) ⬆️
ubuntu-latest-python3.12 90.09% <94.59%> (+0.42%) ⬆️
ubuntu-latest-python3.9 90.20% <94.59%> (+0.46%) ⬆️
windows-latest-python3.12 90.21% <94.59%> (+0.55%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@RaczeQ RaczeQ left a comment

Choose a reason for hiding this comment

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

Thank you @sabman for this contribution! I have left one change request and asked one question. Other than that it looks great.

We will also need to fill the CHANGELOG.md file, can I fill it for you, or do you want to do it yourself?

Comment on lines 297 to 301
# save model and config
self._model.save(path / "model.pt") # type: ignore
# combine model config and embedder config
if self._model is not None:
model_config = self._model.get_config()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is there a check for a model not being None? If self._model was None, the save function would throw an exception.

Should this be a check for a model config, or should the save function be moved inside this if statement?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see in the Hex2Vec implementation that there is no such check with if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RaczeQ thanks for the feedback. The type linter was complaining about _model being None so we put in a check. But let us remove it and push again.

Comment on lines 580 to 586
def get_config(self) -> dict[str, int | float]:
"""
Get the model configuration.

Returns:
Dict[str, int | float]: The model configuration.
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are still supporting the Python 3.9 version, so it doesn't accept the pipe syntax yet and tests on this Python version failed. Please change to the Union version. It will also require additional import at the top from typing.

Suggested change
def get_config(self) -> dict[str, int | float]:
"""
Get the model configuration.
Returns:
Dict[str, int | float]: The model configuration.
"""
def get_config(self) -> dict[str, Union[int, float]]:
"""
Get the model configuration.
Returns:
Dict[str, Union[int, float]]: The model configuration.
"""

Co-Authored-By: Muhammad Hassan <[email protected]>
Copy link
Collaborator

@RaczeQ RaczeQ left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for this contribution 🙂

@RaczeQ RaczeQ merged commit 288509b into kraina-ai:main Aug 26, 2024
11 of 12 checks passed
@RaczeQ RaczeQ linked an issue Aug 26, 2024 that may be closed by this pull request
@sabman sabman deleted the 457-geovex-model-saving-loading branch August 27, 2024 19:30
@RaczeQ
Copy link
Collaborator

RaczeQ commented Aug 30, 2024

FYI @sabman @mhassanch changes have been released with version 0.7.6

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.

Add model saving to GeoVeX
3 participants