-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Keep parameter dtype through ZeRO-3 weight quantization #8215
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
Open
adityasingh2400
wants to merge
3
commits into
deepspeedai:master
Choose a base branch
from
adityasingh2400:fix-zero-quantized-weights-bf16
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−14
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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.
When a coalesced quantized fetch contains parameters with mixed dtypes, this casts the entire dequantized flat buffer to only
self.params[0].dtypebefore it is split; the per-parameter cast that happens later can restore the dtype, but it cannot undo rounding already applied to later fp16/fp32 parameters when the first parameter is bf16, and it can also inflate the whole buffer when the first parameter is fp32. The non-quantized coalesced path already buckets by dtype, so this path should either keep the kernel's fp16 output until each slice is assigned or bucket quantized coalesces by dtype.Useful? React with 👍 / 👎.
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.
Valid finding, fixed in b7fafc7.
I checked the premise before changing anything and it holds. In
all_gather_coalesced, thenot quantizebranch groups parameters intodtype_paramsand issues one_all_gather_dtypeper dtype, and that helper asserts every parameter in the bucket shares a communication dtype. Thequantizebranch does none of that, it concatenates everyds_tensorinto a single int8 buffer regardless of dtype. So a quantized coalesced bucket really can be mixed, andparams[0].dtypeis not a safe stand-in for the rest of it.Rather than bucket the quantized path by dtype, I dropped the argument at that one call site. The flat buffer keeps the kernel's fp16 output exactly as it did before this PR, and the existing per-slice line a few lines down already assigns each parameter its own dtype:
That keeps the change minimal and avoids both failure modes you described, the rounding when
params[0]is the narrower dtype and the buffer inflating when it is the wider one.The other four call sites still pass
dtype, and I checked each one: they assignparam.datadirectly from the dequantized tensor with only a.viewor a device move, so there is no later cast to restore the dtype and the argument is doing real work there.yapf is clean on the file.