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

Removes separate VISSL caching and adds file_name to torch.hub.load_state_dict_from_url everywhere #179

Merged
merged 5 commits into from
Sep 11, 2024

Conversation

jonasd4
Copy link
Collaborator

@jonasd4 jonasd4 commented Sep 10, 2024

This PR fixes further issues with torch.hub.load_state_dict_from_url

  • In every call to that function, the filename attribute is now set to avoid any unwanted caching.
  • The additional caching of vissl models is now removed (previously the assumption was that torch.hub.load_state_dict_from_url does not perform any caching)
  • The issue also affected loading the barlowtwins and vicreg models as in their respective hubconf.py also does not set the filename attribute and the filename in the url was the same. (e.g. https://github.com/facebookresearch/barlowtwins/blob/main/hubconf.py). These models are now directly loaded from the respective url while providing the filename attribute in the load function.

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

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

Project coverage is 76.26%. Comparing base (200e047) to head (c087a2a).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
thingsvision/core/extraction/extractors.py 77.77% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
- Coverage   76.30%   76.26%   -0.04%     
==========================================
  Files          40       40              
  Lines        2055     2056       +1     
  Branches      262      263       +1     
==========================================
  Hits         1568     1568              
  Misses        402      402              
- Partials       85       86       +1     
Flag Coverage Δ
unittests 76.26% <77.77%> (-0.04%) ⬇️

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.

@LukasMut LukasMut added bug Something isn't working cleanup Deprecate or refactor code labels Sep 10, 2024
@LukasMut
Copy link
Collaborator

@jonasd4 Could you provide a meaningful description of the PR? It doesn't have to be long. Can be a one-liner.

Copy link
Collaborator

@lciernik lciernik left a comment

Choose a reason for hiding this comment

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

Docstring and filename extension clarification requested

@@ -350,15 +350,14 @@ def __init__(
device=device,
)

def _download_and_save_model(self, model_url: str,
output_model_filepath: str, unique_model_id: str):
def _load_vissl_state_dict(self, model_url: str, unique_model_filename: str):
"""
Downloads the model in vissl format, converts it to torchvision format and
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe adapt docstring and write that load_state_dict_from_url is using a cached version if available.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I adapted the docstring, please have a look if that's clear now!

@@ -394,25 +392,25 @@ def load_model_from_source(self) -> None:
Otherwise, loads it from the cache directory.
"""
if self.model_name in SSLExtractor.MODELS:

# unique model id name for all models
unique_model_filename = f'thingsvision_ssl_v0_{self.model_name}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

The unique_model_filename no longer has an extension because it is not set in _load_vissl_state_dict nor in load_state_dict_from_url. Is this the desired behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is better with an extension! Added it now.

Copy link
Collaborator

@LukasMut LukasMut left a comment

Choose a reason for hiding this comment

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

@jonasd4 LGTM but please add a short description before I approve.

@jonasd4
Copy link
Collaborator Author

jonasd4 commented Sep 11, 2024

@jonasd4 LGTM but please add a short description before I approve.

Added the description!

Copy link
Collaborator

@lciernik lciernik left a comment

Choose a reason for hiding this comment

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

LGTM

@LukasMut LukasMut added this pull request to the merge queue Sep 11, 2024
Merged via the queue into master with commit da9d717 Sep 11, 2024
4 of 5 checks passed
@LukasMut LukasMut deleted the fix/ssl-models-caching branch September 11, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cleanup Deprecate or refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants