Refactor serialization via Huggingface Hub #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
Description
This PR follows the discussion in #68 and makes DGMR compatible with recent updates in
huggingface_hub
.Specifically, it removes the explicit
config
argument from constructors. This simplifies the constructors, but may cause some backwards compatibility problems if people rely on passing this parameter. However, it should be easy to fix this by replacingDGMR(config=myconfig)
withDGMR(**myconfig)
.Secondly, this PR also contains a separate commit that replaces the custom
NowcastingModelHubMixin
withhuggingface_hub.PyTorchModelHubMixin
. This does not have any real advantages, aside from trimming redundant code. It should be noted that altoughPyTorchModelHubMixin
can read both the PyTorch's.bin
andsafetensors
formats, it can only write the latter. So any potential future updates to the model would migrate the format automatically tosafetensors
.How Has This Been Tested?
Tests have been added in
tests/test_model.py
that verify that models can be serialized and unserialized without any changes to the parameters or hyperparameters. These fixes passes all tests.Additionally, I have manually verified that predictions on random data are identical to those produced by the previous version.
Checklist:
(I've attempted to follow OCF's coding style, but running
black
causes many changes in existing code that is not touched by this PR)