-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[TPU] Call torch._sync(param) during weight loading #9437
Conversation
👋 Hi! Thank you for contributing to the vLLM project. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can do one of these:
🚀 |
Thanks @JackCaoG for finding out the bug and providing the solution. |
vllm/model_executor/utils.py
Outdated
@@ -28,4 +29,22 @@ def set_weight_attrs( | |||
for key, value in weight_attrs.items(): | |||
assert not hasattr( | |||
weight, key), (f"Overwriting existing tensor attribute: {key}") | |||
|
|||
# NOTE(woosuk): For TPU, param.data.copy_(weight) happens lazily, |
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.
to be more accurate this is because in VLLM we do
narrowed_tensor = param.data.narrow(0, offset, len)
narrowed_tensor.copy_(real_weight)
narrowed_tensor
and param.data
share the same storage. With functionization, the in place update on the narrowed_tensor
will lazily propagate to the base tensor which is param.data
.
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.
Thanks for the elaboration. Fixed the comment!
lgtm |
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.
Thanks for referencing the CT issue, LGTM!
Signed-off-by: charlifu <[email protected]>
Signed-off-by: Vinay Damodaran <[email protected]>
Signed-off-by: Alvant <[email protected]>
Signed-off-by: Amit Garg <[email protected]>
Signed-off-by: qishuai <[email protected]>
Signed-off-by: Sumit Dubey <[email protected]>
Signed-off-by: Maxime Fournioux <[email protected]>
Signed-off-by: Tyler Michael Smith <[email protected]>
During weight loading, we often do something like:
expecting narrowed_tensor and param.data to share the same storage. However, on TPUs, narrowed_tensor will lazily propagate to the base tensor, which is param.data, leading to the redundant memory usage. This sometimes causes OOM errors during model loading.
This PR address this problem by adding a post-hook to call
torch._sync(param)
after the weight loader of each param is called.When loading Llama3-8B (bf16) on v5e-8,