-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add explicit parameters for torch.load #6751
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
69b4560
Add weights_only=True to all tests
loadams 8485b9c
Formatting
loadams 4193165
Replace all DeepSpeed calls in deepspeed/ with weights_only=False
loadams 2a4dced
Formatting
loadams 0b1df75
Update tests that fail on HPU
loadams af14023
Pre-commit formatting
loadams a34652e
Merge branch 'master' into loadams/weights-only-true
loadams 703e38f
Update to all weights only False
loadams a5f29d7
Merge branch 'master' into loadams/weights-only-true
loadams 2fd5a2d
Merge branch 'master' into loadams/weights-only-true
loadams efc017d
Merge branch 'master' into loadams/weights-only-true
loadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,7 +264,7 @@ def test_elastic_checkpoint_fixed_dp(self, tmpdir, elastic_save, elastic_load, l | |
model.load_checkpoint(tmpdir, load_optimizer_states=load_optim) | ||
|
||
if load_optim: | ||
saved_sd = torch.load(os.path.join(tmpdir, opt_state_dict_file)) | ||
saved_sd = torch.load(os.path.join(tmpdir, opt_state_dict_file), weights_only=False) | ||
curr_sd = model.optimizer.optimizer.state_dict() | ||
compare_opt_state_dicts(curr_sd, saved_sd, expected_mismatch_keys) | ||
|
||
|
@@ -523,7 +523,7 @@ def test_save_exclude_frozen_weights(self, tmpdir, zero_stage): | |
all_ckpt_folder = os.path.join(tmpdir, 'all_params') | ||
ds_engine.save_checkpoint(all_ckpt_folder) | ||
all_params_ckpt_file = get_model_ckpt_name_for_rank(os.path.join(all_ckpt_folder, 'global_step0'), '00') | ||
loaded_all_param_model = torch.load(all_params_ckpt_file)['module'] | ||
loaded_all_param_model = torch.load(all_params_ckpt_file, weights_only=True)['module'] | ||
all_param_names = set([n for n, p in model.named_parameters()]) | ||
assert set(loaded_all_param_model.keys()) == all_param_names | ||
|
||
|
@@ -536,7 +536,7 @@ def test_save_exclude_frozen_weights(self, tmpdir, zero_stage): | |
# Excluding frozen parameters should reduce checkpoint size | ||
assert os.path.getsize(all_params_ckpt_file) > os.path.getsize(trainable_ckpt_file) | ||
|
||
loaded_trainable_param_model = torch.load(trainable_ckpt_file)['module'] | ||
loaded_trainable_param_model = torch.load(trainable_ckpt_file, weights_only=True)['module'] | ||
frozen_param_names = set([n for n, p in model.named_parameters() if not p.requires_grad]) | ||
loaded_trainable_param_names = set(loaded_trainable_param_model.keys()) | ||
overlap_names = set.intersection(loaded_trainable_param_names, frozen_param_names) | ||
|
@@ -575,7 +575,7 @@ def test_save_exclude_custom_frozen_weights(self, tmpdir, zero_stage): | |
|
||
custom_state_dict_ckpt_file = get_model_ckpt_name_for_rank( | ||
os.path.join(custom_state_dict_ckpt_folder, 'global_step0'), '00') | ||
loaded_custom_state_dict_param_model = torch.load(custom_state_dict_ckpt_file)['module'] | ||
loaded_custom_state_dict_param_model = torch.load(custom_state_dict_ckpt_file, weights_only=True)['module'] | ||
loaded_custom_state_dict_param_names = set(loaded_custom_state_dict_param_model.keys()) | ||
|
||
custom_state_dict_param_names = set([k for k, v in model.state_dict().items()]) | ||
|
@@ -618,7 +618,8 @@ def test_save_tensor_clone(self, tmpdir, zero_stage, use_cpu_device): | |
clone_ckpt_file = os.path.join(tmpdir, 'clone_ckpt.pt') | ||
torch.save(clone_state_dict, clone_ckpt_file) | ||
|
||
compare_state_dicts(torch.load(ref_ckpt_file), torch.load(clone_ckpt_file)) | ||
compare_state_dicts(torch.load(ref_ckpt_file, weights_only=False), torch.load(clone_ckpt_file, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HPU tests failed when this was set to True:
|
||
weights_only=False)) | ||
|
||
|
||
class TestZeRONonDistributed(DistributedTest): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch this value to True for safety where needed.