Skip to content

Conversation

@wz337
Copy link
Contributor

@wz337 wz337 commented Jun 24, 2024

Fixes #129079

Currently, the tensor object is loading correctly in-place, but the non-tensor object such as learning rate is not load correctly after f518cf8, which is a regression introduced in 2.3.

This PR replaces tree_map_only and manual replacement of the state dict items with _tree_map_only and fixes the regression of non-tensor loading.

Test:

# test to make sure lr is loading correctly
python3 test/distributed/checkpoint/e2e/test_e2e_save_and_load.py -k test_init_state_dict
# test to make sure load on meta device model still works
python3 test/distributed/checkpoint/test_tp_checkpoint.py -k test_tp_checkpoint_load_on_meta_device

cc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu @fegin @XilunWu @wanchaol @fduwjj @tianyu-l @wconstab @yf225 @chauhang @d4l3k @LucasLLC @MeetVadakkanchery @mhorowitz

@pytorch-bot
Copy link

pytorch-bot bot commented Jun 24, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/129398

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 2 Unrelated Failures

As of commit b94592b with merge base 1c75ddf (image):

NEW FAILURE - The following job has failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added module: distributed_checkpoint oncall: distributed Add this issue/PR to distributed oncall triage queue labels Jun 24, 2024
@wz337 wz337 requested a review from fegin June 24, 2024 18:42
@wz337 wz337 marked this pull request as ready for review June 24, 2024 18:42
@wz337 wz337 force-pushed the fix_init_state_dict branch 2 times, most recently from 3062c45 to 88d600e Compare June 24, 2024 22:13
Copy link
Contributor

@fegin fegin left a comment

Choose a reason for hiding this comment

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

Nice, are we sure that the meta device still works?

@fegin fegin added ciflow/periodic Trigger jobs ran periodically on master (periodic.yml) on the PR ciflow/trunk Trigger trunk jobs on your pull request labels Jun 25, 2024
@wz337 wz337 force-pushed the fix_init_state_dict branch from 88d600e to 259d7a3 Compare June 25, 2024 20:52
# So we need to temporariy update the each element in the state dict with meta tensor.
for k in state_dict.keys():
state_dict[k] = state_dict_assigned_storage[k]
tree_map_only_(torch.Tensor, lambda v: _init_meta_tensor(v), state_dict)

Choose a reason for hiding this comment

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

Is there a reason a lambda function is used here? Would tree_map_only_(torch.Tensor, _init_meta_tensor, state_dict) not have worked?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. Thanks! Good catch. I modified it to remove the lambda.

@wz337 wz337 force-pushed the fix_init_state_dict branch from 259d7a3 to b94592b Compare June 25, 2024 23:01
@wz337
Copy link
Contributor Author

wz337 commented Jun 26, 2024

@pytorchmergebot merge -i

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@wz337
Copy link
Contributor Author

wz337 commented Jun 26, 2024

@pytorchmergebot merge -i

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: pull / linux-focal-py3.8-clang10 / test (dynamo, 3, 3, linux.2xlarge), periodic / win-vs2019-cuda11.8-py3 / test (default, 1, 4, windows.g5.4xlarge.nvidia.gpu), periodic / win-vs2019-cuda11.8-py3 / test (default, 2, 4, windows.g5.4xlarge.nvidia.gpu)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@wz337
Copy link
Contributor Author

wz337 commented Jun 26, 2024

@pytorchmergebot merge -i

@pytorchmergebot
Copy link
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: pull / linux-focal-py3.8-clang10 / test (dynamo, 3, 3, linux.2xlarge), periodic / win-vs2019-cuda11.8-py3 / test (default, 1, 4, windows.g5.4xlarge.nvidia.gpu), periodic / win-vs2019-cuda11.8-py3 / test (default, 2, 4, windows.g5.4xlarge.nvidia.gpu)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

wz337 added a commit to wz337/pytorch that referenced this pull request Jun 28, 2024
…#129398)

Fixes pytorch#129079

Currently, the tensor object is loading correctly in-place, but the non-tensor object such as learning rate is not load correctly after pytorch@f518cf8, which is a regression introduced in 2.3.

This PR replaces tree_map_only and manual replacement of the state dict items with _tree_map_only and fixes the regression of non-tensor loading.

Test:
```
python3 test/distributed/checkpoint/e2e/test_e2e_save_and_load.py -k test_init_state_dict
python3 test/distributed/checkpoint/test_tp_checkpoint.py -k test_tp_checkpoint_load_on_meta_device
```

Pull Request resolved: pytorch#129398
Approved by: https://github.com/fegin

(cherry picked from commit 8b8e2fc)
atalman pushed a commit that referenced this pull request Jul 2, 2024
…tly (#129398) (#129683)

[DCP] Fix Optimizer Learning Rate not being loaded correctly (#129398)

Fixes #129079

Currently, the tensor object is loading correctly in-place, but the non-tensor object such as learning rate is not load correctly after f518cf8, which is a regression introduced in 2.3.

This PR replaces tree_map_only and manual replacement of the state dict items with _tree_map_only and fixes the regression of non-tensor loading.

Test:
```
python3 test/distributed/checkpoint/e2e/test_e2e_save_and_load.py -k test_init_state_dict
python3 test/distributed/checkpoint/test_tp_checkpoint.py -k test_tp_checkpoint_load_on_meta_device
```

Pull Request resolved: #129398
Approved by: https://github.com/fegin

(cherry picked from commit 8b8e2fc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/periodic Trigger jobs ran periodically on master (periodic.yml) on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (checkpoint) topic: bug fixes topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in loading optimizer learning rate

4 participants