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

[Feature] Load partially instantiated state-dict #103

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

vmoens
Copy link

@vmoens vmoens commented Oct 17, 2022

Summary:

Allows to load state_dicts from disk when the saved copy contains more elements that the pre-populated copy.

Test plan:
TODO

Fixes #{issue number}
Closes #101

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 17, 2022
@codecov
Copy link

codecov bot commented Oct 17, 2022

Codecov Report

Merging #103 (5501d83) into main (a11364c) will decrease coverage by 6.18%.
The diff coverage is 80.85%.

@@            Coverage Diff             @@
##             main     #103      +/-   ##
==========================================
- Coverage   90.40%   84.22%   -6.19%     
==========================================
  Files          25       25              
  Lines        2346     2384      +38     
==========================================
- Hits         2121     2008     -113     
- Misses        225      376     +151     
Impacted Files Coverage Δ
torchsnapshot/flatten.py 86.73% <66.66%> (-3.63%) ⬇️
torchsnapshot/io_preparer.py 92.55% <72.72%> (-1.07%) ⬇️
torchsnapshot/snapshot.py 92.75% <95.23%> (-3.03%) ⬇️
torchsnapshot/storage_plugins/gcs.py 0.00% <0.00%> (-78.90%) ⬇️
torchsnapshot/storage_plugins/s3.py 25.00% <0.00%> (-65.00%) ⬇️
torchsnapshot/storage_plugin.py 43.75% <0.00%> (-21.88%) ⬇️
torchsnapshot/memoryview_stream.py 63.33% <0.00%> (-6.67%) ⬇️
torchsnapshot/io_types.py 79.68% <0.00%> (-3.13%) ⬇️
torchsnapshot/scheduler.py 91.11% <0.00%> (-2.23%) ⬇️
... and 2 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@yifuwang
Copy link
Contributor

Hi @vmoens, thank you so much for raising the issue and drafting a proposal!

Previously, in order to reduce the memory footprint on load, we would find the tensors in the target module's state dict, in-place restore them, and use them to build a state dict for .load_state_dict().

Your proposal made us realize that this is not the right approach. Instead, we should always rebuild the original state dict and reuse the tensor in the target's module's state dict in addition. This way we can achieve the same memory saving while making the behavior much more general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loading tensors in lists/dict that have not yet been instantiated
3 participants