Skip to content

Lazy load pretrained models#229

Merged
mschwoer merged 8 commits intodevelopmentfrom
lazy_load_pretrained_models
Mar 20, 2025
Merged

Lazy load pretrained models#229
mschwoer merged 8 commits intodevelopmentfrom
lazy_load_pretrained_models

Conversation

@mschwoer
Copy link
Copy Markdown
Contributor

@mschwoer mschwoer commented Feb 13, 2025

Avoid the toplevel code that downloaded the module already if just alphadia -v was done ..

Also, added a potentially reusable mechanism for deprecating module-level variables

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@mschwoer mschwoer requested review from GeorgWa and jalew188 February 13, 2025 13:42
@mschwoer mschwoer marked this pull request as ready for review February 13, 2025 13:43
Base automatically changed from adapt_to_latest_standards to development March 12, 2025 13:26
Copy link
Copy Markdown
Collaborator

@GeorgWa GeorgWa left a comment

Choose a reason for hiding this comment

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

Where is the code change where we actually stop downloading models at import time?
Shouldn't this be somewehere?


To deprecate a variable:
> import sys, ModuleWithDeprecations
> sys.modules[__name__].__class__ = ModuleWithDeprecations
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This example confuses me a lot.

Does it need to be sys or is this just and example?
What is modules[__name__]?
Can you provide a simpler example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

maybe this deprecation mechanism is also too much?

sys.modules[__name__].__class__ = ModuleWithDeprecations

LOCAL_MODAL_ZIP_NAME = global_settings["local_model_zip_name"]
MODEL_URL = global_settings["model_url"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this be an all caps constant if it's actually loaded from a config?
Why not using global_settings["model_url"] directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

well, it's a string and somehow constant (within the lifetime of a peptdeep instance) .. that's why I chose ALL_CAPS

Comment on lines -108 to -109
if not os.path.exists(model_zip):
download_models()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mschwoer mschwoer merged commit e717b71 into development Mar 20, 2025
2 checks passed
@mschwoer mschwoer deleted the lazy_load_pretrained_models branch March 20, 2025 15:00
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.

2 participants